Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
unapprove_producer_subcommand Struct Reference

Public Member Functions

 unapprove_producer_subcommand (CLI::App *actionRoot)
 

Public Attributes

string voter
 
string producer_name
 

Detailed Description

Definition at line 1331 of file main.cpp.

Constructor & Destructor Documentation

◆ unapprove_producer_subcommand()

unapprove_producer_subcommand::unapprove_producer_subcommand ( CLI::App * actionRoot)
inline

Definition at line 1335 of file main.cpp.

1335 {
1336 auto approve_producer = actionRoot->add_subcommand("unapprove", localized("Remove one producer from list of voted producers"));
1337 approve_producer->add_option("voter", voter, localized("The voting account"))->required();
1338 approve_producer->add_option("producer", producer_name, localized("The account to remove from voted producers"))->required();
1339 add_standard_transaction_options(approve_producer, "voter@active");
1340
1341 approve_producer->callback([this] {
1342 auto result = call(get_table_func, fc::mutable_variant_object("json", true)
1343 ("code", name(config::system_account_name).to_string())
1344 ("scope", name(config::system_account_name).to_string())
1345 ("table", "voters")
1346 ("table_key", "owner")
1347 ("lower_bound", name(voter).to_uint64_t())
1348 ("upper_bound", name(voter).to_uint64_t() + 1)
1349 // Less than ideal upper_bound usage preserved so clio can still work with old buggy nodeop versions
1350 // Change to voter.value when clio no longer needs to support nodeop versions older than 1.5.0
1351 ("limit", 1)
1352 );
1354 // Condition in if statement below can simply be res.rows.empty() when clio no longer needs to support nodeop versions older than 1.5.0
1355 // Although since this subcommand will actually change the voter's vote, it is probably better to just keep this check to protect
1356 // against future potential chain_plugin bugs.
1357 if( res.rows.empty() || res.rows[0].get_object()["owner"].as_string() != name(voter).to_string() ) {
1358 std::cerr << "Voter info not found for account " << voter << std::endl;
1359 return;
1360 }
1361 SYS_ASSERT( 1 == res.rows.size(), multiple_voter_info, "More than one voter_info for account" );
1362 auto prod_vars = res.rows[0]["producers"].get_array();
1363 vector<sysio::name> prods;
1364 for ( auto& x : prod_vars ) {
1365 prods.push_back( name(x.as_string()) );
1366 }
1367 auto it = std::remove( prods.begin(), prods.end(), name(producer_name) );
1368 if (it == prods.end() ) {
1369 std::cerr << "Cannot remove: producer \"" << producer_name << "\" is not on the list." << std::endl;
1370 return;
1371 }
1372 prods.erase( it, prods.end() ); //should always delete only one element
1374 ("voter", voter)
1375 ("proxy", "")
1376 ("producers", prods);
1377 auto accountPermissions = get_account_permissions(tx_permission, {name(voter), config::active_name});
1378 send_actions({create_action(accountPermissions, config::system_account_name, "voteproducer"_n, act_payload)});
1379 });
1380 }
std::string name
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition CLI11.hpp:5538
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition CLI11.hpp:5099
CRTP * required(bool value=true)
Set the option as required.
Definition CLI11.hpp:3400
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
#define localized(str,...)
Definition localize.hpp:10
fc::string to_string(double)
Definition string.cpp:131
const string get_table_func
Definition httpc.hpp:94
chain::action create_action(const vector< permission_level > &authorization, const account_name &code, const action_name &act, const fc::variant &args)
Definition main.cpp:683
vector< chain::permission_level > get_account_permissions(const vector< string > &permissions)
Definition main.cpp:238
void add_standard_transaction_options(CLI::App *cmd, string default_permission="")
Definition main.cpp:202
void send_actions(std::vector< chain::action > &&actions, packed_transaction::compression_type compression=packed_transaction::compression_type::none)
Definition main.cpp:616
vector< string > tx_permission
Definition main.cpp:198
fc::variant call(const std::string &url, const std::string &path, const T &v)
Definition main.cpp:258
Immutable except for fc::from_variant.
Definition name.hpp:43
Here is the call graph for this function:

Member Data Documentation

◆ producer_name

string unapprove_producer_subcommand::producer_name

Definition at line 1333 of file main.cpp.

◆ voter

string unapprove_producer_subcommand::voter

Definition at line 1332 of file main.cpp.


The documentation for this struct was generated from the following file: