Skip to content
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

updates balancesActions.js to work with 2.9.0 nodes #1543

Merged
merged 2 commits into from
Oct 19, 2018

Conversation

comountainclimber
Copy link
Contributor

Because nodes running 2.9.0 have been capped at 10 GAS limit for invoke scripts we can no longer request balance info in one RPC call... This PR chunks out the request so that balance data for no more than 4 tokens is ever made at once.

Fixes #1541

Related update: neo-project/neo#397

return accum
}

if (accum[accum.length - 1].length < 4) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 4? a good variable name would help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look guys... so 4 represents the "maximum chunk size" I will go ahead and make this a constant

}

if (accum[accum.length - 1].length < 4) {
accum[accum.length - 1].push(currVal.scriptHash)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this push does not have an array surrounding currVal.scripthash but the rest do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats because its pushing into an existing arr... Think of the structure like this:
[ [hash1, hash2, hash3, hash4], [hash5, hash6, hash7, hash8] ... ]

)
const results = await Promise.all(promiseMap)
const resultObject = results.reduce((result, currentObject) => {
Object.keys(currentObject).forEach(key => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just use return Object.assign({}, currentObject)


const parsedTokenBalances = Object.keys(tokenBalances)
const parsedTokenBalances = Object.keys(resultObject)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could also return the format you need from the reduce method instead of calling object.keys on the data after calling reduce. its not a big deal though unless the data is large and we want to be efficient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@comountainclimber comountainclimber merged commit 18b4f33 into design-v2 Oct 19, 2018
@comountainclimber comountainclimber deleted the feature/chunk-balance-requests branch December 15, 2018 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants