diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index 124be72a88..578504f719 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -21,6 +21,51 @@ public sealed class ManagementContract : NativeContract private const byte Prefix_NextAvailableId = 15; private const byte Prefix_Contract = 8; + internal ManagementContract() + { + var events = new List(Manifest.Abi.Events) + { + new ContractEventDescriptor + { + Name = "Deploy", + Parameters = new ContractParameterDefinition[] + { + new ContractParameterDefinition() + { + Name = "Hash", + Type = ContractParameterType.Hash160 + } + } + }, + new ContractEventDescriptor + { + Name = "Update", + Parameters = new ContractParameterDefinition[] + { + new ContractParameterDefinition() + { + Name = "Hash", + Type = ContractParameterType.Hash160 + } + } + }, + new ContractEventDescriptor + { + Name = "Destory", + Parameters = new ContractParameterDefinition[] + { + new ContractParameterDefinition() + { + Name = "Hash", + Type = ContractParameterType.Hash160 + } + } + } + }; + + Manifest.Abi.Events = events.ToArray(); + } + private int GetNextAvailableId(StoreView snapshot) { StorageItem item = snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_NextAvailableId), () => new StorageItem(1)); @@ -77,7 +122,7 @@ public IEnumerable ListContracts(StoreView snapshot) return snapshot.Storages.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable()); } - [ContractMethod(0, CallFlags.WriteStates)] + [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest) { if (!(engine.ScriptContainer is Transaction tx)) @@ -116,10 +161,12 @@ private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] ma if (md != null) engine.CallFromNativeContract(Hash, hash, md.Name, false); + engine.SendNotification(Hash, "Deploy", new VM.Types.Array { contract.Hash.ToArray() }); + return contract; } - [ContractMethod(0, CallFlags.WriteStates)] + [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest) { if (nefFile is null && manifest is null) throw new ArgumentException(); @@ -154,9 +201,10 @@ private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest) if (md != null) engine.CallFromNativeContract(Hash, contract.Hash, md.Name, true); } + engine.SendNotification(Hash, "Update", new VM.Types.Array { contract.Hash.ToArray() }); } - [ContractMethod(0_01000000, CallFlags.WriteStates)] + [ContractMethod(0_01000000, CallFlags.WriteStates | CallFlags.AllowNotify)] private void Destroy(ApplicationEngine engine) { UInt160 hash = engine.CallingScriptHash; @@ -166,6 +214,7 @@ private void Destroy(ApplicationEngine engine) engine.Snapshot.Storages.Delete(ckey); foreach (var (key, _) in engine.Snapshot.Storages.Find(BitConverter.GetBytes(contract.Id))) engine.Snapshot.Storages.Delete(key); + engine.SendNotification(Hash, "Destory", new VM.Types.Array { hash.ToArray() }); } } }