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

Public Member Functions

 approve_producer_subcommand (CLI::App *actionRoot)
 

Public Attributes

string voter
 
string producer_name
 

Detailed Description

Definition at line 1278 of file main.cpp.

Constructor & Destructor Documentation

◆ approve_producer_subcommand()

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

Definition at line 1282 of file main.cpp.

1282 {
1283 auto approve_producer = actionRoot->add_subcommand("approve", localized("Add one producer to list of voted producers"));
1284 approve_producer->add_option("voter", voter, localized("The voting account"))->required();
1285 approve_producer->add_option("producer", producer_name, localized("The account to vote for"))->required();
1286 add_standard_transaction_options(approve_producer, "voter@active");
1287
1288 approve_producer->callback([this] {
1289 auto result = call(get_table_func, fc::mutable_variant_object("json", true)
1290 ("code", name(config::system_account_name).to_string())
1291 ("scope", name(config::system_account_name).to_string())
1292 ("table", "voters")
1293 ("table_key", "owner")
1294 ("lower_bound", name(voter).to_uint64_t())
1295 ("upper_bound", name(voter).to_uint64_t() + 1)
1296 // Less than ideal upper_bound usage preserved so clio can still work with old buggy nodeop versions
1297 // Change to voter.value when clio no longer needs to support nodeop versions older than 1.5.0
1298 ("limit", 1)
1299 );
1301 // 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
1302 // Although since this subcommand will actually change the voter's vote, it is probably better to just keep this check to protect
1303 // against future potential chain_plugin bugs.
1304 if( res.rows.empty() || res.rows[0].get_object()["owner"].as_string() != name(voter).to_string() ) {
1305 std::cerr << "Voter info not found for account " << voter << std::endl;
1306 return;
1307 }
1308 SYS_ASSERT( 1 == res.rows.size(), multiple_voter_info, "More than one voter_info for account" );
1309 auto prod_vars = res.rows[0]["producers"].get_array();
1310 vector<sysio::name> prods;
1311 for ( auto& x : prod_vars ) {
1312 prods.push_back( name(x.as_string()) );
1313 }
1314 prods.push_back( name(producer_name) );
1315 std::sort( prods.begin(), prods.end() );
1316 auto it = std::unique( prods.begin(), prods.end() );
1317 if (it != prods.end() ) {
1318 std::cerr << "Producer \"" << producer_name << "\" is already on the list." << std::endl;
1319 return;
1320 }
1322 ("voter", voter)
1323 ("proxy", "")
1324 ("producers", prods);
1325 auto accountPermissions = get_account_permissions(tx_permission, {name(voter), config::active_name});
1326 send_actions({create_action(accountPermissions, config::system_account_name, "voteproducer"_n, act_payload)});
1327 });
1328 }
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 approve_producer_subcommand::producer_name

Definition at line 1280 of file main.cpp.

◆ voter

string approve_producer_subcommand::voter

Definition at line 1279 of file main.cpp.


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