pub type Ledger = Ledger<Identifier, ()>;
Expand description

The public ledger of all accounts associated with their current state

Aliased Type§

struct Ledger(Hamt<DefaultHasher, Identifier, AccountState<()>>);

Fields§

§0: Hamt<DefaultHasher, Identifier, AccountState<()>>

Implementations§

source§

impl<ID: Clone + Eq + Hash, Extra: Clone> Ledger<ID, Extra>

source

pub fn new() -> Self

Create a new empty account ledger

source

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.

source

pub fn set_delegation( &self, identifier: &ID, delegation: &DelegationType ) -> Result<Self, LedgerError>

Set the delegation of an account in this ledger

source

pub fn exists(&self, identifier: &ID) -> bool

check if an account already exist

source

pub fn get_state( &self, account: &ID ) -> Result<&AccountState<Extra>, LedgerError>

Get account state

If the identifier does not match any account, error out

source

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

source

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.

source

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

source

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

source

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.

source

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.

source

pub fn get_total_value(&self) -> Result<Value, ValueError>

source

pub fn token_add( &self, identifier: &ID, token: TokenIdentifier, value: Value ) -> Result<Self, LedgerError>

source

pub fn iter(&self) -> Iter<'_, ID, Extra>

Trait Implementations§

source§

impl<ID: Clone + Hash + Eq, Extra: Clone> Clone for Ledger<ID, Extra>

source§

fn clone(&self) -> Ledger<ID, Extra>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<ID: Clone + Eq + Hash + Debug, Extra: Clone + Debug> Debug for Ledger<ID, Extra>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<ID: Clone + Eq + Hash, Extra: Clone> Default for Ledger<ID, Extra>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<ID: Clone + Eq + Hash, Extra: Clone> FromIterator<(ID, AccountState<Extra>)> for Ledger<ID, Extra>

source§

fn from_iter<I: IntoIterator<Item = (ID, AccountState<Extra>)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<ID: PartialEq + Hash + Eq, Extra: PartialEq> PartialEq<Ledger<ID, Extra>> for Ledger<ID, Extra>

source§

fn eq(&self, other: &Ledger<ID, Extra>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<ID: Eq + Hash + Eq, Extra: Eq> Eq for Ledger<ID, Extra>

source§

impl<ID: Hash + Eq, Extra> StructuralEq for Ledger<ID, Extra>

source§

impl<ID: Hash + Eq, Extra> StructuralPartialEq for Ledger<ID, Extra>