Convert InteropInterface<IEnumerator> to Array for RpcClient to digest#245
Convert InteropInterface<IEnumerator> to Array for RpcClient to digest#245joeqian10 wants to merge 13 commits intoneo-project:masterfrom
Conversation
| return json; | ||
| } | ||
|
|
||
| public static StackItem[] ConvertIEnumeratorToArray(StackItem[] stackItems) |
There was a problem hiding this comment.
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.
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.
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 |
|
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) | ||
| { |
Close #230
Any suggestions and modifications are welcome.