Returned by MirrorNodeTokenBalanceQuery.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal longThe balance the account holds in this token.final @Nullable IntegerThe number of decimal places the token is divided into, ornullif the mirror node does not report it -- which includes the case where the account is not associated with the token.final TokenIdThe token this balance is for. -
Constructor Summary
ConstructorsConstructorDescriptionMirrorNodeTokenBalance(TokenId tokenId, long balance, @Nullable Integer decimals, boolean associated) Constructor. -
Method Summary
Modifier and TypeMethodDescription(package private) static MirrorNodeTokenBalanceCreate a token balance from a mirror node REST JSON payload.longExtract the balance.@Nullable IntegerExtract the token's decimal places.Extract the token id.booleanWhether the account holds a relationship to this token at all.(package private) static MirrorNodeTokenBalancenotAssociated(TokenId tokenId) A balance for a token the account holds no relationship to -- including the case where the mirror node does not know the account at all.toString()
-
Field Details
-
tokenId
The token this balance is for. -
balance
public final long balanceThe balance the account holds in this token.For a
FUNGIBLE_COMMONtoken this is the amount in the token's smallest denomination. For aNON_FUNGIBLE_UNIQUEtoken this is the number of NFTs the account holds.Zero when the account holds no relationship to the token -- check
isAssociated()to tell that case apart from an associated account whose balance happens to be zero. -
decimals
The number of decimal places the token is divided into, ornullif the mirror node does not report it -- which includes the case where the account is not associated with the token.
-
-
Constructor Details
-
MirrorNodeTokenBalance
MirrorNodeTokenBalance(TokenId tokenId, long balance, @Nullable Integer decimals, boolean associated) Constructor.- Parameters:
tokenId- the token this balance is forbalance- the balance held, in the token's smallest denomination or as an NFT countdecimals- the token's decimal places, may be nullassociated- whether the account holds a relationship to the token at all
-
-
Method Details
-
fromJson
Create a token balance from a mirror node REST JSON payload.The mirror node answers with an empty
tokensarray when the entity exists but holds no relationship to the requested token. That is reported asisAssociated() == falsewith a zero balance, rather than as an error. A non-existent entity is a 404 and never reaches here.- Parameters:
root- the JSON object returned byGET /api/v1/accounts/{id}/tokensrequestedTokenId- the token that was queried, used when the response carries no relationship- Returns:
- the new token balance
-
notAssociated
A balance for a token the account holds no relationship to -- including the case where the mirror node does not know the account at all.- Parameters:
tokenId- the token that was queried- Returns:
- a zero, non-associated balance
-
isAssociated
public boolean isAssociated()Whether the account holds a relationship to this token at all.Use this to distinguish "never associated with the token" from "associated, balance zero" -- both report a
balanceof zero.- Returns:
- true if the account is associated with the token
-
getTokenId
Extract the token id.- Returns:
- the token this balance is for
-
getBalance
public long getBalance()Extract the balance.- Returns:
- the balance held, in the token's smallest denomination or as an NFT count
-
getDecimals
Extract the token's decimal places.- Returns:
- the number of decimal places, or null if not reported
-
toString
-