From d4c7fb88353399f1f5802206f49224c6f4903460 Mon Sep 17 00:00:00 2001 From: MPSxDev Date: Thu, 24 Oct 2024 15:07:43 -0300 Subject: [PATCH 1/4] [feat] add event struct to the fund.cairo --- contracts/src/fund.cairo | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index e241f47..4b9db9b 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -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)] + struct DonationWithdraw { + #[key] + fund_contract_address: ContractAddress, + owner_address: ContractAddress, + withdrawn_amount: u256 + } // ************************************************************************* // STORAGE From 2e2b226150e2ef922af7ab63b6dae86d2032bae0 Mon Sep 17 00:00:00 2001 From: MPSxDev Date: Thu, 24 Oct 2024 15:08:57 -0300 Subject: [PATCH 2/4] [feat] emit event in withdraw --- contracts/src/fund.cairo | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index 4b9db9b..cf46ef1 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -174,6 +174,12 @@ mod Fund { //TODO: Calculate balance to deposit in owner address and in fund manager address (95% 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'); + // Emit Event DonationWithdraw (amount=balance) + self.emit(DonationWithdraw { + fund_contract_address: get_contract_address(), + owner_address: self.getOwner(), + withdrawn_amount: balance + }); self.setState(4); } } From cd19522474cd3447f7c002fe6c93000cc498be43 Mon Sep 17 00:00:00 2001 From: MPSxDev Date: Thu, 24 Oct 2024 15:39:16 -0300 Subject: [PATCH 3/4] [feat] add pub and edit event struct --- contracts/src/fund.cairo | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index cf46ef1..a3d447d 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -45,11 +45,10 @@ mod Fund { } // Struct DonationWithdraw #[derive(Drop, starknet::Event)] - struct DonationWithdraw { + pub struct DonationWithdraw { #[key] - fund_contract_address: ContractAddress, - owner_address: ContractAddress, - withdrawn_amount: u256 + pub owner_address: ContractAddress, + pub withdrawn_amount: u256 } // ************************************************************************* @@ -176,7 +175,6 @@ mod Fund { assert(self.getCurrentGoalState() != 0, 'Fund hasnt reached its goal yet'); // Emit Event DonationWithdraw (amount=balance) self.emit(DonationWithdraw { - fund_contract_address: get_contract_address(), owner_address: self.getOwner(), withdrawn_amount: balance }); From e1d22eca9220b1835630d87f6f42c55715ab1549 Mon Sep 17 00:00:00 2001 From: MPSxDev Date: Thu, 24 Oct 2024 22:17:19 -0300 Subject: [PATCH 4/4] [feat] Add fund contract address + move emit --- contracts/src/fund.cairo | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index a3d447d..105fd4b 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -48,6 +48,7 @@ mod Fund { pub struct DonationWithdraw { #[key] pub owner_address: ContractAddress, + pub fund_contract_address: ContractAddress, pub withdrawn_amount: u256 } @@ -173,12 +174,13 @@ mod Fund { //TODO: Calculate balance to deposit in owner address and in fund manager address (95% 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); // Emit Event DonationWithdraw (amount=balance) self.emit(DonationWithdraw { owner_address: self.getOwner(), + fund_contract_address: get_contract_address(), withdrawn_amount: balance }); - self.setState(4); } } }