-
Notifications
You must be signed in to change notification settings - Fork 100
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
Convert InteropInterface<IEnumerator> to Array for RpcClient to digest #245
Conversation
@@ -70,6 +75,27 @@ private JObject GetInvokeResult(byte[] script, IVerifiable checkWitnessHashes = | |||
return json; | |||
} | |||
|
|||
public static StackItem[] ConvertIEnumeratorToArray(StackItem[] stackItems) |
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.
If we change the items in the same array, we should not return an array, because it's the same.
12345, | ||
"hello", | ||
new InteropInterface(new int[] { 1, 2, 3 }.GetEnumerator()), | ||
new InteropInterface(new Nep5AccountState[] {new Nep5AccountState()}.GetEnumerator()) |
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.
Could add a StorageMap
type here, which used in nep11, see neo-project/neo-devpack-dotnet#268
while (enumerator.MoveNext()) | ||
{ | ||
var current = enumerator.Current; | ||
array.Add(current is StackItem stackItem ? stackItem : current is IInteroperable interoperable ? interoperable.ToStackItem(null) : new InteropInterface(current)); |
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.
This line is too line to read, it's better to split into multiple lines.
If the contract contains return Enumerator<byte[]> , an exception will be thrown when call invokefunction. Contract like: public static Enumerator<byte[]> GetEnumerator()
{
var a = new byte[] { 0x22, 0x32, 0x24 };
var b = new byte[] { 0x10, 0x11, 0x22 };
var c = new byte[] { 0x33, 0x44, 0x55 };
var enumerator = Enumerator<byte[]>.Create(new byte[3][] { a, b, c });
return enumerator;
} invokefunction:
result:
|
Co-authored-by: HaoqiangZhang <gripzhang@outlook.com>
just to mention that this is pretty important to us since many of our tests are failing at the moment (we had to ignore them) due to this. 😄 |
This PR also closes #254 Now the |
Please review this PR.@erikzhang |
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.
If the enumerator returns too many items, it may cause out of memory exception. That's why we need enumerator instead of using array directly.
Paging does not solve all problems. Because if the user requests the last page, you have to traverse all the items. |
@erikzhang @shargon @gsmachado @Tommo-L Got any other ideas? 🤔😂 |
Currently the only way I can think of is to modify the API of the contract so that the results returned by the contract support paging natively. But one problem I can't solve this way is that |
So I don't think RPC should do the conversion anymore. |
Maybe we should limit to the X first registers, and allow more by config. Then you can allow to your own node to return whole data |
I think it's okay.
We can create a |
int low = page * ResultsPerPage; // 0, 50, 100... | ||
int high = (page + 1) * ResultsPerPage - 1; // 49, 99, 149... | ||
while (sysEnum.MoveNext() && index <= high) | ||
{ |
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.
maxPage in config?
Close #230
Any suggestions and modifications are welcome.