Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem: Updating precision for all tokens is very expensive
Fix: Don't load precision from stats table - load it dynamically whenever the token balance is loaded
Why this works: We only need token precision for display and importantly for "send" - prior to display and send we must update the balances; therefore this will not cause any problems.
Tech Notes
In theory token balances are always loaded before we display, and certainly before we send. Also precision never dynamically changes so once we load it, it never changes - ever. That's guaranteed by the token contract in EOSIO.
Testing
Tested "send" with a few different tokens, it works.
Also monitored that as token balances are received, we update the precision.
Future Improvements
It would be nice to remove the tokens table and to package the side effect code a bit better.
I didn't remove the static table because I wasn't sure we have a comprehensive list of "all tokens" anymore since the token master contract change, so I don't know if all known tokens are always there. I believe they probably are - but not sure.