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
impl WalletBalance
Sourcepub const fn new(token_universe: HashSet<Address>) -> Self
pub const fn new(token_universe: HashSet<Address>) -> Self
Creates a new WalletBalance with the specified token universe.
Sourcepub fn is_token_universe_initialized(&self) -> bool
pub fn is_token_universe_initialized(&self) -> bool
Returns true if the token universe has been initialized with token addresses.
Sourcepub fn set_native_currency_balance(&mut self, balance: Money)
pub fn set_native_currency_balance(&mut self, balance: Money)
Sets the native currency balance for the wallet.
Sourcepub fn add_token_balance(&mut self, token_balance: TokenBalance)
pub fn add_token_balance(&mut self, token_balance: TokenBalance)
Adds an ERC-20 token balance to the wallet.
Sourcepub fn replace_balances(
&mut self,
native_currency: Money,
token_balances: Vec<TokenBalance>,
) -> Result<Vec<AccountBalance>>
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.
Sourcepub fn as_account_balances(&self) -> Result<Vec<AccountBalance>>
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.