Skip to content

Commit

Permalink
Merge pull request #149 from MPSxDev/withdraw-event
Browse files Browse the repository at this point in the history
[feat] Emit event when user withdraw fund's balance
  • Loading branch information
EmmanuelAR authored Oct 25, 2024
2 parents 40ff525 + 213f06e commit 85b45cd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ mod Fund {
use gostarkme::constants::{funds::{fund_constants::FundConstants},};
use gostarkme::constants::{funds::{starknet_constants::StarknetConstants},};

// *************************************************************************
// EVENTS
// *************************************************************************

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
DonationWithdraw: DonationWithdraw,
}
// Struct DonationWithdraw
#[derive(Drop, starknet::Event)]
pub struct DonationWithdraw {
#[key]
pub owner_address: ContractAddress,
pub fund_contract_address: ContractAddress,
pub withdrawn_amount: u256
}

// *************************************************************************
// STORAGE
Expand Down Expand Up @@ -158,6 +175,12 @@ mod Fund {
starknet_dispatcher.transfer(self.getOwner(), balance);
assert(self.getCurrentGoalState() != 0, 'Fund hasnt reached its goal yet');
self.setState(4);
// Emit Event DonationWithdraw (amount=balance)
self.emit(DonationWithdraw {
owner_address: self.getOwner(),
fund_contract_address: get_contract_address(),
withdrawn_amount: balance
});
}
}
}

0 comments on commit 85b45cd

Please sign in to comment.