Skip to content

Commit

Permalink
https://github.com/neo-project/neo/pull/2242
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Feb 15, 2021
1 parent 1e20ee0 commit 4693228
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 19 additions & 2 deletions neo3/contracts/native/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def init(self):
return_type=storage.ContractState,
call_flags=contracts.CallFlags.READ_STATES)
self._register_contract_method(self.contract_create,
0,
"deploy",
add_engine=True,
add_snapshot=False,
return_type=None,
parameter_names=["nef_file", "manifest"],
parameter_types=[bytes, bytes],
call_flags=(contracts.CallFlags.WRITE_STATES
| contracts.CallFlags.ALLOW_NOTIFY)
)
self._register_contract_method(self.contract_create_with_data,
0,
"deploy",
add_engine=True,
Expand Down Expand Up @@ -135,8 +146,14 @@ def get_contract(self, snapshot: storage.Snapshot, hash_: types.UInt160) -> Opti
def contract_create(self,
engine: contracts.ApplicationEngine,
nef_file: bytes,
manifest: bytes,
data: vm.StackItem) -> None:
manifest: bytes) -> None:
self.contract_create_with_data(engine, nef_file, manifest, vm.NullStackItem())

def contract_create_with_data(self,
engine: contracts.ApplicationEngine,
nef_file: bytes,
manifest: bytes,
data: vm.StackItem) -> None:
if not isinstance(engine.script_container, payloads.Transaction):
raise ValueError("Cannot create contract without a Transaction script container")

Expand Down
6 changes: 3 additions & 3 deletions neo3/contracts/native/nativecontract.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NativeContract(convenience._Singleton):
active_block_index = 0

def init(self):
self._methods: Dict[str, _ContractMethodMetadata] = {}
self._methods: Dict[Tuple[str, int], _ContractMethodMetadata] = {}

self._management = contracts.ManagementContract()
self._neo = NeoToken()
Expand Down Expand Up @@ -154,7 +154,7 @@ def _register_contract_method(self,
)
)

self._methods.update({func_name: _ContractMethodMetadata(
self._methods.update({(func_name, len(params)): _ContractMethodMetadata(
func, price, call_flags, add_engine, add_snapshot, return_type, parameter_types)
})

Expand Down Expand Up @@ -224,7 +224,7 @@ def invoke(self, engine: contracts.ApplicationEngine) -> None:
operation = context.evaluation_stack.pop().to_array().decode()

flags = contracts.CallFlags(context.call_flags)
method = self._methods.get(operation, None)
method = self._methods.get((operation, len(context.evaluation_stack)), None)
if method is None:
raise ValueError(f"Method \"{operation}\" does not exist on contract {self.service_name()}")
if method.required_flag not in flags:
Expand Down

0 comments on commit 4693228

Please sign in to comment.