BalanceTable

Struct BalanceTable 

Source
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,

Source

pub fn new(bs: &'a BS) -> Self

Initializes a new empty balance table

Source

pub fn from_root(bs: &'a BS, cid: &Cid) -> Result<Self, Error>

Initializes a balance table from a root Cid

Source

pub fn root(&mut self) -> Result<Cid, Error>

Retrieve root from balance table

Source

pub fn get(&self, key: &Address) -> Result<TokenAmount, Error>

Gets token amount for given address in balance table

Source

pub fn add(&mut self, key: &Address, value: &TokenAmount) -> Result<(), Error>

Adds token amount to previously initialized account.

Source

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).

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.