CityOfZion / neon-js

Javascript libraries that allow the applications to interact with NEO blockchain
https://docs.coz.io/neo3/neon-js/index.html
MIT License
183 stars 166 forks source link

TokenInfo interface can't handle integer totalSupply values #921

Open hal0x2328 opened 10 months ago

hal0x2328 commented 10 months ago

The legacy neon-js code can't deal with smart contracts that return an Integer response to a totalSupply invocation. The existing interface code looks like:

const parseTokenInfo = rpc.buildParser(
  rpc.StringParser,
  rpc.StringParser,
  rpc.IntegerParser,
  rpc.Fixed8Parser
);

Most contracts return a Fixed8 ByteArray for the totalSupply (the last field in the structure above) but at least one Flamingo pair (probably all of them) returns an Integer. Example for FLP-nNEO-fUSDT:

{
  "jsonrpc": "2.0",
  "id": 1234,
  "result": {
    "script": "00046e616d65678cada6a808e694ac897ceb271f4bc527a9a33374000673796d626f6c678cada6a808e694ac897ceb271f4bc527a9a333740008646563696d616c73678cada6a808e694ac897ceb271f4bc527a9a33374000b746f74616c537570706c79678cada6a808e694ac897ceb271f4bc527a9a33374",
    "state": "HALT",
    "gas_consumed": "0.651",
    "stack": [
      {
        "type": "ByteArray",
        "value": "45786368616e67652050616972"
      },
      {
        "type": "ByteArray",
        "value": "464c502d6e4e454f2d6655534454"
      },
      {
        "type": "Integer",
        "value": "8"
      },
      {
        "type": "Integer",
        "value": "33119936322"
      }
    ]
  }
}