Return token amounts as floats (#11370)

* Return token amounts as floats

* Floating-point equality

* Return float and raw token amounts

* Fix decimals and token rpcs for native-mint tokens

* Fixup docs and review comments
This commit is contained in:
Tyera Eulberg
2020-08-05 00:48:09 -06:00
committed by GitHub
parent 14339dec0a
commit 86e3f96f16
5 changed files with 152 additions and 64 deletions

View File

@@ -734,7 +734,7 @@ impl RpcClient {
})
}
pub fn get_token_account_balance(&self, pubkey: &Pubkey) -> ClientResult<u64> {
pub fn get_token_account_balance(&self, pubkey: &Pubkey) -> ClientResult<RpcTokenAmount> {
Ok(self
.get_token_account_balance_with_commitment(pubkey, CommitmentConfig::default())?
.value)
@@ -744,7 +744,7 @@ impl RpcClient {
&self,
pubkey: &Pubkey,
commitment_config: CommitmentConfig,
) -> RpcResult<u64> {
) -> RpcResult<RpcTokenAmount> {
self.send(
RpcRequest::GetTokenAccountBalance,
json!([pubkey.to_string(), commitment_config]),
@@ -841,7 +841,7 @@ impl RpcClient {
})
}
pub fn get_token_supply(&self, mint: &Pubkey) -> ClientResult<u64> {
pub fn get_token_supply(&self, mint: &Pubkey) -> ClientResult<RpcTokenAmount> {
Ok(self
.get_token_supply_with_commitment(mint, CommitmentConfig::default())?
.value)
@@ -851,7 +851,7 @@ impl RpcClient {
&self,
mint: &Pubkey,
commitment_config: CommitmentConfig,
) -> RpcResult<u64> {
) -> RpcResult<RpcTokenAmount> {
self.send(
RpcRequest::GetTokenSupply,
json!([mint.to_string(), commitment_config]),