From dc417d4edba759a4c223db92e0f5f8024ab0f221 Mon Sep 17 00:00:00 2001 From: Moody Salem Date: Tue, 7 Nov 2023 10:06:30 -0500 Subject: [PATCH] add events to the governor contract --- src/governor.cairo | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/governor.cairo b/src/governor.cairo index 45877a9..de10e0c 100644 --- a/src/governor.cairo +++ b/src/governor.cairo @@ -91,6 +91,41 @@ mod Governor { use zeroable::{Zeroable}; use hash::{LegacyHash}; + + #[derive(starknet::Event, Drop)] + struct Proposed { + id: felt252, + proposer: ContractAddress, + call: Call, + } + + #[derive(starknet::Event, Drop)] + struct Voted { + id: felt252, + voter: ContractAddress, + weight: u128, + yea: bool, + } + + #[derive(starknet::Event, Drop)] + struct Canceled { + id: felt252, + } + + #[derive(starknet::Event, Drop)] + struct Executed { + id: felt252, + } + + #[derive(starknet::Event, Drop)] + #[event] + enum Event { + Proposed: Proposed, + Voted: Voted, + Canceled: Canceled, + Executed: Executed, + } + #[storage] struct Storage { voting_token: IGovernanceTokenDispatcher, @@ -143,6 +178,8 @@ mod Governor { } ); + self.emit(Proposed { id, proposer, call, }); + id } @@ -176,6 +213,8 @@ mod Governor { } self.proposals.write(id, proposal); self.voted.write((voter, id), true); + + self.emit(Voted { id, voter, weight, yea, }); } @@ -217,6 +256,8 @@ mod Governor { }; self.proposals.write(id, proposal); + + self.emit(Canceled { id, }); } fn execute(ref self: ContractState, call: Call) -> Span { @@ -251,7 +292,11 @@ mod Governor { self.proposals.write(id, proposal); - call.execute() + let data = call.execute(); + + self.emit(Executed { id, }); + + data } fn get_config(self: @ContractState) -> Config {