提交 afc1d048 编写于 作者: A Anton Perkov

cleos listproducers #2807

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