Eos: cleos get table always return no data

Created on 22 Mar 2018  ·  11Comments  ·  Source: EOSIO/eos

Using the latest version of master branch, I'm trying the currency smart contract.
I'm able to:

  • Create new currency
  • Issue currency
  • Transfer currency
  • Cannot transfer more currency than what I have
    So the currency contract seems to work as intended

But I'm not able to view table data. cleos get table currency currency account always return an empty array.

I attached the log to show how to reproduce the issue.
log.txt

needs testing - pass

Most helpful comment

The issue is that the new currency contract ABI specifies that the accounts table name is "account" when the contract code uses the name "accounts".

Even though that one small change should resolve the issue, it can still be difficult to use the get table commands in cleos to get the data because, for example, getting the appropriate "stat" table requires you to provide the correct scope, which in the case of the currency contract would be the uint64_t value representing the symbol name (without the least significant byte containing the precision) but passed into cleos as if it was an account name. For example the "CUR" symbol name would end up being represented by a name like "........edeo3".

To make it easier to use cleos get table in situations where more sophisticated scope names are needed (for example, a symbol name or an arbitrary uint64_t integer), I have added support (see PR #1874) in chain_plugin to interpret the scope string passed in (typically by cleos) to the get_table_rows endpoint as either a name, uint64_t, symbol (e.g. "4,CUR"), or a new built_in_type I added to the ABI serializer called symbol_name (e.g. "CUR") in that specific order of conversion attempts.

So, for example, after running tests/nodeos_run_test.py --dont-kill, it is possible (as of commit 238a141) to run cleos commands such as:

$ programs/cleos/cleos --port 8788 --wallet-port 8899 get table currency CUR stat
{
  "rows": [{
      "currency": "CUR",
      "supply": 1000000000
    }
  ],
  "more": false
}
$ programs/cleos/cleos --port 8788 --wallet-port 8899 get table currency inita accounts
{
  "rows": [{
      "currency": "4,CUR",
      "balance": 50
    }
  ],
  "more": false
}

(Notice that I also switched the order of the contract and scope arguments to better reflect the actual table structure we use.)

All 11 comments

I just noticed that all the tests that use the get table ( https://github.com/EOSIO/eos/blob/master/tests/nodeos_run_test.py#L453 ) are commented out.
Any plan to fix the get table? I wasn't able to find an issue for it.

+1

Now I can only query by API muti-index. Example:
void on( const balance& b, const account_name contract) { auto sym = b.symbol.symbol.name(); stats statstable(contract, sym); const auto& st = statstable.get( sym ); print(st.max_supply.amount); }

The issue is that the new currency contract ABI specifies that the accounts table name is "account" when the contract code uses the name "accounts".

Even though that one small change should resolve the issue, it can still be difficult to use the get table commands in cleos to get the data because, for example, getting the appropriate "stat" table requires you to provide the correct scope, which in the case of the currency contract would be the uint64_t value representing the symbol name (without the least significant byte containing the precision) but passed into cleos as if it was an account name. For example the "CUR" symbol name would end up being represented by a name like "........edeo3".

To make it easier to use cleos get table in situations where more sophisticated scope names are needed (for example, a symbol name or an arbitrary uint64_t integer), I have added support (see PR #1874) in chain_plugin to interpret the scope string passed in (typically by cleos) to the get_table_rows endpoint as either a name, uint64_t, symbol (e.g. "4,CUR"), or a new built_in_type I added to the ABI serializer called symbol_name (e.g. "CUR") in that specific order of conversion attempts.

So, for example, after running tests/nodeos_run_test.py --dont-kill, it is possible (as of commit 238a141) to run cleos commands such as:

$ programs/cleos/cleos --port 8788 --wallet-port 8899 get table currency CUR stat
{
  "rows": [{
      "currency": "CUR",
      "supply": 1000000000
    }
  ],
  "more": false
}
$ programs/cleos/cleos --port 8788 --wallet-port 8899 get table currency inita accounts
{
  "rows": [{
      "currency": "4,CUR",
      "balance": 50
    }
  ],
  "more": false
}

(Notice that I also switched the order of the contract and scope arguments to better reflect the actual table structure we use.)

@arhag I think if you do not change the struct account then the result from cmd programs/cleos/cleos --port 8788 --wallet-port 8899 get table currency inita accounts, the field balance must have dot precision. Ex: 50.0, 50.00 or 50.000...
Not "balance": 50

@navcsdev If the table row was stored as an asset then the results could be pretty printed with the decimal in the right place. But currently (perhaps it may change) both the accounts and stat table separately store a symbol (or symbol_name which doesn't include the precision info) field and another int64_t field containing the amount of the asset in its smallest indivisible unit. So the converter to JSON does not have enough information to know these two fields are necessarily connected in order to pretty print it.

EDIT: Never mind the above. The currency contract already was using asset. It was the ABI that was incorrect but appeared to be correct in testing because of another bug (get_table_rows_ex calling copy_row which prepended the primary key to the retrieved data). That bug has been fixed now in PR #1874, and now cleos returns what one would expect with pretty printing of the asset balances.

Closing as this is fixed by PR #1874

@heifner I saw exception when I query cleos get table currency currency stat

t_exception: Assert Exception comma_pos != string::npos: missing comma in symbol {} thread-0 symbol.hpp:68 from_string 2830894ms thread-0 symbol.hpp:73 from_string ] from: CUR

I think we will fix it, right ? 🙇

@navcsdev

./cleos get table ${YOUR CONTRACT NAME ( ACCOUNT NAME PROVIDED WHEN CREATE CONTRACT )} ${WHICH COLUM NAME YOU WANT TO GET} ${TABLENAME}

you have transfer CUR, so in stat table, JUST do:

./cleos get table xxxContractAccountName CUR stat

same as:

```bash
$ ./cleos get table dood CUR stat
{
  "rows": [{
      "supply": "1001.0000 CUR",
      "max_supply": "9000000000.0000 CUR",
      "issuer": "dood",
      "can_freeze": 1,
      "can_recall": 1,
      "can_whitelist": 1,
      "is_frozen": 0,
      "enforce_whitelist": 0
    }
  ],
  "more": false
}

if you want to query account info:

$ ./cleos get table dood eosio accounts
{
  "rows": [{
      "balance": "1000.0000 CUR",
      "frozen": 0,
      "whitelist": 1
    }
  ],
  "more": false
}
$ ./cleos get table dood dood accounts
{
  "rows": [{
      "balance": "1.0000 CUR",
      "frozen": 0,
      "whitelist": 1
    }
  ],
  "more": false
}

@WildDylan Yes, I query success but on screen console it appear Exception

And I think

./cleos get table ${YOUR CONTRACT NAME ( ACCOUNT NAME PROVIDED WHEN CREATE CONTRACT )} ${WHICH COLUM NAME YOU WANT TO GET} ${TABLENAME}

WHICH COLUM NAME YOU WANT TO GET it must be primary key of table :D

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ResponsiveWebApps picture ResponsiveWebApps  ·  3Comments

christola picture christola  ·  3Comments

Npizza picture Npizza  ·  3Comments

hadramidah picture hadramidah  ·  3Comments

bezalel picture bezalel  ·  3Comments