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

Commit

Permalink
Merge pull request #10036 from EOSIO/keke_epe453
Browse files Browse the repository at this point in the history
Add cleos system activate subcommand (to activate system feature like kv_database)
  • Loading branch information
softprofe authored Feb 13, 2021
2 parents 4094cd2 + 3d01442 commit ac118a1
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey
#include <vector>
#include <regex>
#include <iostream>
#include <locale>
#include <unordered_map>
#include <fc/crypto/hex.hpp>
#include <fc/variant.hpp>
#include <fc/io/datastream.hpp>
Expand Down Expand Up @@ -2199,6 +2201,57 @@ struct closerex_subcommand {
}
};

struct activate_subcommand {
string feature_name_str;

activate_subcommand(CLI::App* actionRoot) {
auto activate = actionRoot->add_subcommand("activate", localized("Activate system feature by feature name eg: KV_DATABASE"));
activate->add_option("feature", feature_name_str, localized("The system feature name to be activated, must be one of below(lowercase also works):\nPREACTIVATE_FEATURE\nONLY_LINK_TO_EXISTING_PERMISSION\nFORWARD_SETCODE\nKV_DATABASE\nWTMSIG_BLOCK_SIGNATURES\nREPLACE_DEFERRED\nNO_DUPLICATE_DEFERRED_ID\nRAM_RESTRICTIONS\nWEBAUTHN_KEY\nBLOCKCHAIN_PARAMETERS\nDISALLOW_EMPTY_PRODUCER_SCHEDULE\nONLY_BILL_FIRST_AUTHORIZER\nRESTRICT_ACTION_TO_SELF\nCONFIGURABLE_WASM_LIMITS\nACTION_RETURN_VALUE\nFIX_LINKAUTH_RESTRICTION\nGET_SENDER"))->required();
activate->fallthrough(false);
activate->callback([this] {
/// map feature name to feature digest
std::unordered_map<std::string, std::string> map_name_digest{
{"PREACTIVATE_FEATURE", "0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"},
{"ONLY_LINK_TO_EXISTING_PERMISSION", "1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b7241"},
{"FORWARD_SETCODE", "2652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25"},
{"KV_DATABASE", "825ee6288fb1373eab1b5187ec2f04f6eacb39cb3a97f356a07c91622dd61d16"},
{"WTMSIG_BLOCK_SIGNATURES", "299dcb6af692324b899b39f16d5a530a33062804e41f09dc97e9f156b4476707"},
{"REPLACE_DEFERRED", "ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99"},
{"NO_DUPLICATE_DEFERRED_ID", "4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f"},
{"RAM_RESTRICTIONS", "4e7bf348da00a945489b2a681749eb56f5de00b900014e137ddae39f48f69d67"},
{"WEBAUTHN_KEY", "4fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c2"},
{"BLOCKCHAIN_PARAMETERS", "5443fcf88330c586bc0e5f3dee10e7f63c76c00249c87fe4fbf7f38c082006b4"},
{"DISALLOW_EMPTY_PRODUCER_SCHEDULE", "68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428"},
{"ONLY_BILL_FIRST_AUTHORIZER", "8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405"},
{"RESTRICT_ACTION_TO_SELF", "ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43"},
{"CONFIGURABLE_WASM_LIMITS", "bf61537fd21c61a60e542a5d66c3f6a78da0589336868307f94a82bccea84e88"},
{"ACTION_RETURN_VALUE", "c3a6138c5061cf291310887c0b5c71fcaffeab90d5deb50d3b9e687cead45071"},
{"FIX_LINKAUTH_RESTRICTION", "e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526"},
{"GET_SENDER", "f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d"}
};
// push system feature
string contract_account = "eosio";
string action="activate";
string data;
std::locale loc;
vector<std::string> permissions = {"eosio"};
for(auto & c : feature_name_str) c = std::toupper(c, loc);
if(map_name_digest.find(feature_name_str) != map_name_digest.end()){
std::string feature_digest = map_name_digest[feature_name_str];
data = "[\"" + feature_digest + "\"]";
} else {
std::cout << "Can't find system feature : " << feature_name_str << std::endl;
return;
}
fc::variant action_args_var;
action_args_var = json_from_file_or_string(data, fc::json::parse_type::relaxed_parser);
auto accountPermissions = get_account_permissions(permissions);
send_actions({chain::action{accountPermissions, name(contract_account), name(action),
variant_to_bin( name(contract_account), name(action), action_args_var ) }}, signing_keys_opt.get_keys());
});
}
};

void get_account( const string& accountName, const string& coresym, bool json_format ) {
fc::variant json;
if (coresym.empty()) {
Expand Down Expand Up @@ -4318,6 +4371,7 @@ int main( int argc, char** argv ) {
auto unregProxy = unregproxy_subcommand(system);

auto cancelDelay = canceldelay_subcommand(system);
auto activate = activate_subcommand(system);

auto rex = system->add_subcommand("rex", localized("Actions related to REX (the resource exchange)"));
rex->require_subcommand();
Expand Down

0 comments on commit ac118a1

Please sign in to comment.