Skip to content

Commit

Permalink
Merge pull request #148 from jorgezerpa/issue-137-emit-event-on-recei…
Browse files Browse the repository at this point in the history
…ve-vote

[test] #137 implement newVoteReceived event on Fund contract
  • Loading branch information
EmmanuelAR authored Oct 25, 2024
2 parents 87dd170 + c1d92fe commit 1ffa737
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod Fund {
#[derive(Drop, starknet::Event)]
enum Event {
DonationWithdraw: DonationWithdraw,
NewVoteReceived: NewVoteReceived
}

#[derive(Drop, starknet::Event)]
Expand All @@ -51,6 +52,13 @@ mod Fund {
pub withdrawn_amount: u256
}

#[derive(Drop, starknet::Event)]
pub struct NewVoteReceived {
#[key]
pub voter: ContractAddress,
pub fund: ContractAddress,
pub votes: u32
}
// *************************************************************************
// STORAGE
// *************************************************************************
Expand Down Expand Up @@ -121,6 +129,15 @@ mod Fund {
if self.up_votes.read() >= FundConstants::UP_VOTES_NEEDED {
self.state.write(FundStates::RECOLLECTING_DONATIONS);
}

self
.emit(
NewVoteReceived {
voter: get_caller_address(),
fund: get_contract_address(),
votes: self.up_votes.read()
}
);
}
fn getUpVotes(self: @ContractState) -> u32 {
return self.up_votes.read();
Expand Down

0 comments on commit 1ffa737

Please sign in to comment.