Skip to content

Commit

Permalink
add events to the governor contract
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Nov 7, 2023
1 parent b09f6d1 commit dc417d4
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/governor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -143,6 +178,8 @@ mod Governor {
}
);

self.emit(Proposed { id, proposer, call, });

id
}

Expand Down Expand Up @@ -176,6 +213,8 @@ mod Governor {
}
self.proposals.write(id, proposal);
self.voted.write((voter, id), true);

self.emit(Voted { id, voter, weight, yea, });
}


Expand Down Expand Up @@ -217,6 +256,8 @@ mod Governor {
};

self.proposals.write(id, proposal);

self.emit(Canceled { id, });
}

fn execute(ref self: ContractState, call: Call) -> Span<felt252> {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dc417d4

Please sign in to comment.