Skip to content
Permalink
Browse files

Make account details gettable from ledger

  • Loading branch information...
CodeSandwich committed May 14, 2019
1 parent e4fa5a1 commit 49c1c5c7a5dc8b7d95d716ce0cb1aefd9aaad08c
Showing with 22 additions and 0 deletions.
  1. +18 −0 chain-impl-mockchain/src/account.rs
  2. +4 −0 chain-impl-mockchain/src/ledger.rs
@@ -125,6 +125,10 @@ impl State {
pub fn get_value(&self) -> Value {
self.value
}

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

/// Spending counter associated to an account.
@@ -148,12 +152,19 @@ impl SpendingCounter {
self.0.to_le_bytes()
}
}

impl From<u32> for SpendingCounter {
fn from(v: u32) -> Self {
SpendingCounter(v)
}
}

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

/// Account Spending witness, which contains a
/// cryptographic signature and a counter.
/// The counter need to be matched with the current state of this account in the ledger,
@@ -194,6 +205,13 @@ impl Ledger {
self.0.contains_key(account)
}

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

/// Remove an account from this ledger
///
/// If the account still have value > 0, then error
@@ -444,6 +444,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 49c1c5c

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