Skip to content
Permalink
Browse files

Make account details gettable from ledger

  • Loading branch information...
CodeSandwich committed May 14, 2019
1 parent 323c2e4 commit b0f18cbfba60ce062f838c802f3bf093b7ef31e7
Showing with 21 additions and 0 deletions.
  1. +17 −0 chain-impl-mockchain/src/accounting/account.rs
  2. +4 −0 chain-impl-mockchain/src/ledger.rs
@@ -95,6 +95,10 @@ impl AccountState {
pub fn get_value(&self) -> Value {
self.value
}

pub fn get_counter(&self) -> u32 {
self.counter.into()
}
}

/// Spending counter associated to an account.
@@ -126,6 +130,12 @@ impl From<u32> for SpendingCounter {
}
}

impl Into<u32> for SpendingCounter {
fn into(self) -> u32 {
self.0
}
}

/// The public ledger of all accounts associated with their current state
#[derive(Clone)]
pub struct Ledger<ID: Hash + Eq>(Hamt<DefaultHasher, ID, AccountState>);
@@ -152,6 +162,13 @@ impl<ID: Clone + Eq + Hash> Ledger<ID> {
self.0.contains_key(identifier)
}

/// Get account state
///
/// If the identifier does not match any account, error out
pub fn get_state(&self, account: &ID) -> Result<&AccountState, LedgerError> {
self.0.lookup(account).ok_or(LedgerError::NonExistent)
}

/// Remove an account from this ledger
///
/// If the account still have value > 0, then error
@@ -464,6 +464,10 @@ impl Ledger {
self.static_params.as_ref()
}

pub fn accounts(&self) -> &account::Ledger {
&self.accounts
}

pub fn get_ledger_parameters(&self) -> LedgerParameters {
LedgerParameters {
fees: *self.settings.linear_fees,

0 comments on commit b0f18cb

Please sign in to comment.
You can’t perform that action at this time.