Skip to content

Commit

Permalink
Merge branch 'dev' into issue-137-emit-event-on-receive-vote
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgezerpa committed Oct 25, 2024
2 parents 69daeb9 + 87dd170 commit 4f08647
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
25 changes: 23 additions & 2 deletions contracts/src/donatorManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ mod DonatorManager {
self.donator_class_hash.write(donator_class_hash.try_into().unwrap());
}

// *************************************************************************
// EVENTS
// *************************************************************************
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
DonatorContractDeployed: DonatorContractDeployed,
}

#[derive(Drop, starknet::Event)]
struct DonatorContractDeployed {
new_donator: ContractAddress,
owner: ContractAddress
}

// *************************************************************************
// EXTERNALS
// *************************************************************************
Expand All @@ -49,11 +64,17 @@ mod DonatorManager {
let mut calldata = ArrayTrait::<felt252>::new();
calldata.append(get_caller_address().try_into().unwrap());

let (address_0, _) = deploy_syscall(
let (new_donator_address, _) = deploy_syscall(
self.donator_class_hash.read(), 12345, calldata.span(), false
)
.unwrap();
self.donators.write(get_caller_address().try_into().unwrap(), address_0);
self.donators.write(get_caller_address().try_into().unwrap(), new_donator_address);
self
.emit(
DonatorContractDeployed {
owner: get_caller_address(), new_donator: new_donator_address
}
)
}
fn getOwner(self: @ContractState) -> ContractAddress {
return self.owner.read();
Expand Down
24 changes: 24 additions & 0 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ 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,
}

#[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 @@ -185,6 +201,14 @@ mod Fund {
starknet_dispatcher.transfer(self.getOwner(), balance);
assert(self.getCurrentGoalState() != 0, 'Fund hasnt reached its goal yet');
self.setState(4);
self
.emit(
DonationWithdraw {
owner_address: self.getOwner(),
fund_contract_address: get_contract_address(),
withdrawn_amount: balance
}
);
}
}
}
4 changes: 2 additions & 2 deletions contracts/src/fundManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ mod FundManager {
Serde::serialize(@get_caller_address(), ref call_data);
Serde::serialize(@name, ref call_data);
Serde::serialize(@goal, ref call_data);
let (address_0, _) = deploy_syscall(
let (new_fund_address, _) = deploy_syscall(
self.fund_class_hash.read(), 12345, call_data.span(), false
)
.unwrap();
self.funds.write(self.current_id.read(), address_0);
self.funds.write(self.current_id.read(), new_fund_address);
self.current_id.write(self.current_id.read() + 1);
}
fn getCurrentId(self: @ContractState) -> u128 {
Expand Down

0 comments on commit 4f08647

Please sign in to comment.