Skip to main content

WalletBalance

Struct WalletBalance 

Source
pub struct WalletBalance {
    pub native_currency: Option<Money>,
    pub token_balances: Vec<TokenBalance>,
    pub token_universe: HashSet<Address>,
}
Expand description

Represents the complete balance state of a blockchain wallet.

Tracks both the native currency balance (e.g., ETH, ARB) and ERC-20 token balances for a wallet address. The token_universe defines which tokens should be tracked for balance fetching.

Fields§

§native_currency: Option<Money>

The balance of the chain’s native currency

§token_balances: Vec<TokenBalance>

Collection of ERC-20 token balances held in the wallet.

§token_universe: HashSet<Address>

Set of token addresses to track for balance updates.

Implementations§

Source§

impl WalletBalance

Source

pub const fn new(token_universe: HashSet<Address>) -> Self

Creates a new WalletBalance with the specified token universe.

Source

pub fn is_token_universe_initialized(&self) -> bool

Returns true if the token universe has been initialized with token addresses.

Source

pub fn set_native_currency_balance(&mut self, balance: Money)

Sets the native currency balance for the wallet.

Source

pub fn add_token_balance(&mut self, token_balance: TokenBalance)

Adds an ERC-20 token balance to the wallet.

Source

pub fn replace_balances( &mut self, native_currency: Money, token_balances: Vec<TokenBalance>, ) -> Result<Vec<AccountBalance>>

Replaces the complete native and token balance snapshot.

§Errors

Returns an error if the token balances do not exactly match the configured universe, contain duplicate currencies, or cannot be represented as account balances. The existing snapshot remains unchanged on error.

Source

pub fn as_account_balances(&self) -> Result<Vec<AccountBalance>>

Returns the complete wallet snapshot as account balances.

§Errors

Returns an error if the snapshot is incomplete, contains duplicate currencies, or a token amount cannot be represented as money.

Trait Implementations§

Source§

impl Debug for WalletBalance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

impl<T> Ungil for T
where T: Send,