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

How are NEP11 Tokens / TokensOf methods supposed to be invoked #647

Closed
devhawk opened this issue Jun 23, 2021 · 5 comments
Closed

How are NEP11 Tokens / TokensOf methods supposed to be invoked #647

devhawk opened this issue Jun 23, 2021 · 5 comments

Comments

@devhawk
Copy link
Contributor

devhawk commented Jun 23, 2021

Can someone please share code demonstrating how to invoke a method that returns an Iterator such as NEP11 Tokens or TokensOf

@ProDog
Copy link
Contributor

ProDog commented Jun 23, 2021

        private void TokensOf()
        {
            byte[] script;
            using (ScriptBuilder sb = new ScriptBuilder())
            {
                sb.EmitDynamicCall(UInt160.Parse("0x324552a48aaee3be71f6ab3a4edb971c6d5c1ae2"), "tokensOf", UInt160.Parse("0xbed7d6494ceb31c82630de657cbb1e7fc1254469"));
                script = sb.ToArray();
            }

            RpcInvokeResult invokeResult = _rpcClient.InvokeScriptAsync(script, new Signer[] { }).Result;
        }

@devhawk
Copy link
Contributor Author

devhawk commented Jun 23, 2021

How are you supposed to get the results of the iterator out of the RpcInvokeResult?

The JSON returned from invokescript will include up to RpcServerSettings.MaxIteratorResultItems. Here's an example of the JSON returned from tokensOf for a NEP-11 sample I've built:

{
    "script": "DBQAAAAAAAAAAAAAAAAAAAAAAAAAABHAHwwIdG9rZW5zT2YMFJpa9Q5eO0wZ\u002BCiMbClC50kOH5vlQWJ9W1I=",
    "state": "HALT",
    "gasconsumed": "2538240",
    "exception": null,
    "stack": [
        {
            "type": "InteropInterface",
            "iterator": [
                {
                    "type": "ByteString",
                    "value": "MCzYlCuv8ZFJBafDBVfbFAhXs6UN0UTp05b7dVH\u002BJ6k="
                },
                {
                    "type": "ByteString",
                    "value": "PeIWEBz1lPu7Q8\u002BZ5u0/xUr7Lku9EPiLpfpBabZIySM="
                },
                {
                    "type": "ByteString",
                    "value": "nKO\u002BA7byvYwio1pv0GJnKJGdx3lDgF0Y8JZPvpZUflA="
                }
            ],
            "truncated": false
        }
    ]
}

However, Utility.StackItemFromJson doesn't parse the iterator property when it encounters an InteropInterface type:

public static StackItem StackItemFromJson(JObject json)
{
    StackItemType type = json["type"].TryGetEnum<StackItemType>();
    switch (type)
    {
        // other StackItemType case blocks omitted for clarity
        case StackItemType.InteropInterface:
            return new InteropInterface(new object()); // See https://github.com/neo-project/neo/blob/master/src/neo/VM/Helper.cs#L194
    }
    return json["value"] is null ? StackItem.Null : json["value"].AsString();
}

@devhawk
Copy link
Contributor Author

devhawk commented Jun 23, 2021

It appears that I have to use RpcClient.RpcSendAsync and parse the resulting JSON manually.

@devhawk
Copy link
Contributor Author

devhawk commented Jun 23, 2021

Also, since the RPC server will only return the first MaxIteratorResultItems items in the JSON, how does one access additional items? For example, if I own 110 tokens, and MaxIteratorResultItems is set to the default of 100, how do I get information about tokens 101 thru 110?

@devhawk
Copy link
Contributor Author

devhawk commented Oct 20, 2021

Note, this issue may be a more specific duplicate of neo-project/neo-modules#629

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

No branches or pull requests

3 participants