Skip to content

Commit

Permalink
Merge pull request EOSIO#3207 from EOSIO/cleos-system-list-bw
Browse files Browse the repository at this point in the history
Cleos system list bw
  • Loading branch information
moskvanaft authored May 18, 2018
2 parents 734804e + 7956234 commit 1cecc8b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,43 @@ struct undelegate_bandwidth_subcommand {
}
};

struct list_bw_subcommand {
eosio::name account;
bool print_json = false;

list_bw_subcommand(CLI::App* actionRoot) {
auto list_bw = actionRoot->add_subcommand("listbw", localized("List delegated bandwidth"));
list_bw->add_option("account", account, localized("The account delegated bandwidth"))->required();
list_bw->add_flag("--json,-j", print_json, localized("Output in JSON format") );

list_bw->set_callback([this] {
//get entire table in scope of user account
auto result = call(get_table_func, fc::mutable_variant_object("json", true)
("code", name(config::system_account_name).to_string())
("scope", account.to_string())
("table", "delband")
);
if (!print_json) {
auto res = result.as<eosio::chain_apis::read_only::get_table_rows_result>();
if ( !res.rows.empty() ) {
std::cout << std::setw(13) << std::left << "Receiver" << std::setw(21) << std::left << "Net bandwidth"
<< std::setw(21) << std::left << "CPU bandwidth" << std::endl;
for ( auto& r : res.rows ){
std::cout << std::setw(13) << std::left << r["to"].as_string()
<< std::setw(21) << std::left << r["net_weight"].as_string()
<< std::setw(21) << std::left << r["cpu_weight"].as_string()
<< std::endl;
}
} else {
std::cerr << "Delegated bandwidth not found" << std::endl;
}
} else {
std::cout << fc::json::to_pretty_string(result) << std::endl;
}
});
}
};

struct buyram_subcommand {
string from_str;
string receiver_str;
Expand Down Expand Up @@ -2426,6 +2463,7 @@ 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 biyram = buyram_subcommand(system);
auto sellram = sellram_subcommand(system);
Expand Down

0 comments on commit 1cecc8b

Please sign in to comment.