Skip to content

Commit

Permalink
Add committee change events (#3158)
Browse files Browse the repository at this point in the history
* Add committee change events

* Update src/Neo/SmartContract/Native/NeoToken.cs

* Update src/Neo/SmartContract/Native/NeoToken.cs
  • Loading branch information
shargon authored Feb 26, 2024
1 parent d4564d1 commit 0de52d2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Neo/SmartContract/Native/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public sealed class NeoToken : FungibleToken<NeoToken.NeoAccountState>
"from", ContractParameterType.PublicKey,
"to", ContractParameterType.PublicKey,
"amount", ContractParameterType.Integer)]
[ContractEvent(3, name: "CommitteeChanged",
"old", ContractParameterType.Array,
"new", ContractParameterType.Array)]
internal NeoToken() : base()
{
this.TotalAmount = 100000000 * Factor;
Expand Down Expand Up @@ -192,10 +195,23 @@ internal override ContractTask OnPersist(ApplicationEngine engine)
// Set next committee
if (ShouldRefreshCommittee(engine.PersistingBlock.Index, engine.ProtocolSettings.CommitteeMembersCount))
{
StorageItem storageItem = engine.Snapshot.GetAndChange(CreateStorageKey(Prefix_Committee));
var storageItem = engine.Snapshot.GetAndChange(CreateStorageKey(Prefix_Committee));
var cachedCommittee = storageItem.GetInteroperable<CachedCommittee>();

var prevCommittee = cachedCommittee.Select(u => u.PublicKey).ToArray();

cachedCommittee.Clear();
cachedCommittee.AddRange(ComputeCommitteeMembers(engine.Snapshot, engine.ProtocolSettings));

var newCommittee = cachedCommittee.Select(u => u.PublicKey).ToArray();

if (!newCommittee.SequenceEqual(prevCommittee))
{
engine.SendNotification(Hash, "CommitteeChanged", new VM.Types.Array(engine.ReferenceCounter) {
new VM.Types.Array(engine.ReferenceCounter, prevCommittee.Select(u => (ByteString)u.ToArray())) ,
new VM.Types.Array(engine.ReferenceCounter, newCommittee.Select(u => (ByteString)u.ToArray()))
});
}
}
return ContractTask.CompletedTask;
}
Expand Down

0 comments on commit 0de52d2

Please sign in to comment.