added proxy to daemon

This commit is contained in:
cryptozoidberg 2025-03-18 18:51:27 +04:00
parent 3a29780d8f
commit 3e2a39db2c
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
4 changed files with 61 additions and 1 deletions

View file

@ -21,6 +21,7 @@
#define API_RETURN_CODE_BAD_ARG_WRONG_AMOUNT "BAD_ARG_WRONG_AMOUNT"
#define API_RETURN_CODE_BAD_ARG_UNKNOWN_DECIMAL_POINT "BAD_ARG_UNKNOWN_DECIMAL_POINT"
#define API_RETURN_CODE_BAD_ARG_WRONG_PAYMENT_ID "BAD_ARG_WRONG_PAYMENT_ID"
#define API_RETURN_CODE_BAD_ARG_INVALID_JSON "BAD_ARG_INVALID_JSON"
#define API_RETURN_CODE_WRONG_PASSWORD "WRONG_PASSWORD"
#define API_RETURN_CODE_WALLET_WRONG_ID "WALLET_WRONG_ID"
#define API_RETURN_CODE_WALLET_WATCH_ONLY_NOT_SUPPORTED "WALLET_WATCH_ONLY_NOT_SUPPORTED"

View file

@ -63,7 +63,8 @@ namespace tools
#endif
const epee::net_utils::http::http_response_info* response = nullptr;
bool res = m_http_client.invoke(uri, "POST", body, &response);
bool res = epee::net_utils::http::invoke_request(m_daemon_address + uri, m_http_client, m_connection_timeout, &response, "POST", body);
//bool res = m_http_client.invoke(uri, "POST", body, &response);
if (response)
{
response_body = response->m_body;

View file

@ -73,6 +73,7 @@ namespace plain_wallet
std::atomic<uint64_t> gjobs_counter;
std::map<uint64_t, std::string> gjobs;
epee::critical_section gjobs_lock;
tools::default_http_core_proxy m_common_daemon_proxy;
};
std::shared_ptr<plain_wallet::plain_wallet_instance> ginstance_ptr;
@ -249,6 +250,8 @@ namespace plain_wallet
ptr->postponed_main_worked_started = true;
}
ptr->m_common_daemon_proxy.set_connection_addr(ip + ":" + port);
LOG_PRINT_L0("[INIT PLAIN_WALLET_INSTANCE] Ver:" << PROJECT_VERSION_LONG << "(" << BUILD_TYPE << ")" << ENDL << "Working dir: " << working_dir << ENDL << "URL: " << ip << ", port: " << port);
@ -598,6 +601,35 @@ namespace plain_wallet
return sanitized_store_to_json(ar);
}
std::string handle_proxy_to_daemon(const std::string& data)
{
GET_INSTANCE_PTR(inst_ptr);
tools::wallet_public::COMMAND_PROXY_TO_DAEMON::request req;
tools::wallet_public::COMMAND_PROXY_TO_DAEMON::response res;
if (!epee::serialization::load_t_from_json(req, data))
{
view::api_response ar = AUTO_VAL_INIT(ar);
ar.error_code = API_RETURN_CODE_BAD_ARG_INVALID_JSON;
return sanitized_store_to_json(ar);
}
std::string buff = epee::string_encoding::base64_decode(req.base64_body);
int response_code = 0;
std::string response_body;
if (!inst_ptr->m_common_daemon_proxy.call_COMMAND_RPC_INVOKE(req.uri, buff, response_code, response_body))
{
view::api_response ar = AUTO_VAL_INIT(ar);
ar.error_code = API_RETURN_CODE_FAIL;
return sanitized_store_to_json(ar);
}
res.base64_body = epee::string_encoding::base64_encode(response_body);
res.response_code = response_code;
return sanitized_store_to_json(res);
}
std::string handle_run_wallet(uint64_t instance_id)
{
GET_INSTANCE_PTR(inst_ptr);
@ -708,6 +740,10 @@ namespace plain_wallet
{
res = handle_run_wallet(instance_id);
}
else if (method_name == "proxy_to_daemon")
{
res = handle_proxy_to_daemon(params);
}
else
{
view::api_response ar = AUTO_VAL_INIT(ar);

View file

@ -46,6 +46,21 @@ void test_plain_wallet()
conf.postponed_run_wallet = true;
std::string r = plain_wallet::sync_call("configure", 0, epee::serialization::store_t_to_json(conf));
//-------------------------------------------------------------------
//test proxy_to_wallet
std::string daemon_body = "{\"method\":\"getinfo\",\"params\":{}}";
std::string daemon_body_base64 = epee::string_encoding::base64_encode(daemon_body);
tools::wallet_public::COMMAND_PROXY_TO_DAEMON::request req_to_daemon;
req_to_daemon.uri = "/json_rpc";
req_to_daemon.base64_body = daemon_body_base64;
std::string rsp_ = plain_wallet::sync_call("proxy_to_daemon", 0, epee::serialization::store_t_to_json(req_to_daemon));
//-------------------------------------------------------------------
std::string seed;
if (!epee::file_io_utils::load_file_to_string("C:\\Users\\roky\\home\\temp\\wallets\\seed.txt", seed))
return;
@ -65,6 +80,11 @@ void test_plain_wallet()
r = plain_wallet::sync_call("run_wallet", instance_id, "");
while(true)
{
epee::misc_utils::sleep_no_w(2000);
@ -75,6 +95,8 @@ void test_plain_wallet()
if (wsi.wallet_state == 2)
break;
}
std::string invoke_body = "{\"method\":\"store\",\"params\":{}}";
std::string res1 = plain_wallet::sync_call("invoke", instance_id, invoke_body);