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

Fix GetCandidates #2686

Merged
merged 13 commits into from
May 4, 2022
Merged

Fix GetCandidates #2686

merged 13 commits into from
May 4, 2022

Conversation

shargon
Copy link
Member

@shargon shargon commented Apr 7, 2022

Close #2683

@@ -344,7 +344,26 @@ private async ContractTask<bool> Vote(ApplicationEngine engine, UInt160 account,
(
p.Key.Key.AsSerializable<ECPoint>(1),
p.Value.GetInteroperable<CandidateState>()
)).Where(p => p.Item2.Registered).Select(p => (p.Item1, p.Item2.Votes)).ToArray();
)).Where(p => p.Item2.Registered).Select(p => (p.Item1, p.Item2.Votes)).Take(100).ToArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

How does the caller retrieve the remaining candidates if there are more than 100?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think that it's needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This method was used by Grant Shares so or we add a new method for paginate it, or I think that we can't add a new arguments here (without versioning)

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think that it's needed?

Yes, I think it's a bad idea to arbitrarily limit return values without providing a mechanism to paginate. We have similar issues w/ accessing iterators over JSON-RPC (neo-project/neo-modules#629 and neo-project/neo-devpack-dotnet#647)

This method was used by Grant Shares so or we add a new method for paginate it, or I think that we can't add a new arguments here (without versioning)

We can add an overload that takes skip + take parameters and returns a structure that has the (ECPoint PublicKey, BigInteger Votes) tuple array + a boolean to indicate if there are more results (similar to the FindState State Service RPC method). That way we don't break existing callers but we can still provide the full functionality to contracts that switch to the new overload.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please, take a look again

Copy link
Contributor

Choose a reason for hiding this comment

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

This works, though I like the FindState pattern much better.

I decided to build a single GitHub issue to track the Iterator JSON RPC return issue #2699. I actually think it would be pretty straightforward to add Iterator skip support. Assuming we can add that, then we could change GetCandidates to return an Iterator

@devhawk
Copy link
Contributor

devhawk commented Apr 22, 2022

First draft of paged iterator support : neo-project/neo-modules#708

/// <param name="engine">The <see cref="ApplicationEngine"/> that is executing the contract.</param>
/// <returns>All the registered candidates.</returns>
[ContractMethod(CpuFee = 1 << 22, RequiredCallFlags = CallFlags.ReadStates)]
private IIterator GetAllCandidates(ApplicationEngine engine)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm glad you've added this, but we still have no mechanism to retrieve all the values of an iterator over JSON-RPC

@shargon shargon merged commit 9c4aad3 into neo-project:develop May 4, 2022
@shargon shargon deleted the fix-get-candidates branch May 4, 2022 08:06
ixje added a commit to CityOfZion/neo-mamba that referenced this pull request Jun 27, 2022
ixje added a commit to CityOfZion/neo-mamba that referenced this pull request Jun 27, 2022
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.

4 participants