diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index 05e0b691..5e73df90 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -507,6 +507,26 @@ namespace epee { return true;\ } +#define MAP_JON_RPC_CONDITIONAL(method_name, callback_f, command_type, predicate) \ + else if(predicate && auto_doc(current_zone_json_uri, method_name, true, docs) && callback_name == method_name) \ +{ \ + call_found = true; \ + PREPARE_OBJECTS_FROM_JSON(command_type) \ + if(!callback_f(req.params, resp.result, m_conn_context)) \ + { \ + epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \ + fail_resp.jsonrpc = "2.0"; \ + fail_resp.method = req.method; \ + fail_resp.id = req.id; \ + fail_resp.error.code = -32603; \ + fail_resp.error.message = "Internal error"; \ + epee::serialization::store_t_to_json(static_cast(fail_resp), response_info.m_body); \ + return true; \ + } \ + FINALIZE_OBJECTS_TO_JSON(method_name) \ + return true;\ +} + #define MAP_JON_RPC_N(callback_f, command_type) MAP_JON_RPC(command_type::methodname(), callback_f, command_type) #define END_JSON_RPC_MAP() \ diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index bf6b6912..1fb4aacb 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -42,6 +42,7 @@ namespace currency const command_line::arg_descriptor arg_rpc_bind_ip ("rpc-bind-ip", "", "127.0.0.1"); const command_line::arg_descriptor arg_rpc_bind_port ("rpc-bind-port", "", std::to_string(RPC_DEFAULT_PORT)); const command_line::arg_descriptor arg_rpc_ignore_offline_status ("rpc-ignore-offline", "Let rpc calls despite online/offline status"); + const command_line::arg_descriptor arg_rpc_enable_rpc_api ("rpc-enable-admin-api", "Enable API commands that can alter state of pool or daemon(reset pool, remove txs etc)"); } //----------------------------------------------------------------------------------- void core_rpc_server::init_options(boost::program_options::options_description& desc) @@ -49,6 +50,8 @@ namespace currency command_line::add_arg(desc, arg_rpc_bind_ip); command_line::add_arg(desc, arg_rpc_bind_port); command_line::add_arg(desc, arg_rpc_ignore_offline_status); + command_line::add_arg(desc, arg_rpc_enable_rpc_api); + } //------------------------------------------------------------------------------------------------------------------------------ core_rpc_server::core_rpc_server(core& cr, nodetool::node_server >& p2p, @@ -74,6 +77,11 @@ namespace currency { m_ignore_offline_status = command_line::get_arg(vm, arg_rpc_ignore_offline_status); } + if (command_line::has_arg(vm, arg_rpc_enable_rpc_api)) + { + m_enabled_admin_api = command_line::get_arg(vm, arg_rpc_enable_rpc_api); + } + return true; } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index fa5313e3..3dc4049d 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -171,9 +171,10 @@ namespace currency MAP_JON_RPC_WE("get_alt_block_details", on_get_alt_block_details, COMMAND_RPC_GET_BLOCK_DETAILS) MAP_JON_RPC ("get_alt_blocks_details", on_get_alt_blocks_details, COMMAND_RPC_GET_ALT_BLOCKS_DETAILS) // - MAP_JON_RPC ("reset_transaction_pool", on_reset_transaction_pool, COMMAND_RPC_RESET_TX_POOL) - MAP_JON_RPC ("remove_tx_from_pool", on_remove_tx_from_pool, COMMAND_RPC_REMOVE_TX_FROM_POOL) - MAP_JON_RPC ("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN) + MAP_JON_RPC_CONDITIONAL("reset_transaction_pool", on_reset_transaction_pool, COMMAND_RPC_RESET_TX_POOL, m_enabled_admin_api) + MAP_JON_RPC_CONDITIONAL("remove_tx_from_pool", on_remove_tx_from_pool, COMMAND_RPC_REMOVE_TX_FROM_POOL, m_enabled_admin_api) + + MAP_JON_RPC("get_current_core_tx_expiration_median", on_get_current_core_tx_expiration_median, COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN) // MAP_JON_RPC_WE("marketplace_global_get_offers_ex", on_get_offers_ex, COMMAND_RPC_GET_OFFERS_EX) MAP_JON_RPC_WE("validate_signature", on_validate_signature, COMMAND_VALIDATE_SIGNATURE) @@ -200,6 +201,7 @@ namespace currency std::string m_port; std::string m_bind_ip; bool m_ignore_offline_status; + bool m_enabled_admin_api = false; epee::net_utils::http::i_chain_handler* m_prpc_chain_handler = nullptr; }; }