pub struct BalanceTree<const P: u8 = 2> { /* private fields */ }Expand description
One (currency, layer) of a seal: accounts leaves, the non-zero ones kept.
use doubleentry::{AccountHandle, Balance, Layer, Side, amount, currency::EUR, log::BalanceTree};
let mut tree: BalanceTree = BalanceTree::new(EUR, Layer::Settled, 3);
let cash = Balance::ZERO.post(Side::Debit, amount!("1190.00"))?;
let sales = Balance::ZERO.post(Side::Credit, amount!("1190.00"))?;
tree.set(AccountHandle::new(0).unwrap(), cash)?;
tree.set(AccountHandle::new(2).unwrap(), sales)?;
assert_eq!(
tree.root().to_string(),
"61a2dffcc9633717adfac15db9f40c2f9390bfab45181a7e2dad078cf25451e8",
);Implementations§
Source§impl<const P: u8> BalanceTree<P>
impl<const P: u8> BalanceTree<P>
Sourcepub const fn new(currency: Currency, layer: Layer, accounts: u32) -> Self
pub const fn new(currency: Currency, layer: Layer, accounts: u32) -> Self
An all-zero tree of accounts leaves.
Sourcepub fn set(
&mut self,
handle: AccountHandle,
balance: Balance<P>,
) -> Result<(), ProofError>
pub fn set( &mut self, handle: AccountHandle, balance: Balance<P>, ) -> Result<(), ProofError>
Sets a handle’s balance; a zero balance removes it.
§Errors
ProofError::IndexOutOfRange for a handle not below accounts.
Sourcepub fn totals(&self) -> Result<Balance<P>, AmountError>
pub fn totals(&self) -> Result<Balance<P>, AmountError>
Sourcepub fn head(&self) -> Result<TreeHeadEntry<P>, AmountError>
pub fn head(&self) -> Result<TreeHeadEntry<P>, AmountError>
Sourcepub fn prove(
&self,
handle: AccountHandle,
) -> Result<BalanceProof<P>, ProofError>
pub fn prove( &self, handle: AccountHandle, ) -> Result<BalanceProof<P>, ProofError>
The proof of one handle’s balance (the zero leaf for an account without postings).
§Errors
ProofError::IndexOutOfRange for a handle not below accounts.
Trait Implementations§
Source§impl<const P: u8> Clone for BalanceTree<P>
impl<const P: u8> Clone for BalanceTree<P>
Source§impl<const P: u8> Debug for BalanceTree<P>
impl<const P: u8> Debug for BalanceTree<P>
impl<const P: u8> Eq for BalanceTree<P>
Auto Trait Implementations§
impl<const P: u8 = 2> !Freeze for BalanceTree<P>
impl<const P: u8> RefUnwindSafe for BalanceTree<P>
impl<const P: u8> Send for BalanceTree<P>
impl<const P: u8> Sync for BalanceTree<P>
impl<const P: u8> Unpin for BalanceTree<P>
impl<const P: u8> UnsafeUnpin for BalanceTree<P>
impl<const P: u8> UnwindSafe for BalanceTree<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more