wharfkit / contract

Access table data, create actions, and retrieve types for Antelope-based Smart Contracts
https://wharfkit.com
Other
1 stars 1 forks source link

DecodingError: Invalid number when fetching defibox pairs #50

Closed Wapaca closed 8 months ago

Wapaca commented 10 months ago

By using the gist example code, when fetching table "pairs" of contract "swap.box" on wax i get this error.

I get this error ``` node:internal/process/esm_loader:97 internalBinding('errors').triggerUncaughtException( ^

DecodingError: Invalid number at new Float (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1999:19) at new Float64 (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:2026:1) at Float64.fromABI (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1987:16) at decodeInner (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1269:28) at decodeBinary (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1264:16) at decodeInner (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1287:38) at decodeBinary (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1264:16) at Object.abiDecode [as decode] (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1216:20) at /home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/contract/lib/contract.js:163:65 at Array.map () { 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: 'pair', fields: [ [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object] ] } }, { field: 'price0_last', type: ResolvedType { isExtension: false, isOptional: false, isArray: false, id: 7, name: 'float64' } } ] }, underlyingError: Error: Invalid number at new Float (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1999:19) at new Float64 (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:2026:1) at Float64.fromABI (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1987:16) at decodeInner (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1269:28) at decodeBinary (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1264:16) at decodeInner (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1287:38) at decodeBinary (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1264:16) at Object.abiDecode [as decode] (/home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/antelope/lib/antelope.js:1216:20) at /home/waxdev/NFS/testwharfkit/node_modules/@wharfkit/contract/lib/contract.js:163:65 at Array.map () }

aaroncox commented 10 months ago

Thanks for this, it's an odd one! It appears that the API is actually returning bad data, and the serializer is failing to decode it.

curl https://wax.greymass.com/v1/chain/get_table_rows -d "{\"json\":true,\"limit\":1000,\"table\":\"pairs\",\"code\":\"swap.box\",\"scope\":\"swap.box\",\"key_type\":\"name\"}" | jq
    {
      "id": 972,
      "token0": {
        "contract": "niftywizards",
        "symbol": "4,DUST"
      },
      "token1": {
        "contract": "starcadiatok",
        "symbol": "5,STAR"
      },
      "reserve0": "0.0000 DUST",
      "reserve1": "0.00000 STAR",
      "liquidity_token": 0,
      "price0_last": "-nan",
      "price1_last": "-nan",
      "price0_cumulative_last": 0,
      "price1_cumulative_last": 0,
      "block_time_last": "2023-07-31T13:50:26"
    },

It can't process "price0_last": "-nan" as a number 🤔

Looking into this.

aaroncox commented 10 months ago

The above PR on wharfkit/antelope resolves this issue. During our next release we'll update that dependency and it should resolve the issue here too.