Return token amounts as floats (bp #11370) (#11378)

* 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

(cherry picked from commit 86e3f96f16)

# Conflicts:
#	core/src/rpc.rs

* Fix conflicts

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
mergify[bot]
2020-08-05 08:31:22 +00:00
committed by GitHub
parent c14f98c6fc
commit 80525ac862
5 changed files with 152 additions and 64 deletions

View File

@@ -1031,7 +1031,11 @@ Returns the token balance of an SPL Token account.
#### Results:
- `RpcResponse<u64>` - RpcResponse JSON object with `value` field set to the balance
The result will be an RpcResponse JSON object with `value` equal to a JSON object containing:
- `uiAmount: <f64>` - the balance, using mint-prescribed decimals
- `amount: <string>` - the raw balance without decimals, a string representation of u64
- `decimals: <u8>` - number of base 10 digits to the right of the decimal place
#### Example:
@@ -1039,7 +1043,7 @@ Returns the token balance of an SPL Token account.
// Request
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getTokenAccountBalance", "params": ["7fUAJdStEuGbc3sM84cKRL6yYaaSstyLSU4ve5oovLS7"]}' http://localhost:8899
// Result
{"jsonrpc":"2.0","result":{"context":{"slot":1114},"value":9864,"id":1}
{"jsonrpc":"2.0","result":{"context":{"slot":1114},"value":{"uiAmount":98.64,"amount":"9864","decimals":2},"id":1}
```
### getTokenAccountsByDelegate
@@ -1125,7 +1129,11 @@ Returns the total supply of an SPL Token type.
#### Results:
- `RpcResponse<u64>` - RpcResponse JSON object with `value` field set to the total token supply
The result will be an RpcResponse JSON object with `value` equal to a JSON object containing:
- `uiAmount: <f64>` - the total token supply, using mint-prescribed decimals
- `amount: <string>` - the raw total token supply without decimals, a string representation of u64
- `decimals: <u8>` - number of base 10 digits to the right of the decimal place
#### Example:
@@ -1133,7 +1141,7 @@ Returns the total supply of an SPL Token type.
// Request
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getTokenSupply", "params": ["3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E"]}' http://localhost:8899
// Result
{"jsonrpc":"2.0","result":{"context":{"slot":1114},"value":100000,"id":1}
{"jsonrpc":"2.0","result":{"context":{"slot":1114},"value":{"uiAmount":1000.0,"amount":"100000","decimals":2},"id":1}
```
### getTransactionCount