Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion contracts/eosio.system/eosio.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
{"name":"owner", "type":"account_name"},
{"name":"total_votes", "type":"float64"},
{"name":"producer_key", "type":"public_key"},
{"name":"url", "type":"string"},
{"name":"produced_blocks", "type":"uint32"},
{"name":"last_claim_time", "type":"time"},
{"name":"location", "type":"uint16"},
Expand Down Expand Up @@ -255,7 +256,7 @@
}
],
"tables": [{
"name": "producerinfo",
"name": "producers",
"type": "producer_info",
"index_type": "i64",
"key_names" : ["owner"],
Expand Down
3 changes: 2 additions & 1 deletion contracts/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_claim_time = 0;
uint16_t location = 0;
Expand All @@ -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_claim_time)(location)
(time_became_active)(last_produced_block_time) )
};
Expand Down
2 changes: 2 additions & 0 deletions contracts/eosio.system/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ namespace eosiosystem {
if( producer_key != prod->producer_key ) {
_producers.modify( prod, producer, [&]( producer_info& info ){
info.producer_key = producer_key;
info.url = url;
});
}
} else {
_producers.emplace( producer, [&]( producer_info& info ){
info.owner = producer;
info.total_votes = 0;
info.producer_key = producer_key;
info.url = url;
});
}
}
Expand Down
55 changes: 55 additions & 0 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,59 @@ struct vote_producers_subcommand {
}
};

struct list_producers_subcommand {
bool print_json = false;
bool sort_names = false;

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_names, 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.emplace_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 {
if ( sort_names ) {
FC_THROW("Sorting producers is not supported for JSON format");
}
std::cout << fc::json::to_pretty_string(result)
<< std::endl;
}
}
);
}
};

struct delegate_bandwidth_subcommand {
string from_str;
string receiver_str;
Expand Down Expand Up @@ -2153,6 +2206,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);

Expand Down