Struct chain_impl_mockchain::accounting::account::Ledger
source · pub struct Ledger<ID: Hash + Eq, Extra>(Hamt<DefaultHasher, ID, AccountState<Extra>>);
Expand description
The public ledger of all accounts associated with their current state
Tuple Fields§
§0: Hamt<DefaultHasher, ID, AccountState<Extra>>
Implementations§
source§impl<ID: Clone + Eq + Hash, Extra: Clone> Ledger<ID, Extra>
impl<ID: Clone + Eq + Hash, Extra: Clone> Ledger<ID, Extra>
sourcepub fn add_account(
&self,
identifier: ID,
initial_value: Value,
extra: Extra
) -> Result<Self, LedgerError>
pub fn add_account( &self, identifier: ID, initial_value: Value, extra: Extra ) -> Result<Self, LedgerError>
Add a new account into this ledger.
If the identifier is already present, error out.
sourcepub fn set_delegation(
&self,
identifier: &ID,
delegation: &DelegationType
) -> Result<Self, LedgerError>
pub fn set_delegation( &self, identifier: &ID, delegation: &DelegationType ) -> Result<Self, LedgerError>
Set the delegation of an account in this ledger
sourcepub fn get_state(
&self,
account: &ID
) -> Result<&AccountState<Extra>, LedgerError>
pub fn get_state( &self, account: &ID ) -> Result<&AccountState<Extra>, LedgerError>
Get account state
If the identifier does not match any account, error out
sourcepub fn remove_account(&self, identifier: &ID) -> Result<Self, LedgerError>
pub fn remove_account(&self, identifier: &ID) -> Result<Self, LedgerError>
Remove an account from this ledger
If the account still have value > 0, then error
sourcepub fn add_value(
&self,
identifier: &ID,
value: Value
) -> Result<Self, LedgerError>
pub fn add_value( &self, identifier: &ID, value: Value ) -> Result<Self, LedgerError>
Add value to an existing account.
If the account doesn’t exist, error out.
sourcepub fn add_value_or_account(
&self,
identifier: &ID,
value: Value,
extra: Extra
) -> Result<Self, ValueError>
pub fn add_value_or_account( &self, identifier: &ID, value: Value, extra: Extra ) -> Result<Self, ValueError>
Add value to an existing account.
If the account doesn’t exist, it creates it with the value
sourcepub fn add_rewards_to_account(
&self,
identifier: &ID,
epoch: Epoch,
value: Value,
extra: Extra
) -> Result<Self, ValueError>
pub fn add_rewards_to_account( &self, identifier: &ID, epoch: Epoch, value: Value, extra: Extra ) -> Result<Self, ValueError>
Add rewards to an existing account.
If the account doesn’t exist, it creates it with the value
sourcepub fn spend(
&self,
identifier: &ID,
counter: SpendingCounter,
value: Value
) -> Result<Self, LedgerError>
pub fn spend( &self, identifier: &ID, counter: SpendingCounter, value: Value ) -> Result<Self, LedgerError>
Spend value from an existing account.
If the account doesn’t exist, or if the value is too much to spend,
or if the spending counter doesn’t match, it throws a LedgerError
.
sourcepub(crate) fn spend_with_no_counter_check(
&self,
identifier: &ID,
counter: SpendingCounter,
value: Value
) -> Result<Self, LedgerError>
pub(crate) fn spend_with_no_counter_check( &self, identifier: &ID, counter: SpendingCounter, value: Value ) -> Result<Self, LedgerError>
Spend value from an existing account without spending counter check.
If the account doesn’t exist, or if the value is too much to spend,
it throws a LedgerError
.