Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Rename cleos sudo command to wrap; also allow user to override contract account #5953

Merged
merged 2 commits into from
Oct 10, 2018
Merged
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
24 changes: 13 additions & 11 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3053,34 +3053,36 @@ int main( int argc, char** argv ) {
}
);

// sudo subcommand
auto sudo = app.add_subcommand("sudo", localized("Sudo contract commands"), false);
sudo->require_subcommand();
// wrap subcommand
auto wrap = app.add_subcommand("wrap", localized("Wrap contract commands"), false);
wrap->require_subcommand();

// sudo exec
// wrap exec
string wrap_con = "eosio.wrap";
executer = "";
string trx_to_exec;
auto sudo_exec = sudo->add_subcommand("exec", localized("Execute a transaction while bypassing authorization checks"));
add_standard_transaction_options(sudo_exec);
sudo_exec->add_option("executer", executer, localized("Account executing the transaction and paying for the deferred transaction RAM"))->required();
sudo_exec->add_option("transaction", trx_to_exec, localized("The JSON string or filename defining the transaction to execute"))->required();
auto wrap_exec = wrap->add_subcommand("exec", localized("Execute a transaction while bypassing authorization checks"));
add_standard_transaction_options(wrap_exec);
wrap_exec->add_option("executer", executer, localized("Account executing the transaction and paying for the deferred transaction RAM"))->required();
wrap_exec->add_option("transaction", trx_to_exec, localized("The JSON string or filename defining the transaction to execute"))->required();
wrap_exec->add_option("--contract,-c", wrap_con, localized("The account which controls the wrap contract"));

sudo_exec->set_callback([&] {
wrap_exec->set_callback([&] {
fc::variant trx_var;
try {
trx_var = json_from_file_or_string(trx_to_exec);
} EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Fail to parse transaction JSON '${data}'", ("data",trx_to_exec))

auto accountPermissions = get_account_permissions(tx_permission);
if( accountPermissions.empty() ) {
accountPermissions = vector<permission_level>{{executer, config::active_name}, {"eosio.sudo", config::active_name}};
accountPermissions = vector<permission_level>{{executer, config::active_name}, {wrap_con, config::active_name}};
}

auto args = fc::mutable_variant_object()
("executer", executer )
("trx", trx_var);

send_actions({chain::action{accountPermissions, "eosio.sudo", "exec", variant_to_bin( N(eosio.sudo), N(exec), args ) }});
send_actions({chain::action{accountPermissions, wrap_con, "exec", variant_to_bin( wrap_con, N(exec), args ) }});
});

// system subcommand
Expand Down