-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return token amounts as floats #11370
Conversation
5b8e5bb
to
21ed9e5
Compare
Looks good, let me try to integrate this into the token cli locally first. I'll respond back here hopefully later tonight |
Codecov Report
@@ Coverage Diff @@
## master #11370 +/- ##
=======================================
Coverage 82.3% 82.3%
=======================================
Files 315 315
Lines 74224 74266 +42
=======================================
+ Hits 61092 61129 +37
- Misses 13132 13137 +5 |
core/src/rpc.rs
Outdated
}) | ||
.map(|account: &mut TokenAccount| account.amount)?; | ||
})?; | ||
let mint_account = bank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check for native_mint::id()
and then use native_mint::DECIMALS
to avoid hitting "Invalid param: could not find mint"
Overall looks good, this PR allowed me to cut out a bunch of client code: solana-labs/solana-program-library@3883174 |
@mvines , do you want the rpc_client balance/supply methods to return the float only? or the complete amount struct? |
afc5269
to
a11a25f
Compare
I've adapted solana-labs/solana-program-library#188 to the latest here. Working great, save for the native_mint issues we've discussed |
039e22d
to
2970587
Compare
@mvines , can you take the native-mint handling for a spin? |
I just did, it works well! |
2970587
to
51dab9e
Compare
6bb27e9
to
e98e509
Compare
* 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 86e3f96) # Conflicts: # core/src/rpc.rs
* 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 86e3f96) # Conflicts: # core/src/rpc.rs * Fix conflicts Co-authored-by: Tyera Eulberg <[email protected]> Co-authored-by: Tyera Eulberg <[email protected]>
Problem
In order to correctly represent a spl-token balance to the user, it needs to be normalized with the mint's decimals value. But getTokenAccountBalance/getTokenSupply don't provide this information.
Summary of Changes
getTokenAccountBalance
andgetTokenSupply
to struct containing ui_amount (f64), amount (string representation of u64), and decimals (u8).getTokenLargestAccounts
amount field to same structFixes #11366