EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

parsing error: Invalid extended asset string #209

Closed robertkowalski closed 6 years ago

robertkowalski commented 6 years ago

Hi James,

I have a custom contract where I can send custom tokens to.

Here is an example from the command line. The testuser1234 has quite some CANDY and offers it to sell:

$ cleos push action organiccandy add '["testuser1234" 1 "-1.337 CANDY" 12 0]' -p testuser1234

executed transaction: 086250dc677361b615ea962b4149669e9517adb3cf4bdc706308449c201f6344  136 bytes  1114 us
#  organiccandy <= organiccandy::add          {"account":"testuser1234","clId":1,"qty_and_pair":"-1.337 CANDY","priceDbl":"12.00000000000000000...

With the eosjs I run into a problem with negative values like -1.337:

const payload = { account: 'testuser1234',
  clId: 1,
  qty_and_type: '-1.337 CANDY',
  py: 0,
  priceDbl: '1337' 
}

eos.contract('organiccandy').then((contract) => {
  return contract.add(payload, { authorization: 'testuser1234@active' })
})
.then((res) => {
  console.log('yay!')
  console.log(res)
})
.catch((err) => { console.error(err) })
{ AssertionError [ERR_ASSERTION]: Invalid extended asset string: -1.337 CANDY !== CANDY place.qty_and_type action.data transaction.actions
    at parseAsset (/Users/robert/candystore/node_modules/eosjs/lib/format.js:367:10)
    at Object.fromObject (/Users/robert/candystore/node_modules/eosjs/lib/structs.js:402:26)
    at Object.fromObject (/Users/robert/candystore/node_modules/fcbuffer/lib/struct.js:151:34)
    at actionDataFromObject (/Users/robert/candystore/node_modules/eosjs/lib/structs.js:674:29)
    at Object.fromObject (/Users/robert/candystore/node_modules/fcbuffer/lib/struct.js:148:15)
    at Object.fromObject (/Users/robert/candystore/node_modules/fcbuffer/lib/types.js:384:28)
    at Object.fromObject (/Users/robert/candystore/node_modules/fcbuffer/lib/struct.js:151:34)
    at _callee2$ (/Users/robert/candystore/node_modules/eosjs/lib/write-api.js:652:38)
    at tryCatch (/Users/robert/candystore/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Users/robert/candystore/node_modules/regenerator-runtime/runtime.js:296:22)
  generatedMessage: false,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: '-1.337 CANDY',
  expected: 'CANDY',
  operator: '==' }
jcalfee commented 6 years ago

I renamed some types: UDecimalPad -> DecimalPad (for example)

jcalfee commented 6 years ago

Released under v15.0.1

ricktobacco commented 5 years ago

I dont believe this issue is closed, I am getting a very similar error with extended symbols. Any advice besides don't use them? :)

jcalfee commented 5 years ago

This is a legacy issue.. If your on the latest version a new issue will be better, the entire code base changed.