Skip to content

Commit

Permalink
fixed 'cleos system bidname info' cmd exec return could not parse uin…
Browse files Browse the repository at this point in the history
…t64_t (#30)

* recovery system account bos to eosio

* catch exception plugin initialize sync list before initialize database

* fixed bidnameinfo could not parse uint64_t
  • Loading branch information
vlbos authored and Thaipanda committed Jan 10, 2019
1 parent 9899638 commit 2f26403
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,33 +1285,38 @@ struct bidname_subcommand {

struct bidname_info_subcommand {
bool print_json = false;
string newname_str;
name newname;
bidname_info_subcommand(CLI::App* actionRoot) {
auto list_producers = actionRoot->add_subcommand("bidnameinfo", localized("Get bidname info"));
list_producers->add_flag("--json,-j", print_json, localized("Output in JSON format"));
list_producers->add_option("newname", newname_str, localized("The bidding name"))->required();
list_producers->add_option("newname", newname, localized("The bidding name"))->required();
list_producers->set_callback([this] {
auto rawResult = call(get_table_func, fc::mutable_variant_object("json", true)
("code", "eosio")("scope", "eosio")("table", "namebids")
("lower_bound", eosio::chain::string_to_name(newname_str.c_str()))("limit", 1));
("lower_bound", newname.value)("limit", 1));
if ( print_json ) {
std::cout << fc::json::to_pretty_string(rawResult) << std::endl;
return;
}
auto result = rawResult.as<eosio::chain_apis::read_only::get_table_rows_result>();
if ( result.rows.empty() ) {
// Condition in if statement below can simply be res.rows.empty() when cleos no longer needs to support nodeos versions older than 1.5.0
if( result.rows.empty() || result.rows[0].get_object()["newname"].as_string() != newname.to_string() ) {
std::cout << "No bidname record found" << std::endl;
return;
}
for ( auto& row : result.rows ) {
fc::time_point time(fc::microseconds(row["last_bid_time"].as_uint64()));
int64_t bid = row["high_bid"].as_int64();
std::cout << std::left << std::setw(18) << "bidname:" << std::right << std::setw(24) << row["newname"].as_string() << "\n"
<< std::left << std::setw(18) << "highest bidder:" << std::right << std::setw(24) << row["high_bidder"].as_string() << "\n"
<< std::left << std::setw(18) << "highest bid:" << std::right << std::setw(24) << (bid > 0 ? bid : -bid) << "\n"
<< std::left << std::setw(18) << "last bid time:" << std::right << std::setw(24) << ((std::string)time).c_str() << std::endl;
if (bid < 0) std::cout << "This auction has already closed" << std::endl;
const auto& row = result.rows[0];
string time = row["last_bid_time"].as_string();
try {
time = (string)fc::time_point(fc::microseconds(to_uint64(time)));
} catch (fc::parse_error_exception&) {
}
int64_t bid = row["high_bid"].as_int64();
std::cout << std::left << std::setw(18) << "bidname:" << std::right << std::setw(24) << row["newname"].as_string() << "\n"
<< std::left << std::setw(18) << "highest bidder:" << std::right << std::setw(24) << row["high_bidder"].as_string() << "\n"
<< std::left << std::setw(18) << "highest bid:" << std::right << std::setw(24) << (bid > 0 ? bid : -bid) << "\n"
<< std::left << std::setw(18) << "last bid time:" << std::right << std::setw(24) << time << std::endl;
if (bid < 0) std::cout << "This auction has already closed" << std::endl;

});
}
};
Expand Down

0 comments on commit 2f26403

Please sign in to comment.