From 102a099074ff7116a67b60785595641cc9dd85f0 Mon Sep 17 00:00:00 2001 From: Kayan Date: Mon, 4 Jun 2018 15:33:14 +0800 Subject: [PATCH] add cleos command for name bidding --- contracts/eosio.system/eosio.system.abi | 15 +++++++ programs/cleos/main.cpp | 55 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index de5389ac4..ab1059d7b 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -398,6 +398,15 @@ {"name":"base", "type":"connector"}, {"name":"quote", "type":"connector"} ] + }, { + "name": "namebid_info", + "base": "", + "fields": [ + {"name":"newname", "type":"account_name"}, + {"name":"high_bidder", "type":"account_name"}, + {"name":"high_bid", "type":"int64"}, + {"name":"last_bid_time", "type":"uint64"} + ] } ], "actions": [{ @@ -559,6 +568,12 @@ "index_type": "i64", "key_names" : ["owner"], "key_types" : ["uint64"] + },{ + "name": "namebids", + "type": "namebid_info", + "index_type": "i64", + "key_names" : ["newname"], + "key_types" : ["account_name"] } ], "ricardian_clauses": [], diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 30417064a..b460f7ecc 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -1133,6 +1133,59 @@ struct undelegate_bandwidth_subcommand { } }; +struct bidname_subcommand { + string bidder_str; + string newname_str; + string bid_amount; + bidname_subcommand(CLI::App *actionRoot) { + auto bidname = actionRoot->add_subcommand("bidname", localized("Name bidding")); + bidname->add_option("bidder", bidder_str, localized("The bidding account"))->required(); + bidname->add_option("newname", newname_str, localized("The bidding name"))->required(); + bidname->add_option("bid", bid_amount, localized("The amount of EOS to bid"))->required(); + add_standard_transaction_options(bidname); + bidname->set_callback([this] { + fc::variant act_payload = fc::mutable_variant_object() + ("bidder", bidder_str) + ("newname", newname_str) + ("bid", to_asset(bid_amount)); + send_actions({create_action({permission_level{bidder_str, config::active_name}}, config::system_account_name, N(bidname), act_payload)}); + }); + } +}; + +struct bidname_info_subcommand { + bool print_json = false; + string newname_str; + 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->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)); + if ( print_json ) { + std::cout << fc::json::to_pretty_string(rawResult) << std::endl; + return; + } + auto result = rawResult.as(); + if ( result.rows.empty() ) { + 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; + } + }); + } +}; + struct list_bw_subcommand { eosio::name account; bool print_json = false; @@ -2555,6 +2608,8 @@ int main( int argc, char** argv ) { auto delegateBandWidth = delegate_bandwidth_subcommand(system); auto undelegateBandWidth = undelegate_bandwidth_subcommand(system); auto listBandWidth = list_bw_subcommand(system); + auto bidname = bidname_subcommand(system); + auto bidnameinfo = bidname_info_subcommand(system); auto biyram = buyram_subcommand(system); auto sellram = sellram_subcommand(system); -- GitLab