Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Cleos bidname #3792

Merged
merged 20 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions contracts/eosio.system/eosio.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -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": [{
Expand Down Expand Up @@ -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": [],
Expand Down
55 changes: 55 additions & 0 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down