提交 102a0990 编写于 作者: K Kayan

add cleos command for name bidding

上级 00168f0b
......@@ -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": [],
......
......@@ -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<eosio::chain_apis::read_only::get_table_rows_result>();
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册