pub struct BalanceTable<'a, BS>(/* private fields */);Expand description
Balance table which handles getting and updating token balances specifically
Implementations§
Source§impl<'a, BS> BalanceTable<'a, BS>where
BS: Blockstore,
impl<'a, BS> BalanceTable<'a, BS>where
BS: Blockstore,
Sourcepub fn from_root(bs: &'a BS, cid: &Cid) -> Result<Self, Error>
pub fn from_root(bs: &'a BS, cid: &Cid) -> Result<Self, Error>
Initializes a balance table from a root Cid
Sourcepub fn get(&self, key: &Address) -> Result<TokenAmount, Error>
pub fn get(&self, key: &Address) -> Result<TokenAmount, Error>
Gets token amount for given address in balance table
Sourcepub fn add(&mut self, key: &Address, value: &TokenAmount) -> Result<(), Error>
pub fn add(&mut self, key: &Address, value: &TokenAmount) -> Result<(), Error>
Adds token amount to previously initialized account.
Sourcepub fn subtract_with_minimum(
&mut self,
key: &Address,
req: &TokenAmount,
floor: &TokenAmount,
) -> Result<TokenAmount, Error>
pub fn subtract_with_minimum( &mut self, key: &Address, req: &TokenAmount, floor: &TokenAmount, ) -> Result<TokenAmount, Error>
Subtracts up to the specified amount from a balance, without reducing the balance below some minimum. Returns the amount subtracted (always positive or zero).
Sourcepub fn must_subtract(
&mut self,
key: &Address,
req: &TokenAmount,
) -> Result<(), Error>
pub fn must_subtract( &mut self, key: &Address, req: &TokenAmount, ) -> Result<(), Error>
Subtracts value from a balance, and errors if full amount was not substracted.
Sourcepub fn total(&self) -> Result<TokenAmount, Error>
pub fn total(&self) -> Result<TokenAmount, Error>
Returns total balance held by this balance table
Auto Trait Implementations§
impl<'a, BS> Freeze for BalanceTable<'a, BS>
impl<'a, BS> RefUnwindSafe for BalanceTable<'a, BS>where
BS: RefUnwindSafe,
impl<'a, BS> Send for BalanceTable<'a, BS>where
BS: Sync,
impl<'a, BS> !Sync for BalanceTable<'a, BS>
impl<'a, BS> Unpin for BalanceTable<'a, BS>
impl<'a, BS> UnwindSafe for BalanceTable<'a, BS>where
BS: RefUnwindSafe,
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> 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