Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add emit event to receiveDonation function #161

Merged
merged 6 commits into from
Oct 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ mod Fund {
#[derive(Drop, starknet::Event)]
enum Event {
DonationWithdraw: DonationWithdraw,
NewVoteReceived: NewVoteReceived
NewVoteReceived: NewVoteReceived,
DonationReceived: DonationReceived,
}

#[derive(Drop, starknet::Event)]
Expand All @@ -59,6 +60,15 @@ mod Fund {
pub fund: ContractAddress,
pub votes: u32
}

#[derive(Drop, starknet::Event)]
pub struct DonationReceived {
#[key]
pub donor_address: ContractAddress,
NueloSE marked this conversation as resolved.
Show resolved Hide resolved
pub donated_strks: u256,
pub current_balance: u256,
pub fund_contract_address: ContractAddress,
}
// *************************************************************************
// STORAGE
// *************************************************************************
Expand Down Expand Up @@ -160,6 +170,17 @@ mod Fund {
if self.current_goal_state.read() >= self.goal.read() {
self.state.write(FundStates::CLOSED);
}

// Emit receiveDonation event
self
.emit(
DonationReceived {
donor_address: get_caller_address(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also change the event, please run the scarb build and fmt

fund_contract_address: get_contract_address(),
current_balance: self.current_goal_state.read(),
donated_strks: strks,
}
)
}
fn getCurrentGoalState(self: @ContractState) -> u256 {
return self.current_goal_state.read();
Expand Down Expand Up @@ -187,7 +208,8 @@ mod Fund {
contract_address: starknet_contract_address
};
let balance = starknet_dispatcher.balance_of(get_contract_address());
//TODO: Calculate balance to deposit in owner address and in fund manager address (95% and 5%), also transfer the amount to fund manager address.
//TODO: Calculate balance to deposit in owner address and in fund manager address (95%
NueloSE marked this conversation as resolved.
Show resolved Hide resolved
//and 5%), also transfer the amount to fund manager address.
starknet_dispatcher.transfer(self.getOwner(), balance);
assert(self.getCurrentGoalState() != 0, 'Fund hasnt reached its goal yet');
self.setState(4);
Expand Down