From 116b5ea2958f7fc26d3da7f675caf4ba67d84cca Mon Sep 17 00:00:00 2001 From: Keke Li Date: Thu, 11 Feb 2021 16:10:39 -0800 Subject: [PATCH 1/2] Add cleos system activate subcommand to activate a system feature. such as: cleos system activate kv_database. don't need using digest. --- programs/cleos/main.cpp | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index cbd93671edc..09c9dd28d88 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -69,6 +69,8 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey #include #include #include +#include +#include #include #include #include @@ -2199,6 +2201,58 @@ 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 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 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; + } + fc::variant action_args_var; + if( !data.empty() ) { + 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()) { @@ -4318,6 +4372,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(); From 3d01442bec1aadd4e4c328aa72ae7155121c64ee Mon Sep 17 00:00:00 2001 From: Keke Li Date: Fri, 12 Feb 2021 10:13:21 -0800 Subject: [PATCH 2/2] enhance error handling --- programs/cleos/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 09c9dd28d88..3ea631ab6f9 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -2241,11 +2241,10 @@ struct activate_subcommand { data = "[\"" + feature_digest + "\"]"; } else { std::cout << "Can't find system feature : " << feature_name_str << std::endl; + return; } fc::variant action_args_var; - if( !data.empty() ) { - action_args_var = json_from_file_or_string(data, fc::json::parse_type::relaxed_parser); - } + 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());