EOSIO / eosjs

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

asset error for DAWN4 #34

Closed zshchou closed 6 years ago

zshchou commented 6 years ago

for DAWN3:

i define my token: S(8, ZSH)

if i transfer my token, it will error, because "structs.js" set precision for 4 /* @example '0.0001 CUR' / var symbolCache = function symbolCache(symbol) { return { precision: 4 }; };

still structs.js: var prefix = '\x04'; // 4 decimals in EOS

chris-allnutt commented 6 years ago

@jcalfee any ideas here?

jcalfee commented 6 years ago

I believe the precision is not available in the API yet. I had to hard-code it to 4.. I'll ask about this..

jcalfee commented 6 years ago

Kevin in the c++ team is aware of the ticket above to add the asset precision to the API.

jcalfee commented 6 years ago

Having some issues using the docker release which may have been fixed in master. On vacation next week. I'll continue this using the next dawn3 release when I get back.

https://github.com/EOSIO/eos/issues/1857#issuecomment-379066952

zshchou commented 6 years ago

eos3.22 and eos3.28 is middle state, now wait rc2.

jcalfee commented 6 years ago

Precision can be derived from the supply in this API call using eosio in master (eosio/eos:20180420 for example). This does not work in eosio/eos:dawn3x ..

> eos.getCurrencyStats('currency', 'CUR', (error, result) => console.log(error, result))
undefined
> null { CUR: 
   { supply: '2000000000.0000 CUR',
     max_supply: '1000000000.0000 CUR',
     issuer: 'currency' } }
zshchou commented 6 years ago

now eosjs and eos3 is ok, can create new account, can transfre asset, but if init currency precision is 8, then transfer asset will is 4 . for instance:

cleos push action inkcoin issue '{"to":"inkcoin","quantity":"1000000000.00000000 AYA","memo":"issue"}' -p inkcoin@active
cleos push action inkcoin transfer '{"from":"inkcoin","to":"inita","quantity":"1000.00000000 AYA","memo":"to inita"}' -p inkcoin@active
cleos push action inkcoin transfer '{"from":"inita","to":"initb","quantity":"1.00000000 AYA","memo":"to initb"}' -p inita@active

the command is ok, the result:

➜  ~ cleos get table inkcoin inita accounts
{
  "rows": [{
      "balance": "999.00000000 AYA",
      "frozen": 0,
      "whitelist": 1
    }
  ],
  "more": false
}

if I use eosjs transfer 1 AYA from inita to other:

let data = {form: inita, to: initb, amount: 1};
let quantity = format.UDecimalPad(data.amount, 8) + " AYA";
let res = await eos.transaction(inkcoin, coin => {
      coin.transfer(data.from, data.to, quantity, "eosapi");
    });

the inita asset is error.

{
  "status": 200,
  "balance": "998.99990000",
  "coinname": "AYA"
}

the expected inita asset is:

{
  "status": 200,
  "balance": "998.00000000",
  "coinname": "AYA"
}

@jcalfee

jcalfee commented 6 years ago

This is working in the unit test under the custom token call PHI.