Skip to content

Commit

Permalink
https://github.com/neo-project/neo/pull/2150
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Feb 2, 2021
1 parent f21f8c6 commit fe83b4c
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions neo3/contracts/native/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import NativeContract
from typing import Optional
from neo3 import storage, contracts, vm
from neo3.core import to_script_hash, types
from neo3.core import to_script_hash, types, msgrouter
from neo3.network import payloads
from neo3.contracts.interop import register

Expand Down Expand Up @@ -96,7 +96,9 @@ def init(self):
return_type=None,
parameter_names=["nef_file", "manifest"],
parameter_types=[bytes, bytes],
call_flags=contracts.native.CallFlags.WRITE_STATES)
call_flags=(contracts.native.CallFlags.WRITE_STATES
| contracts.CallFlags.ALLOW_NOTIFY)
)
self._register_contract_method(self.contract_update,
0,
"update",
Expand All @@ -105,14 +107,18 @@ def init(self):
return_type=None,
parameter_names=["nef_file", "manifest"],
parameter_types=[bytes, bytes],
call_flags=contracts.native.CallFlags.WRITE_STATES)
call_flags=(contracts.native.CallFlags.WRITE_STATES
| contracts.CallFlags.ALLOW_NOTIFY)
)
self._register_contract_method(self.contract_destroy,
1000000,
"destroy",
add_engine=True,
add_snapshot=False,
return_type=None,
call_flags=contracts.native.CallFlags.WRITE_STATES)
call_flags=(contracts.native.CallFlags.WRITE_STATES
| contracts.CallFlags.ALLOW_NOTIFY)
)
self._register_contract_method(self.get_minimum_deployment_fee,
1000000,
"getMinimumDeploymentFee",
Expand All @@ -128,6 +134,27 @@ def init(self):
return_type=None,
call_flags=contracts.native.CallFlags.WRITE_STATES)

self.manifest.abi.events = [
contracts.ContractEventDescriptor(
"Deploy",
parameters=[
contracts.ContractParameterDefinition("Hash", contracts.ContractParameterType.HASH160)
]
),
contracts.ContractEventDescriptor(
"Update",
parameters=[
contracts.ContractParameterDefinition("Hash", contracts.ContractParameterType.HASH160)
]
),
contracts.ContractEventDescriptor(
"Destroy",
parameters=[
contracts.ContractParameterDefinition("Hash", contracts.ContractParameterType.HASH160)
]
),
]

def _initialize(self, engine: contracts.ApplicationEngine) -> None:
engine.snapshot.storages.add(
self.create_key(self._PREFIX_MINIMUM_DEPLOYMENT_FEE),
Expand Down Expand Up @@ -210,6 +237,13 @@ def contract_create(self, engine: contracts.ApplicationEngine, nef_file: bytes,
if method_descriptor is not None:
engine.call_from_native(hash_, hash_, method_descriptor.name, [vm.BooleanStackItem(False)])

msgrouter.interop_notify(self.hash,
"Deploy",
vm.ArrayStackItem(engine.reference_counter,
vm.ByteStringStackItem(contract.hash.to_array())
)
)

def contract_update(self, engine: contracts.ApplicationEngine, nef_file: bytes, manifest: bytes) -> None:
nef_len = len(nef_file)
manifest_len = len(manifest)
Expand Down Expand Up @@ -243,6 +277,13 @@ def contract_update(self, engine: contracts.ApplicationEngine, nef_file: bytes,
if method_descriptor is not None:
engine.call_from_native(self.hash, contract.hash, method_descriptor.name, [vm.BooleanStackItem(True)])

msgrouter.interop_notify(self.hash,
"Update",
vm.ArrayStackItem(engine.reference_counter,
vm.ByteStringStackItem(contract.hash.to_array())
)
)

def contract_destroy(self, engine: contracts.ApplicationEngine) -> None:
hash_ = engine.current_scripthash
key = self.create_key(self._PREFIX_CONTRACT + hash_.to_array())
Expand All @@ -256,6 +297,13 @@ def contract_destroy(self, engine: contracts.ApplicationEngine) -> None:
for key, _ in engine.snapshot.storages.find(contract.id.to_bytes(4, 'little', signed=True), b''):
engine.snapshot.storages.delete(key)

msgrouter.interop_notify(self.hash,
"Destroy",
vm.ArrayStackItem(engine.reference_counter,
vm.ByteStringStackItem(contract.hash.to_array())
)
)

def get_minimum_deployment_fee(self, snapshot: storage.Snapshot) -> int:
key = self.create_key(self._PREFIX_MINIMUM_DEPLOYMENT_FEE)
return int.from_bytes(snapshot.storages[key].value, 'little')
Expand Down

0 comments on commit fe83b4c

Please sign in to comment.