wharfkit / antelope

Core types, client interfaces, and other tools for working with Antelope-based blockchains.
Other
44 stars 23 forks source link

Serializer.decode error: Unknown type #63

Closed cc32d9 closed 1 year ago

cc32d9 commented 1 year ago

Code to reproduce the failure:

https://github.com/EOSChronicleProject/chronos-client-npm/blob/af4762f00d23cdf108e43cb8bd430b7f3c2f2d5e/tmp/wharf_abi_decode_failure.js

Error message:

# node tmp/wharf_abi_decode_failure.js 
node:internal/process/esm_loader:97
    internalBinding('errors').triggerUncaughtException(
                              ^

DecodingError: Unknown type
    at decodeInner (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1246:23)
    at decodeBinary (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1192:16)
    at Object.abiDecode [as decode] (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1144:20)
    at file:///opt/src/chronos-client-npm/tmp/wharf_abi_decode_failure.js:9:25
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
  ctx: {
    types: {
      bool: {
        abiName: 'bool',
        abiDefault: [Function: abiDefault],
        fromABI: [Function: fromABI],
        from: [Function: from],
        toABI: [Function: toABI]
      },
      string: {
        abiName: 'string',
        abiDefault: [Function: abiDefault],
        fromABI: [Function: fromABI],
        from: [Function: from],
        toABI: [Function: toABI]
      },
      asset: [class Asset] {
        abiName: 'asset',
        Symbol: [class Symbol] {
          abiName: 'symbol',
          symbolNamePattern: /^[A-Z]{0,7}$/,
          maxPrecision: 18
        },
        SymbolCode: [class SymbolCode] { abiName: 'symbol_code' }
      },
      symbol: [class Symbol] {
        abiName: 'symbol',
        symbolNamePattern: /^[A-Z]{0,7}$/,
        maxPrecision: 18
      },
      symbol_code: [class SymbolCode] { abiName: 'symbol_code' },
      block_timestamp_type: [class BlockTimestamp extends TimePointBase] {
        abiName: 'block_timestamp_type'
      },
      bytes: [class Bytes] { abiName: 'bytes' },
      checksum160: [class Checksum160 extends Checksum] {
        abiName: 'checksum160',
        byteSize: 20
      },
      checksum256: [class Checksum256 extends Checksum] {
        abiName: 'checksum256',
        byteSize: 32
      },
      checksum512: [class Checksum512 extends Checksum] {
        abiName: 'checksum512',
        byteSize: 64
      },
      extended_asset: [class ExtendedAsset] { abiName: 'extended_asset' },
      float128: [class Float128] { abiName: 'float128', byteWidth: 16 },
      float32: [class Float32 extends Float] { abiName: 'float32', byteWidth: 4 },
      float64: [class Float64 extends Float] { abiName: 'float64', byteWidth: 8 },
      int128: [class Int128 extends Int] {
        abiName: 'int128',
        byteWidth: 16,
        isSigned: true
      },
      int16: [class Int16 extends Int] {
        abiName: 'int16',
        byteWidth: 2,
        isSigned: true
      },
      int32: [class Int32 extends Int] {
        abiName: 'int32',
        byteWidth: 4,
        isSigned: true
      },
      int64: [class Int64 extends Int] {
        abiName: 'int64',
        byteWidth: 8,
        isSigned: true
      },
      int8: [class Int8 extends Int] {
        abiName: 'int8',
        byteWidth: 1,
        isSigned: true
      },
      name: [class Name] { abiName: 'name', pattern: /^[a-z1-5.]{0,13}$/ },
      public_key: [class PublicKey] { abiName: 'public_key' },
      signature: [class Signature] { abiName: 'signature' },
      time_point: [class TimePoint extends TimePointBase] { abiName: 'time_point' },
      time_point_sec: [class TimePointSec extends TimePointBase] {
        abiName: 'time_point_sec'
      },
      uint128: [class UInt128 extends Int] {
        abiName: 'uint128',
        byteWidth: 16,
        isSigned: false
      },
      uint16: [class UInt16 extends Int] {
        abiName: 'uint16',
        byteWidth: 2,
        isSigned: false
      },
      uint32: [class UInt32 extends Int] {
        abiName: 'uint32',
        byteWidth: 4,
        isSigned: false
      },
      uint64: [class UInt64 extends Int] {
        abiName: 'uint64',
        byteWidth: 8,
        isSigned: false
      },
      uint8: [class UInt8 extends Int] {
        abiName: 'uint8',
        byteWidth: 1,
        isSigned: false
      },
      varint32: [class VarInt extends Int] {
        abiName: 'varint32',
        byteWidth: 32,
        isSigned: true
      },
      varuint32: [class VarUInt extends Int] {
        abiName: 'varuint32',
        byteWidth: 32,
        isSigned: false
      }
    },
    strictExtensions: false,
    codingPath: [
      {
        field: 'root',
        type: ResolvedType {
          isExtension: false,
          isOptional: false,
          isArray: false,
          id: 1,
          name: 'claimprize'
        }
      }
    ]
  },
  underlyingError: Error: Unknown type
      at decodeInner (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1246:23)
      at decodeBinary (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1192:16)
      at Object.abiDecode [as decode] (/opt/src/chronos-client-npm/node_modules/@greymass/eosio/lib/eosio-core.js:1144:20)
      at file:///opt/src/chronos-client-npm/tmp/wharf_abi_decode_failure.js:9:25
      at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
}

Node.js v18.13.0

Transaction ID on WAX: bde4e9ad905af3c9ee322473eea25bb7d7529b272c7c884d4dfd9ca00565c213

cc32d9 commented 1 year ago

The ABI has different names for the action and its type: "claimprize" vs. "claim_prize". The values in the data are name, followed by uint16

cc32d9 commented 1 year ago

seems like I see the error: "claimprize" is not a type, so I need to find the action and get its type first

jnordberg commented 1 year ago

Yes, this is not a bug in the decoder. EOSIO ABI decoding is not coupled to actions, if the action specifies an argument type you need to use that. What confused you is probably that commonly the ABIs are created with action and type names being the same.

cc32d9 commented 1 year ago

yes, it's the PEBCAK