Package zephyr.wallet.model
Class ZephyrBalance
java.lang.Object
zephyr.wallet.model.ZephyrBalance
Balances per asset: a map from asset name to amount in atomic units.
The JSON form is the plain object {asset: amount} that the core emits. The asset is an open
string (see
ZephyrAssets).-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty balance.ZephyrBalance(Map<String, BigInteger> balances) Constructs a balance from a map of asset to amount. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Returns a copy of this balance.booleanCompares two balances per asset.Returns the amount of one asset.Returns the asset names present in this balance.inthashCode()Returns a hash code consistent withequals(Object): entries with a zero amount do not contribute, so a balance that lists an asset at zero hashes like one that omits it.booleanisEmpty()Indicates whether this balance has no asset entries.set(String assetType, BigInteger amount) Sets the amount of one asset.toMap()Returns the balances as a map; this is also the JSON form.toString()toString(int indent) Returns one line per asset.
-
Constructor Details
-
ZephyrBalance
public ZephyrBalance()Constructs an empty balance. -
ZephyrBalance
Constructs a balance from a map of asset to amount.- Parameters:
balances- maps asset name to amount in atomic units (copied)
-
-
Method Details
-
get
Returns the amount of one asset.- Parameters:
assetType- is the asset name- Returns:
- the amount in atomic units,
BigInteger.ZEROwhen the asset is absent, never null
-
set
Sets the amount of one asset.- Parameters:
assetType- is the asset nameamount- is the amount in atomic units- Returns:
- this balance for chaining
-
getAssetTypes
Returns the asset names present in this balance.- Returns:
- the asset names, sorted (unmodifiable)
-
toMap
Returns the balances as a map; this is also the JSON form.- Returns:
- the map of asset name to amount, sorted by asset (unmodifiable)
-
isEmpty
public boolean isEmpty()Indicates whether this balance has no asset entries.- Returns:
- true if there are no asset entries, false otherwise
-
copy
Returns a copy of this balance.- Returns:
- the copy
-
toString
-
toString
Returns one line per asset.- Parameters:
indent- indents the lines- Returns:
- the human-friendly string
-
hashCode
public int hashCode()Returns a hash code consistent withequals(Object): entries with a zero amount do not contribute, so a balance that lists an asset at zero hashes like one that omits it. -
equals
Compares two balances per asset. An asset that is absent from one balance counts as zero, so the wallet-level balance (which lists every asset, zeros included) equals an account or subaddress balance (which lists only the assets it holds) when the amounts agree.
-