Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/neo/SmartContract/Native/ManagementContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,56 @@ public sealed class ManagementContract : NativeContract
private const byte Prefix_NextAvailableId = 15;
private const byte Prefix_Contract = 8;

internal ManagementContract()
{
var events = new List<ContractEventDescriptor>(Manifest.Abi.Events)
{
new ContractEventDescriptor
{
Name = "Deploy",
Parameters = new ContractParameterDefinition[]
{
new ContractParameterDefinition()
{
Name = "Contract",
Type = ContractParameterType.Hash160
}
}
},
new ContractEventDescriptor
{
Name = "Update",
Parameters = new ContractParameterDefinition[]
{
new ContractParameterDefinition()
{
Name = "Contract",
Type = ContractParameterType.Hash160
},
new ContractParameterDefinition()
{
Name = "UpdateCounter",
Type = ContractParameterType.Integer
}
}
},
new ContractEventDescriptor
{
Name = "Destory",
Parameters = new ContractParameterDefinition[]
{
new ContractParameterDefinition()
{
Name = "Contract",
Type = ContractParameterType.Hash160
}
}
}
};

Manifest.Abi.Events = events.ToArray();
}

private int GetNextAvailableId(StoreView snapshot)
{
StorageItem item = snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_NextAvailableId), () => new StorageItem(1));
Expand Down Expand Up @@ -116,6 +166,8 @@ 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;
}

Expand Down Expand Up @@ -154,6 +206,7 @@ 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(), (int)contract.UpdateCounter });
}

[ContractMethod(0_01000000, CallFlags.WriteStates)]
Expand All @@ -166,6 +219,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() });
}
}
}