diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index f76d317860f695c221d07cf6e370908fdbd7e63c..32080cfb74b7a84c822cb589565effe2d340b94c 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -132,10 +132,13 @@ "base": "", "fields": [ {"name":"owner", "type":"account_name"}, - {"name":"total_votes", "type":"uint128"}, - {"name":"packed_key", "type":"public_key"}, - {"name":"per_block_payments", "type":"uint64"}, - {"name":"last_claim_time", "type":"time"} + {"name":"total_votes", "type":"float64"}, + {"name":"producer_key", "type":"public_key"}, + {"name":"url", "type":"string"}, + {"name":"last_rewards_claim", "type":"uint32"}, + {"name":"location", "type":"uint16"}, + {"name":"time_became_active", "type":"uint32"}, + {"name":"time_produced_block_time", "type":"uint32"} ] },{ "name": "regproducer", @@ -247,7 +250,7 @@ } ], "tables": [{ - "name": "producerinfo", + "name": "producers", "type": "producer_info", "index_type": "i64", "key_names" : ["owner"], diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index 3b8eb743138dfc4f9ff74dbd74fd66d2abf1eb07..6984b4af72687a94ef1990d0a9a840f0f785e7f7 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -50,6 +50,7 @@ namespace eosiosystem { account_name owner; double total_votes = 0; eosio::public_key producer_key; /// a packed public key object + std::string url; uint32_t produced_blocks; time last_rewards_claim = 0; uint16_t location = 0; @@ -61,7 +62,7 @@ namespace eosiosystem { bool active() const { return producer_key != public_key(); } // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(producer_key) + EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(producer_key)(url) (produced_blocks)(last_rewards_claim) (time_became_active)(last_produced_block_time) ) }; diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index d5435fd0d98832ad38b3f4c49c555b5915b124f9..1cea2f492e64e6213ec24bc55672ce45852fa08b 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -45,6 +45,7 @@ namespace eosiosystem { if( producer_key != prod->producer_key ) { _producers.modify( prod, producer, [&]( producer_info& info ){ info.producer_key = producer_key; + info.url = url; }); } } else { @@ -52,6 +53,7 @@ namespace eosiosystem { info.owner = producer; info.total_votes = 0; info.producer_key = producer_key; + info.url = url; }); } } diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 82b2d283444f089ffa95bb59517c8edc22405755..f8f2e68ff4f5fe10afa313c0d6edc6dbbd32f559 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -823,6 +823,57 @@ struct vote_producers_subcommand { } }; +struct list_producers_subcommand { + bool print_json; + bool sort_names; + bool sort_votes; + + list_producers_subcommand(CLI::App* actionRoot) { + auto list_producers = actionRoot->add_subcommand("listproducers", localized("List producers")); + list_producers->add_flag("--json,-j", print_json, localized("Output in JSON format") ); + list_producers->add_flag("--sort-account-names,-n", sort_votes, localized("Sort by account names (default order is by votes)") ); + list_producers->set_callback([this] { + auto result = call(get_table_func, fc::mutable_variant_object("json", true) + ("code", name(config::system_account_name).to_string()) + ("scope", name(config::system_account_name).to_string()) + ("table", "producers") + ); + + if ( !print_json ) { + auto res = result.as(); + std::vector> v; + for ( auto& row : res.rows ) { + auto& r = row.get_object(); + v.push_back({ r["owner"].as_string(), r["total_votes"].as_string(), r["producer_key"].as_string(), r["url"].as_string() }); + + } + if ( !v.empty() ) { + if ( sort_names ) { + std::sort( v.begin(), v.end(), [](auto a, auto b) { return std::get<0>(a) < std::get<0>(b); } ); + } else { + std::sort( v.begin(), v.end(), [](auto a, auto b) { + return std::get<1>(a) < std::get<1>(b) || (std::get<1>(a) == std::get<1>(b) && std::get<0>(a) < std::get<0>(b)); } + ); + } + + std::cout << std::left << std::setw(14) << "Producer" << std::setw(55) << "Producer key" + << std::setw(50) << "Url" << "Total votes" << std::endl; + for ( auto& x : v ) { + std::cout << std::left << std::setw(14) << std::get<0>(x) << std::setw(55) << std::get<2>(x) + << std::setw(50) << std::get<3>(x) << std::get<1>(x) << std::endl; + } + } else { + std::cout << "No producers found" << std::endl; + } + } else { + std::cout << fc::json::to_pretty_string(result) + << std::endl; + } + } + ); + } +}; + struct delegate_bandwidth_subcommand { string from_str; string receiver_str; @@ -2117,6 +2168,8 @@ int main( int argc, char** argv ) { auto voteProxy = vote_producer_proxy_subcommand(voteProducer); auto voteProducers = vote_producers_subcommand(voteProducer); + auto listProducers = list_producers_subcommand(system); + auto delegateBandWidth = delegate_bandwidth_subcommand(system); auto undelegateBandWidth = undelegate_bandwidth_subcommand(system);