1
0
Fork 0
forked from lthn/blockchain

made some of the api optional

This commit is contained in:
cryptozoidberg 2025-07-15 14:30:55 +04:00 committed by sowle
parent 992ea22294
commit 695bd88c11
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 33 additions and 3 deletions

View file

@ -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<command_type, true>(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<epee::json_rpc::error_response&>(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() \

View file

@ -42,6 +42,7 @@ namespace currency
const command_line::arg_descriptor<std::string> arg_rpc_bind_ip ("rpc-bind-ip", "", "127.0.0.1");
const command_line::arg_descriptor<std::string> arg_rpc_bind_port ("rpc-bind-port", "", std::to_string(RPC_DEFAULT_PORT));
const command_line::arg_descriptor<bool> arg_rpc_ignore_offline_status ("rpc-ignore-offline", "Let rpc calls despite online/offline status");
const command_line::arg_descriptor<bool> 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<currency::t_currency_protocol_handler<currency::core> >& 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;
}
//------------------------------------------------------------------------------------------------------------------------------

View file

@ -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;
};
}