From 3beeb5869547d08d9c5676c5ac16fd248b1c6306 Mon Sep 17 00:00:00 2001 From: Kayan Date: Mon, 21 May 2018 16:37:09 -0400 Subject: [PATCH 1/3] fix #3219 (asset's precision zero) --- libraries/chain/asset.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/chain/asset.cpp b/libraries/chain/asset.cpp index 142e04cffa3..03c968c63a1 100644 --- a/libraries/chain/asset.cpp +++ b/libraries/chain/asset.cpp @@ -23,11 +23,13 @@ int64_t asset::precision()const { string asset::to_string()const { string sign = amount < 0 ? "-" : ""; int64_t abs_amount = std::abs(amount); - string result = fc::to_string( static_cast(abs_amount) / precision()); + auto preci = precision(); + EOS_ASSERT(preci > 0, asset_type_exception, "Asset's precision should be positive"); + string result = fc::to_string( static_cast(abs_amount) / preci); if( decimals() ) { - auto fract = static_cast(abs_amount) % precision(); - result += "." + fc::to_string(precision() + fract).erase(0,1); + auto fract = static_cast(abs_amount) % preci; + result += "." + fc::to_string(preci + fract).erase(0,1); } return sign + result + " " + symbol_name(); } From 776d5aedf96482c4c5884a483acc41d9603f41ef Mon Sep 17 00:00:00 2001 From: Kayan Date: Tue, 22 May 2018 11:49:45 -0400 Subject: [PATCH 2/3] revert asset.cpp --- libraries/chain/asset.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/chain/asset.cpp b/libraries/chain/asset.cpp index 03c968c63a1..142e04cffa3 100644 --- a/libraries/chain/asset.cpp +++ b/libraries/chain/asset.cpp @@ -23,13 +23,11 @@ int64_t asset::precision()const { string asset::to_string()const { string sign = amount < 0 ? "-" : ""; int64_t abs_amount = std::abs(amount); - auto preci = precision(); - EOS_ASSERT(preci > 0, asset_type_exception, "Asset's precision should be positive"); - string result = fc::to_string( static_cast(abs_amount) / preci); + string result = fc::to_string( static_cast(abs_amount) / precision()); if( decimals() ) { - auto fract = static_cast(abs_amount) % preci; - result += "." + fc::to_string(preci + fract).erase(0,1); + auto fract = static_cast(abs_amount) % precision(); + result += "." + fc::to_string(precision() + fract).erase(0,1); } return sign + result + " " + symbol_name(); } From 102a099074ff7116a67b60785595641cc9dd85f0 Mon Sep 17 00:00:00 2001 From: Kayan Date: Mon, 4 Jun 2018 15:33:14 +0800 Subject: [PATCH 3/3] 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 de5389ac409..ab1059d7bbb 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 30417064ac0..b460f7eccec 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);