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

update to new pattern in cairo2 #5

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions src/GuildSBT.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use array::Array;

#[starknet::interface]
trait IMaster<T> {
fn get_dev_points(self: @T, contributor: ContractAddress) -> u32;
fn get_guild_points(self: @T, contributor: ContractAddress, guild: felt252) -> u32;
}

//
Expand Down Expand Up @@ -114,7 +114,7 @@ mod GuildSBT {
let master = self._master.read();
let masterDispatcher = IMasterDispatcher { contract_address: master };
// @notice this is a sample SBT contract for dev guild, update the next line before deploying other guild

Choose a reason for hiding this comment

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

Since it's only for a dev guild contract what do you think about changing the name also? Like DevGuildSBT

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its just a temporary name

let points = masterDispatcher.get_dev_points(owner);
let points = masterDispatcher.get_guild_points(owner, 'dev');
let token_type = self._token_type.read(owner);

let tier = InternalImpl::_get_contribution_tier(self, points);
Expand All @@ -129,7 +129,7 @@ mod GuildSBT {
let master = self._master.read();
let masterDispatcher = IMasterDispatcher { contract_address: master };
// @notice this is a sample SBT contract for dev guild, update the next line before deploying other guild
let points = masterDispatcher.get_dev_points(contributor);
let points = masterDispatcher.get_guild_points(contributor, 'dev');
let token_type = self._token_type.read(contributor);

let tier = InternalImpl::_get_contribution_tier(self, points);
Expand All @@ -151,7 +151,7 @@ mod GuildSBT {
fn get_contribution_tier(self: @ContractState, contributor: ContractAddress) -> u32 {
let master = self._master.read();
let masterDispatcher = IMasterDispatcher { contract_address: master };
let points = masterDispatcher.get_dev_points(contributor);
let points = masterDispatcher.get_guild_points(contributor, 'dev');
InternalImpl::_get_contribution_tier(self, points)
}

Expand Down Expand Up @@ -201,7 +201,7 @@ mod GuildSBT {

let master = self._master.read();
let masterDispatcher = IMasterDispatcher { contract_address: master };
let points = masterDispatcher.get_dev_points(account);
let points = masterDispatcher.get_guild_points(account, 'dev');
let tier = InternalImpl::_get_contribution_tier(@self, points);

assert (tier != 0, 'NOT_ENOUGH_POINTS');
Expand Down
73 changes: 44 additions & 29 deletions src/Master.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ trait IGuild<T> {
trait IMaster<TContractState> {
// view functions
fn get_contributions_points(self: @TContractState, contributor: ContractAddress) -> Contribution;
fn get_dev_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_design_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_problem_solving_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_marcom_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_research_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_guild_points(self: @TContractState, contributor: ContractAddress, guild: felt252) -> u32;
fn get_last_update_id(self: @TContractState) -> u32;
fn get_last_update_time(self: @TContractState) -> u64;
fn get_migartion_queued_state(self: @TContractState, hash: felt252 ) -> bool;
Expand All @@ -88,6 +84,8 @@ trait IMaster<TContractState> {
fn get_research_guild_SBT(self: @TContractState) -> ContractAddress;
fn get_total_contribution(self: @TContractState, month_id: u32) -> TotalMonthlyContribution;
fn get_contributions_data(self: @TContractState, contributor: ContractAddress, guild: felt252) -> Array<u32>;
fn get_guild_total_contribution(self: @TContractState, month_id: u32, guild: felt252) -> u32;


// external functions
fn update_contibutions(ref self: TContractState, month_id: u32, contributions: Array::<MonthlyContribution>);
Expand Down Expand Up @@ -204,33 +202,50 @@ mod Master {
self._total_contribution.read(month_id)
}

fn get_contributions_data(self: @ContractState, contributor: ContractAddress, guild: felt252) -> Array<u32> {
self._contributions_data.read((contributor, guild))
}

fn get_dev_points(self: @ContractState, contributor: ContractAddress) -> u32 {
let contribution: Contribution = self._contributions.read(contributor);
contribution.dev
}

fn get_design_points(self: @ContractState, contributor: ContractAddress) -> u32 {
let contribution = self._contributions.read(contributor);
contribution.design
}

fn get_problem_solving_points(self: @ContractState, contributor: ContractAddress) -> u32 {
let contribution = self._contributions.read(contributor);
contribution.problem_solving
fn get_guild_total_contribution(self: @ContractState, month_id: u32, guild: felt252) -> u32 {

Choose a reason for hiding this comment

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

Question - how detailed should tests be? If very then we might want to test get_guild_total_contribution and get_guild_points functions for every guild in a specific test.

if(guild == 'dev') {
self._total_contribution.read(month_id).dev
}
else if(guild == 'design') {
self._total_contribution.read(month_id).design
}
else if(guild == 'problem_solving') {
self._total_contribution.read(month_id).problem_solving
}
else if(guild == 'marcom') {
self._total_contribution.read(month_id).marcom
}
else if(guild == 'research') {
self._total_contribution.read(month_id).research
}
else {
0
}
}

fn get_marcom_points(self: @ContractState, contributor: ContractAddress) -> u32 {
let contribution = self._contributions.read(contributor);
contribution.marcom
fn get_contributions_data(self: @ContractState, contributor: ContractAddress, guild: felt252) -> Array<u32> {
self._contributions_data.read((contributor, guild))
}

fn get_research_points(self: @ContractState, contributor: ContractAddress) -> u32 {
let contribution = self._contributions.read(contributor);
contribution.research
fn get_guild_points(self: @ContractState, contributor: ContractAddress, guild: felt252) -> u32 {
if(guild == 'dev') {
self._contributions.read(contributor).dev
}
else if(guild == 'design') {
self._contributions.read(contributor).design
}
else if(guild == 'problem_solving') {
self._contributions.read(contributor).problem_solving
}
else if(guild == 'marcom') {
self._contributions.read(contributor).marcom
}
else if(guild == 'research') {
self._contributions.read(contributor).research
}
else {
0
}
}

fn get_last_update_id(self: @ContractState) -> u32 {
Expand Down Expand Up @@ -390,7 +405,7 @@ mod Master {
if(new_contribution_score != 0) {
let mut contribution_data = self._contributions_data.read((contributor, guild));
contribution_data.append(month_id);

Choose a reason for hiding this comment

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

Indents are not needed. Should be inline with let mut contribution_data

contribution_data.append(new_guild_score);
contribution_data.append(new_contribution_score);

Choose a reason for hiding this comment

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

Could you create a test for this case? We missed it


self._contributions_data.write((contributor, guild), contribution_data);
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ mod master;
mod access;
mod storage;
mod guildSBT;
mod array;
mod array;
mod salary;
1 change: 0 additions & 1 deletion tests/test_migrate_points.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use contributor_SBT2_0::master::Contribution;
#[starknet::interface]
trait IMaster<TContractState> {
fn get_last_update_id(self: @TContractState) -> u32;
fn get_dev_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_contributions_points(self: @TContractState, contributor: ContractAddress) -> Contribution;

fn update_contibutions(ref self: TContractState, month_id: u32, contributions: Array::<MonthlyContribution>);
Expand Down
1 change: 0 additions & 1 deletion tests/test_mint.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use contributor_SBT2_0::master::MonthlyContribution;
#[starknet::interface]
trait IMaster<TContractState> {
fn get_last_update_id(self: @TContractState) -> u32;
fn get_dev_points(self: @TContractState, contributor: ContractAddress) -> u32;

fn update_contibutions(ref self: TContractState, month_id: u32, contributions: Array::<MonthlyContribution>);

Expand Down
1 change: 0 additions & 1 deletion tests/test_update_contribution_points.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use contributor_SBT2_0::master::TotalMonthlyContribution;
#[starknet::interface]
trait IMaster<TContractState> {
fn get_last_update_id(self: @TContractState) -> u32;
fn get_dev_points(self: @TContractState, contributor: ContractAddress) -> u32;
fn get_contributions_points(self: @TContractState, contributor: ContractAddress) -> Contribution;
fn get_contributions_data(self: @TContractState, contributor: ContractAddress, guild: felt252) -> Array<u32>;
fn get_total_contribution(self: @TContractState, month_id: u32) -> TotalMonthlyContribution;
Expand Down