@@ -17,18 +17,108 @@ use casper_types::{
1717 EntryPointType , EntryPoints , Group , RuntimeArgs , URef , U256 ,
1818} ;
1919
20+ /// Interface of the Reputation Contract.
21+ ///
22+ /// It should be implemented by [`ReputationContract`], [`ReputationContractCaller`]
23+ /// and [`ReputationContractTest`].
2024pub trait ReputationContractInterface {
25+ /// Constructor method.
26+ ///
27+ /// It initializes contract elements:
28+ /// * Events dictionary.
29+ /// * Named keys of [`TokenWithStaking`], [`Owner`] and [`Whitelist`].
30+ /// * Set [`caller`] as the owner of the contract.
31+ /// * Add [`caller`] to the whitelist.
32+ ///
33+ /// It emits [`OwnerChanged`](casper_dao_utils::owner::events::OwnerChanged),
34+ /// [`AddedToWhitelist`](casper_dao_utils::whitelist::events::AddedToWhitelist) events.
2135 fn init ( & mut self ) ;
36+
37+ /// Mint new tokens. Add `amount` of new tokens to the balance of the `recipient` and
38+ /// increment the total supply. Only whitelisted addresses are permited to call this method.
39+ ///
40+ /// It throws [`NotWhitelisted`](casper_dao_utils::Error::NotWhitelisted) if caller
41+ /// is not whitelisted.
42+ ///
43+ /// It emits [`Mint`](casper_dao_utils::token::events::Mint) event.
2244 fn mint ( & mut self , recipient : Address , amount : U256 ) ;
45+
46+ /// Burn existing tokens. Remove `amount` of existing tokens from the balance of the `owner`
47+ /// and decrement the total supply. Only whitelisted addresses are permited to call this
48+ /// method.
49+ ///
50+ /// It throws [`NotWhitelisted`](casper_dao_utils::Error::NotWhitelisted) if caller
51+ /// is not whitelisted.
52+ ///
53+ /// It emits [`Burn`](casper_dao_utils::token::events::Burn) event.
2354 fn burn ( & mut self , owner : Address , amount : U256 ) ;
55+
56+ /// Transfer `amount` of tokens from `owner` to `recipient`. Only whitelisted addresses are
57+ /// permited to call this method.
58+ ///
59+ /// It throws [`NotWhitelisted`](casper_dao_utils::Error::NotWhitelisted) if caller
60+ /// is not whitelisted.
61+ ///
62+ /// It throws [`InsufficientBalance`](casper_dao_utils::Error::InsufficientBalance)
63+ /// if `recipient`'s balance is less then `amount`.
64+ ///
65+ /// It emits [`Transfer`](casper_dao_utils::token::events::Transfer) event.
2466 fn transfer_from ( & mut self , owner : Address , recipient : Address , amount : U256 ) ;
67+
68+ /// Change ownership of the contract. Transfer the ownership to the `owner`. Only current owner
69+ /// is permited to call this method.
70+ ///
71+ /// It throws [`NotAnOwner`](casper_dao_utils::Error::NotAnOwner) if caller
72+ /// is not the current owner.
73+ ///
74+ /// It emits [`OwnerChanged`](casper_dao_utils::owner::events::OwnerChanged),
75+ /// [`AddedToWhitelist`](casper_dao_utils::whitelist::events::AddedToWhitelist) events.
2576 fn change_ownership ( & mut self , owner : Address ) ;
77+
78+ /// Add new address to the whitelist.
79+ ///
80+ /// It throws [`NotAnOwner`](casper_dao_utils::Error::NotAnOwner) if caller
81+ /// is not the current owner.
82+ ///
83+ /// It emits [`AddedToWhitelist`](casper_dao_utils::whitelist::events::AddedToWhitelist) event.
2684 fn add_to_whitelist ( & mut self , address : Address ) ;
85+
86+ /// Remove address from the whitelist.
87+ ///
88+ /// It throws [`NotAnOwner`](casper_dao_utils::Error::NotAnOwner) if caller
89+ /// is not the current owner.
90+ ///
91+ /// It emits [`RemovedFromWhitelist`](casper_dao_utils::whitelist::events::RemovedFromWhitelist)
92+ /// event.
2793 fn remove_from_whitelist ( & mut self , address : Address ) ;
94+
95+ /// Stake `amount` of tokens for the `address`. It decrements `address`'s balance by `amount`.
96+ ///
97+ /// It throws [`NotAnOwner`](casper_dao_utils::Error::NotAnOwner) if caller
98+ /// is not the current owner.
99+ ///
100+ /// It throws [`InsufficientBalance`](casper_dao_utils::Error::InsufficientBalance)
101+ /// if `address`'s balance is less then `amount`.
102+ ///
103+ /// It emits [`TokensStaked`](casper_dao_utils::staking::events::TokensStaked)
104+ /// event.
28105 fn stake ( & mut self , address : Address , amount : U256 ) ;
106+
107+ /// Unstake `amount` of tokens for the `address`. It increments `address`'s balance by
108+ /// `amount`.
109+ ///
110+ /// It throws [`NotAnOwner`](casper_dao_utils::Error::NotAnOwner) if caller
111+ /// is not the current owner.
112+ ///
113+ /// It throws [`InsufficientBalance`](casper_dao_utils::Error::InsufficientBalance)
114+ /// if `address`'s staked amount is less then `amount`.
115+ ///
116+ /// It emits [`TokensUnstaked`](casper_dao_utils::staking::events::TokensUnstaked)
117+ /// event.
29118 fn unstake ( & mut self , address : Address , amount : U256 ) ;
30119}
31120
121+ /// Implementation of the Reputation Contract. See [`ReputationContractInterface`].
32122#[ derive( Default ) ]
33123pub struct ReputationContract {
34124 pub token : TokenWithStaking ,
@@ -148,6 +238,7 @@ impl ReputationContract {
148238 }
149239}
150240
241+ /// Implementation of the Reputation Contract Caller. See [`ReputationContractInterface`].
151242pub struct ReputationContractCaller {
152243 contract_package_hash : ContractPackageHash ,
153244}
@@ -275,6 +366,7 @@ mod tests {
275366
276367 use crate :: { ReputationContract , ReputationContractInterface } ;
277368
369+ /// Implementation of the Reputation Contract Test. See [`ReputationContractInterface`].
278370 pub struct ReputationContractTest {
279371 env : TestEnv ,
280372 package_hash : ContractPackageHash ,
0 commit comments