Skip to content

Commit

Permalink
Merge pull request #5 from GuiGou12358/main
Browse files Browse the repository at this point in the history
add the claim_from method
  • Loading branch information
GuiGou12358 authored Dec 11, 2023
2 parents 675da12 + b481481 commit dcdff4b
Show file tree
Hide file tree
Showing 19 changed files with 16 additions and 6,417 deletions.
1 change: 0 additions & 1 deletion ink/artifacts/dapps_staking_developer.contract

This file was deleted.

926 changes: 0 additions & 926 deletions ink/artifacts/dapps_staking_developer.json

This file was deleted.

Binary file removed ink/artifacts/dapps_staking_developer.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion ink/artifacts/lucky_raffle.contract

This file was deleted.

2,749 changes: 0 additions & 2,749 deletions ink/artifacts/lucky_raffle.json

This file was deleted.

Binary file removed ink/artifacts/lucky_raffle.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion ink/artifacts/random_generator.contract

This file was deleted.

1,316 changes: 0 additions & 1,316 deletions ink/artifacts/random_generator.json

This file was deleted.

Binary file removed ink/artifacts/random_generator.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion ink/artifacts/reward_manager.contract

This file was deleted.

1,420 changes: 0 additions & 1,420 deletions ink/artifacts/reward_manager.json

This file was deleted.

Binary file removed ink/artifacts/reward_manager.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion ink/contracts/reward_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reward_manager"
version = "1.0.1"
version = "1.1.0"
authors = ["guigou"]
edition = "2021"

Expand Down
5 changes: 5 additions & 0 deletions ink/contracts/reward_manager/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ pub mod reward_manager {
REWARD_MANAGER
}

#[ink(message)]
pub fn get_role_claimer_from(&self) -> RoleType {
CLAIMER_FROM
}

#[ink(message)]
pub fn get_role_reward_viewer(&self) -> RoleType {
REWARD_VIEWER
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contract":{"authors":["guigou"],"name":"reward_manager","version":"1.1.0"},"source":{"build_info":{"build_mode":"Release","cargo_contract_version":"3.2.0","rust_toolchain":"stable-x86_64-unknown-linux-gnu","wasm_opt_settings":{"keep_debug_symbols":false,"optimization_passes":"Z"}},"compiler":"rustc 1.71.1","hash":"0xd5ce954d0674b3b68e4896a66a0aa36b7ce4b215c9bdad7730ce97c0fd477436","language":"ink! 4.3.0"},"spec":{"constructors":[{"args":[],"default":false,"docs":[],"label":"new","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":3},"selector":"0x9bae9d5e"}],"docs":[],"environment":{"accountId":{"displayName":["AccountId"],"type":16},"balance":{"displayName":["Balance"],"type":0},"blockNumber":{"displayName":["BlockNumber"],"type":1},"chainExtension":{"displayName":["ChainExtension"],"type":28},"hash":{"displayName":["Hash"],"type":5},"maxEventTopics":4,"timestamp":{"displayName":["Timestamp"],"type":27}},"events":[{"args":[{"docs":[],"indexed":true,"label":"account","type":{"displayName":["AccountId"],"type":16}},{"docs":[],"indexed":false,"label":"era","type":{"displayName":["u32"],"type":1}},{"docs":[],"indexed":false,"label":"amount","type":{"displayName":["Balance"],"type":0}}],"docs":["Event emitted when a reward is pending"],"label":"PendingReward"},{"args":[{"docs":[],"indexed":true,"label":"account","type":{"displayName":["AccountId"],"type":16}},{"docs":[],"indexed":false,"label":"amount","type":{"displayName":["Balance"],"type":0}}],"docs":["Event emitted when a user claim rewards"],"label":"RewardsClaimed"}],"lang_error":{"displayName":["ink","LangError"],"type":4},"messages":[{"args":[{"label":"new_code_hash","type":{"displayName":["Hash"],"type":5}}],"default":false,"docs":[],"label":"upgrade_contract","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":8},"selector":"0x1345543d"},{"args":[],"default":false,"docs":[],"label":"terminate_me","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":8},"selector":"0x17feb370"},{"args":[],"default":false,"docs":[],"label":"get_role_reward_manager","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":13},"selector":"0xe37044e4"},{"args":[],"default":false,"docs":[],"label":"get_role_claimer_from","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":13},"selector":"0x1b25f9bd"},{"args":[],"default":false,"docs":[],"label":"get_role_reward_viewer","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":13},"selector":"0x3c40d3be"},{"args":[{"label":"value","type":{"displayName":["Balance"],"type":0}}],"default":false,"docs":[],"label":"withdraw","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":8},"selector":"0x410fcc9d"},{"args":[{"label":"era","type":{"displayName":["psp22reward_external","FundRewardsAndAddWinnersInput1"],"type":1}},{"label":"accounts","type":{"displayName":["psp22reward_external","FundRewardsAndAddWinnersInput2"],"type":14}}],"default":false,"docs":[" Add the accounts in the list of winners for a given era"," accounts contains the list of winners and the rewards by account"],"label":"Psp22Reward::fund_rewards_and_add_winners","mutates":true,"payable":true,"returnType":{"displayName":["ink","MessageResult"],"type":17},"selector":"0xc218e5ba"},{"args":[],"default":false,"docs":[" return true if the current account has pending rewards"],"label":"Psp22Reward::has_pending_rewards","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":19},"selector":"0x4fa2ad68"},{"args":[{"label":"from","type":{"displayName":["psp22reward_external","GetPendingRewardsFromInput1"],"type":16}}],"default":false,"docs":[" return the pending rewards for a given account."],"label":"Psp22Reward::get_pending_rewards_from","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":21},"selector":"0xf53a4041"},{"args":[],"default":false,"docs":[" claim all pending rewards for the current account"," After claiming, there is not anymore pending rewards for this account"],"label":"Psp22Reward::claim","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":17},"selector":"0x51be5832"},{"args":[{"label":"from","type":{"displayName":["psp22reward_external","ClaimFromInput1"],"type":16}}],"default":false,"docs":[" claim all pending rewards for the given account"," After claiming, there is not anymore pending rewards for this account"],"label":"Psp22Reward::claim_from","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":17},"selector":"0x14e8fe0f"},{"args":[{"label":"role","type":{"displayName":["accesscontrol_external","RenounceRoleInput1"],"type":1}},{"label":"account","type":{"displayName":["accesscontrol_external","RenounceRoleInput2"],"type":24}}],"default":false,"docs":[],"label":"AccessControl::renounce_role","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":25},"selector":"0xeaf1248a"},{"args":[{"label":"role","type":{"displayName":["accesscontrol_external","GrantRoleInput1"],"type":1}},{"label":"account","type":{"displayName":["accesscontrol_external","GrantRoleInput2"],"type":24}}],"default":false,"docs":[],"label":"AccessControl::grant_role","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":25},"selector":"0x4ac062fd"},{"args":[{"label":"role","type":{"displayName":["accesscontrol_external","RevokeRoleInput1"],"type":1}},{"label":"account","type":{"displayName":["accesscontrol_external","RevokeRoleInput2"],"type":24}}],"default":false,"docs":[],"label":"AccessControl::revoke_role","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":25},"selector":"0x6e4f0991"},{"args":[{"label":"role","type":{"displayName":["accesscontrol_external","GetRoleAdminInput1"],"type":1}}],"default":false,"docs":[],"label":"AccessControl::get_role_admin","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":13},"selector":"0x83da3bb2"},{"args":[{"label":"role","type":{"displayName":["accesscontrol_external","HasRoleInput1"],"type":1}},{"label":"address","type":{"displayName":["accesscontrol_external","HasRoleInput2"],"type":24}}],"default":false,"docs":[],"label":"AccessControl::has_role","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":19},"selector":"0xc1d9ac18"}]},"storage":{"root":{"layout":{"struct":{"fields":[{"layout":{"struct":{"fields":[{"layout":{"root":{"layout":{"leaf":{"key":"0x06fea0cc","ty":0}},"root_key":"0x06fea0cc"}},"name":"pending_rewards"}],"name":"Data"}},"name":"reward"},{"layout":{"struct":{"fields":[{"layout":{"root":{"layout":{"leaf":{"key":"0x1f2cf4ac","ty":1}},"root_key":"0x1f2cf4ac"}},"name":"admin_roles"},{"layout":{"root":{"layout":{"leaf":{"key":"0x8150f558","ty":2}},"root_key":"0x8150f558"}},"name":"members"}],"name":"Data"}},"name":"access"}],"name":"Contract"}},"root_key":"0x00000000"}},"types":[{"id":0,"type":{"def":{"primitive":"u128"}}},{"id":1,"type":{"def":{"primitive":"u32"}}},{"id":2,"type":{"def":{"tuple":[]}}},{"id":3,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":4}],"path":["Result"]}},{"id":4,"type":{"def":{"variant":{"variants":[{"index":1,"name":"CouldNotReadInput"}]}},"path":["ink_primitives","LangError"]}},{"id":5,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","Hash"]}},{"id":6,"type":{"def":{"array":{"len":32,"type":7}}}},{"id":7,"type":{"def":{"primitive":"u8"}}},{"id":8,"type":{"def":{"variant":{"variants":[{"fields":[{"type":9}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":9},{"name":"E","type":4}],"path":["Result"]}},{"id":9,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":10}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":10}],"path":["Result"]}},{"id":10,"type":{"def":{"variant":{"variants":[{"fields":[{"type":11,"typeName":"RewardError"}],"index":0,"name":"RewardError"},{"fields":[{"type":12,"typeName":"AccessControlError"}],"index":1,"name":"AccessControlError"},{"index":2,"name":"UpgradeError"},{"index":3,"name":"TransferError"}]}},"path":["reward_manager","reward_manager","ContractError"]}},{"id":11,"type":{"def":{"variant":{"variants":[{"index":0,"name":"InsufficientTransferredBalance"},{"index":1,"name":"TransferError"},{"index":2,"name":"AddOverFlow"},{"index":3,"name":"NoReward"},{"fields":[{"type":12,"typeName":"AccessControlError"}],"index":4,"name":"AccessControlError"}]}},"path":["lucky","traits","reward","psp22_reward","RewardError"]}},{"id":12,"type":{"def":{"variant":{"variants":[{"index":0,"name":"InvalidCaller"},{"index":1,"name":"MissingRole"},{"index":2,"name":"RoleRedundant"}]}},"path":["openbrush_contracts","traits","errors","access_control","AccessControlError"]}},{"id":13,"type":{"def":{"variant":{"variants":[{"fields":[{"type":1}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":1},{"name":"E","type":4}],"path":["Result"]}},{"id":14,"type":{"def":{"sequence":{"type":15}}}},{"id":15,"type":{"def":{"tuple":[16,0]}}},{"id":16,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","AccountId"]}},{"id":17,"type":{"def":{"variant":{"variants":[{"fields":[{"type":18}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":18},{"name":"E","type":4}],"path":["Result"]}},{"id":18,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":11}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":11}],"path":["Result"]}},{"id":19,"type":{"def":{"variant":{"variants":[{"fields":[{"type":20}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":20},{"name":"E","type":4}],"path":["Result"]}},{"id":20,"type":{"def":{"primitive":"bool"}}},{"id":21,"type":{"def":{"variant":{"variants":[{"fields":[{"type":22}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":22},{"name":"E","type":4}],"path":["Result"]}},{"id":22,"type":{"def":{"variant":{"variants":[{"fields":[{"type":23}],"index":0,"name":"Ok"},{"fields":[{"type":11}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":23},{"name":"E","type":11}],"path":["Result"]}},{"id":23,"type":{"def":{"variant":{"variants":[{"index":0,"name":"None"},{"fields":[{"type":0}],"index":1,"name":"Some"}]}},"params":[{"name":"T","type":0}],"path":["Option"]}},{"id":24,"type":{"def":{"variant":{"variants":[{"index":0,"name":"None"},{"fields":[{"type":16}],"index":1,"name":"Some"}]}},"params":[{"name":"T","type":16}],"path":["Option"]}},{"id":25,"type":{"def":{"variant":{"variants":[{"fields":[{"type":26}],"index":0,"name":"Ok"},{"fields":[{"type":4}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":26},{"name":"E","type":4}],"path":["Result"]}},{"id":26,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":12}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":12}],"path":["Result"]}},{"id":27,"type":{"def":{"primitive":"u64"}}},{"id":28,"type":{"def":{"variant":{}},"path":["ink_env","types","NoChainExtension"]}}],"version":"4"}
Binary file not shown.
2 changes: 1 addition & 1 deletion ink/logics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lucky"
version = "0.1.0"
version = "1.1.0"
authors = ["guigou"]
edition = "2021"

Expand Down
7 changes: 7 additions & 0 deletions ink/logics/traits/reward/psp22_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub type Psp22RewardRef = dyn Psp22Reward;

pub const REWARD_MANAGER: RoleType = ink::selector_id!("REWARD_MANAGER");
pub const REWARD_VIEWER: RoleType = ink::selector_id!("REWARD_VIEWER");
pub const CLAIMER_FROM: RoleType = ink::selector_id!("CLAIMER_FROM");

#[derive(Default, Debug)]
#[openbrush::storage_item]
Expand Down Expand Up @@ -86,6 +87,12 @@ pub trait Psp22Reward: Internal + Storage<Data> + access_control::Internal {

/// claim all pending rewards for the given account
/// After claiming, there is not anymore pending rewards for this account
#[ink(message)]
#[openbrush::modifiers(access_control::only_role(CLAIMER_FROM))]
fn claim_from(&mut self, from: AccountId) -> Result<(), RewardError> {
self._claim_from(from)
}

fn _claim_from(&mut self, from: AccountId) -> Result<(), RewardError> {
// get all pending rewards for this account
match self.data::<Data>().pending_rewards.get(&from) {
Expand Down

0 comments on commit dcdff4b

Please sign in to comment.