EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.27k stars 3.6k forks source link

Get account balance for eosio nothing #2962

Closed caokun2018 closed 5 years ago

caokun2018 commented 6 years ago

When I did the following, I encountered such a problem. The problems are step 10 and step 11 step 1 ./cleos wallet create Creating wallet: default Save password to use in the future to unlock this wallet. Without password imported keys will not be retrievable. "PW5HwThcr4ZqL4TjeQMA9Q6L78LuQH8LjvK3NyKjbkLuVPQRW7TFQ"

step 2 ./cleos set contract eosio ../../contracts/eosio.bios -p eosio Reading WAST... Assembling WASM... Publishing contract... executed transaction: 1b2b440ffdcf6e624aaab1d67336d67641c7923af157d8ed8f2ce6173dbead8d 3280 bytes 2200576 cycles eosio <= eosio::setcode {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001581060037f7e7f0060057f7e7e7e7e... eosio <= eosio::setabi {"account":"eosio","abi":{"types":[],"structs":[{"name":"set_account_limits","base":"","fields":[{"n...

step 3 ./cleos set contract eosio ../../contracts/eosio.system Reading WAST... Assembling WASM... Publishing contract... executed transaction: 1b2b440ffdcf6e624aaab1d67336d67641c7923af157d8ed8f2ce6173dbead8d 3280 bytes 2200576 cycles eosio <= eosio::setcode {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001581060037f7e7f0060057f7e7e7e7e... eosio <= eosio::setabi {"account":"eosio","abi":{"types":[],"structs":[{"name":"set_account_limits","base":"","fields":[{"n...

step 4 ./cleos push action eosio issue '{"to":"eosio","quantity":"1000000000.0000 EOS"}' --permission eosio@active executed transaction: 922779f9a5ebb90983101f4cb42dc087394009398abb4a172e0f0723a8fb04a9 248 bytes 120832 cycles eosio <= eosio::issue {"to":"eosio","quantity":"1000000000.0000 EOS"} eosio <= eosio::transfer {"from":"eosio","to":"eosio","quantity":"1000000000.0000 EOS","memo":""}

step 5 ./cleos get currency balance eos eosio 1000000000.0000 EOS

step 6 ./cleos wallet import 5JZ5Wwb8uQbi3A7DmMsD2zevcKCYw1pxmitij1x4xCjU8gv7ucj imported private key for: EOS6a5pr4DS4CksCQSHqTdKMPbAdCyrE4b7QExDwTuCxH1vbkYMqG

step 7 ./cleos wallet import 5JKkei9CFtawsvnHt728DUQaahcjHm5nqJsNgZzna9XZKq8eA5c imported private key for: EOS5NiFNF4bG7T49S6f7qVXMAt4RN2WM211s77UZrwD4cz2Xu6gw9

step 8 ./cleos create account eosio currency EOS6a5pr4DS4CksCQSHqTdKMPbAdCyrE4b7QExDwTuCxH1vbkYMqG EOS5NiFNF4bG7T49S6f7qVXMAt4RN2WM211s77UZrwD4cz2Xu6gw9 executed transaction: 899b071b1e68de82d946cb91dbccdba688ca3f288e4d28a6174d6bbbeb81d1f6 352 bytes 104448 cycles eosio <= eosio::newaccount {"creator":"eosio","name":"currency","owner":{"threshold":1,"keys":[{"key":"EOS6a5pr4DS4CksCQSHqTdKM...

step 9 ./cleos transfer eosio currency 100000000 executed transaction: 7f84845ce4b59069cc4160613f9ab6c0e834f1a78de05c9abce70014730f35c4 256 bytes 107520 cycles eosio <= eosio::transfer {"from":"eosio","to":"currency","quantity":"10000.0000 EOS","memo":""} currency <= eosio::transfer {"from":"eosio","to":"currency","quantity":"10000.0000 EOS","memo":""}

step 10 The problem is here ,as get balance for account eosio ,return two balances. ./cleos get currency balance eos eosio 999990000.0000 EOS 10000.0000 EOS

And as get balance for account for currency ,return nothing ./cleos get currency balance eos currency return nothing

step 11 When I send the following command, that is, the currency account is transferred to the eosio account to transfer 0, and the reading balance is normal. ./cleos transfer currency eosio 0

I think this is a bug, so I changed the code below, and the bug was solved. The third row is removed, plus the fourth row.

vector<asset> read_only::get_currency_balance( const read_only::get_currency_balance_params& p )const { vector<asset> results; - walk_table<contracts::key_value_index, contracts::by_scope_primary>(p.code, p.account, N(accounts), [&](const contracts::key_value_object& obj){

+ walk_table<contracts::key_value_index, contracts::by_scope_primary>(p.code, p.account, N(account), [&](const contracts::key_value_object& obj){

  share_type balance;
  fc::datastream<const char *> ds(obj.value.data(), obj.value.size());
 fc::raw::unpack(ds, balance);
  auto cursor = asset(balance, symbol(obj.primary_key));

 if( !p.symbol || cursor.symbol_name().compare(*p.symbol) == 0 ) {
     results.emplace_back(balance, symbol(obj.primary_key));`
  }

  // return false if we are looking for one and found it, true otherwise
  return !p.symbol || cursor.symbol_name().compare(*p.symbol) != 0;

});

return results; }

taokayan commented 6 years ago

Please use ./cleos get currency balance eosio currency

taokayan commented 5 years ago

We haven't received any update for this. If you still have the problem and wish to discuss further, please post it in https://eosio.stackexchange.com