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

[19] Add asserts to funds contract #24

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Changes from all commits
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
14 changes: 11 additions & 3 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait IFund<TContractState> {
fn getUpVotes(self: @TContractState) -> u32;
fn setGoal(ref self: TContractState, goal: u64);
fn getGoal(self: @TContractState) -> u64;
fn donate(ref self: TContractState, amount: u64);
fn setCurrentGoalState(ref self: TContractState, strks: u64);
fn getCurrentGoalState(self: @TContractState) -> u64;
fn setIsActive(ref self: TContractState, is_active: bool);
fn getIsActive(self: @TContractState) -> bool;
Expand All @@ -21,6 +21,7 @@ trait IFund<TContractState> {
#[starknet::contract]
mod Fund {
use starknet::ContractAddress;
use starknet::get_caller_address;

#[storage]
struct Storage {
Expand Down Expand Up @@ -62,12 +63,16 @@ mod Fund {
return self.owner.read();
}
fn setName(ref self: ContractState, name: felt252) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
self.name.write(name);
}
fn getName(self: @ContractState) -> felt252 {
return self.name.read();
}
fn setReason(ref self: ContractState, reason: felt252) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
self.reason.write(reason);
}
fn getReason(self: @ContractState) -> felt252 {
Expand All @@ -80,13 +85,16 @@ mod Fund {
return self.up_votes.read();
}
fn setGoal(ref self: ContractState, goal: u64) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
self.goal.write(goal);
}
fn getGoal(self: @ContractState) -> u64 {
return self.goal.read();
}
fn donate(ref self: ContractState, amount: u64) {
self.current_goal_state.write(self.current_goal_state.read() + amount);
// TODO: implement the logic where user actually donates starks
fn setCurrentGoalState(ref self: ContractState, strks: u64) {
self.current_goal_state.write(self.current_goal_state.read() + strks);
}
fn getCurrentGoalState(self: @ContractState) -> u64 {
return self.current_goal_state.read();
Expand Down
Loading