itering / scale.go

Golang polkadot substrate scale codec
http://subscan.io
Apache License 2.0
63 stars 36 forks source link

How to parse OpaqueCall value? #46

Closed crossle closed 3 years ago

crossle commented 3 years ago
Screen Shot 2021-11-04 at 23 10 41
freehere107 commented 3 years ago
m := types.ScaleDecoder{}
m.Init(types.ScaleBytes{Data: util.HexToBytes(raw)}, types.ScaleDecoderOption{Metadata:Metadata})
m.ProcessAndUpdateData("OpaqueCall")
crossle commented 3 years ago
m := types.ScaleDecoder{}
m.Init(types.ScaleBytes{Data: util.HexToBytes(raw)}, types.ScaleDecoderOption{Metadata:Metadata})
m.ProcessAndUpdateData("OpaqueCall")

get empty data. map[call_index: call_module: call_name: params:[]]

freehere107 commented 3 years ago

@crossle Can you paste your code?

crossle commented 3 years ago
            m := types.ScaleDecoder{}
            m.Init(types.ScaleBytes{Data: util.HexToBytes("05000061d0f165cc77b059f1ac1fe2598cd90f487ab60dc26c63d7633852d554ad1db50700e40b5402")}, &types.ScaleDecoderOption{Metadata: metadataRaw})
            a := m.ProcessAndUpdateData("OpaqueCall")

metadata raw from state_getMetadata on the block 7329637

freehere107 commented 3 years ago

@crossle ok, this type is Call, usetype field you can use this m.ProcessAndUpdateData("Call") will get

{
  "call_index": "0500",
  "call_module": "Authorship",
  "call_name": "set_uncles",
  "params": [
    {
      "name": "new_uncles",
      "type": "Vec\u003cHeader\u003e",
      "value": null
    }
  ]
}
crossle commented 3 years ago

Got it, Thanks.