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

[RpcClient] RpcApplicationLog not able to deal with auto-claim gas records in ToJson() method #369

Closed
cloud8little opened this issue Oct 10, 2020 · 0 comments · Fixed by #371

Comments

@cloud8little
Copy link
Contributor

Describe the bug
Use RpcClient to call following code.

RpcApplicationLog applicationLog = rpcClient.GetApplicationLogAsync("0x96cb71e07a998ef4de61cffa5ac6966c25d8e45c09154cacc0b3d1fc3f2c6c87").Result;
Console.WriteLine(applicationLog.ToJson());

use rpcserver:

Request:

{
  "jsonrpc": "2.0",
  "method": "getapplicationlog",
  "params": ["0x96cb71e07a998ef4de61cffa5ac6966c25d8e45c09154cacc0b3d1fc3f2c6c87"],
  "id": 1
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "txid": "0x96cb71e07a998ef4de61cffa5ac6966c25d8e45c09154cacc0b3d1fc3f2c6c87",
    "trigger": "Application",
    "vmstate": "HALT",
    "gasconsumed": "9007960",
    "stack": [
      {
        "type": "Boolean",
        "value": true
      }
    ],
    "notifications": [
      {
        "contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
        "eventname": "Transfer",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "Any"
            },
            {
              "type": "ByteString",
              "value": "sTvq6eLtwtEFXYEWs3q3ccXFRnY="
            },
            {
              "type": "Integer",
              "value": "8500"
            }
          ]
        }
      },
      {
        "contract": "0xde5f57d430d3dece511cf975a8d37848cb9e0525",
        "eventname": "Transfer",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteString",
              "value": "sTvq6eLtwtEFXYEWs3q3ccXFRnY="
            },
            {
              "type": "ByteString",
              "value": "Wejy6zUhjWo8DyOhafPXyv8r3Sg="
            },
            {
              "type": "Integer",
              "value": "1"
            }
          ]
        }
      }
    ]
  }
}

Expected behavior
RpcApplicationLog should deal with Type: Any correctly.

Screenshots
eb9d2c4327987b8b130557549bc6b14
e2d053cd5f5e04941a26d8e4a80c31f

Platform:

  • OS: Windows 10 x64
  • Version neo-modules:

Root Cause:

public static RpcNotifyEventArgs FromJson(JObject json)
{
return new RpcNotifyEventArgs
{
Contract = json["contract"].ToScriptHash(),
EventName = json["eventname"].AsString(),
State = Utility.StackItemFromJson(json["state"])

public static StackItem StackItemFromJson(JObject json)
{
StackItemType type = json["type"].TryGetEnum<StackItemType>();
switch (type)
{
case StackItemType.Boolean:
return new Boolean(json["value"].AsBoolean());
case StackItemType.Buffer:
return new Buffer(Convert.FromBase64String(json["value"].AsString()));
case StackItemType.ByteString:
return new ByteString(Convert.FromBase64String(json["value"].AsString()));
case StackItemType.Integer:
return new Integer(new BigInteger(json["value"].AsNumber()));
case StackItemType.Array:
Array array = new Array();
foreach (var item in (JArray)json["value"])
array.Add(StackItemFromJson(item));
return array;
case StackItemType.Struct:
Struct @struct = new Struct();
foreach (var item in (JArray)json["value"])
@struct.Add(StackItemFromJson(item));
return @struct;
case StackItemType.Map:
Map map = new Map();
foreach (var item in (JArray)json["value"])
{
PrimitiveType key = (PrimitiveType)StackItemFromJson(item["key"]);
map[key] = StackItemFromJson(item["value"]);
}
return map;
case StackItemType.Pointer:
return new Pointer(null, (int)json["value"].AsNumber());
case StackItemType.InteropInterface:
return new InteropInterface(new object()); // See https://github.com/neo-project/neo/blob/master/src/neo/VM/Helper.cs#L194
}
return null;

There is no logic for type any, so it returns null which lead to the exception.

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 a pull request may close this issue.

1 participant