Skip to content

Commit 45e609f

Browse files
authored
Merge pull request #5704 from EOSIO/get-account-bug-fixes
Improvements to get account (chain_plugin and cleos) related to core_symbol
2 parents 2e94abd + c750569 commit 45e609f

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

plugins/chain_plugin/chain_plugin.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,16 +1644,18 @@ read_only::get_account_results read_only::get_account( const get_account_params&
16441644

16451645
const auto token_code = N(eosio.token);
16461646

1647+
auto core_symbol = extract_core_symbol();
1648+
16471649
const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( token_code, params.account_name, N(accounts) ));
16481650
if( t_id != nullptr ) {
16491651
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
1650-
auto it = idx.find(boost::make_tuple( t_id->id, symbol().to_symbol_code() ));
1652+
auto it = idx.find(boost::make_tuple( t_id->id, core_symbol.to_symbol_code() ));
16511653
if( it != idx.end() && it->value.size() >= sizeof(asset) ) {
16521654
asset bal;
16531655
fc::datastream<const char *> ds(it->value.data(), it->value.size());
16541656
fc::raw::unpack(ds, bal);
16551657

1656-
if( bal.get_symbol().valid() && bal.get_symbol() == symbol() ) {
1658+
if( bal.get_symbol().valid() && bal.get_symbol() == core_symbol ) {
16571659
result.core_liquid_balance = bal;
16581660
}
16591661
}
@@ -1766,6 +1768,46 @@ read_only::get_transaction_id_result read_only::get_transaction_id( const read_o
17661768
return params.id();
17671769
}
17681770

1771+
namespace detail {
1772+
struct ram_market_exchange_state_t {
1773+
asset ignore1;
1774+
asset ignore2;
1775+
double ignore3;
1776+
asset core_symbol;
1777+
double ignore4;
1778+
};
1779+
}
1780+
1781+
chain::symbol read_only::extract_core_symbol()const {
1782+
symbol core_symbol; // Default to CORE_SYMBOL if the appropriate data structure cannot be found in the system contract table data
1783+
1784+
// The following code makes assumptions about the contract deployed on eosio account (i.e. the system contract) and how it stores its data.
1785+
const auto& d = db.db();
1786+
const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( N(eosio), N(eosio), N(rammarket) ));
1787+
if( t_id != nullptr ) {
1788+
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
1789+
auto it = idx.find(boost::make_tuple( t_id->id, eosio::chain::string_to_symbol_c(4,"RAMCORE") ));
1790+
if( it != idx.end() ) {
1791+
detail::ram_market_exchange_state_t ram_market_exchange_state;
1792+
1793+
fc::datastream<const char *> ds( it->value.data(), it->value.size() );
1794+
1795+
try {
1796+
fc::raw::unpack(ds, ram_market_exchange_state);
1797+
} catch( ... ) {
1798+
return core_symbol;
1799+
}
1800+
1801+
if( ram_market_exchange_state.core_symbol.get_symbol().valid() ) {
1802+
core_symbol = ram_market_exchange_state.core_symbol.get_symbol();
1803+
}
1804+
}
1805+
}
1806+
1807+
return core_symbol;
1808+
}
17691809

17701810
} // namespace chain_apis
17711811
} // namespace eosio
1812+
1813+
FC_REFLECT( eosio::chain_apis::detail::ram_market_exchange_state_t, (ignore1)(ignore2)(ignore3)(core_symbol)(ignore4) )

plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ class read_only {
512512
return result;
513513
}
514514

515+
chain::symbol extract_core_symbol()const;
516+
515517
friend struct resolver_factory<read_only>;
516518
};
517519

programs/cleos/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,13 @@ void get_account( const string& accountName, bool json_format ) {
14791479
asset staked;
14801480
asset unstaking;
14811481

1482+
if( res.core_liquid_balance.valid() ) {
1483+
unstaking = asset( 0, res.core_liquid_balance->get_symbol() ); // Correct core symbol for unstaking asset.
1484+
staked = asset( 0, res.core_liquid_balance->get_symbol() ); // Correct core symbol for staked asset.
1485+
}
1486+
1487+
std::cout << "created: " << string(res.created) << std::endl;
1488+
14821489
if(res.privileged) std::cout << "privileged: true" << std::endl;
14831490

14841491
constexpr size_t indent_size = 5;

0 commit comments

Comments
 (0)