mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 03:59:33 +00:00
wallet rpc: enable solo mining
This commit is contained in:
parent
73e8510717
commit
8bbcbcfb0d
3 changed files with 93 additions and 0 deletions
|
@ -46,6 +46,7 @@ using namespace epee;
|
|||
#include "string_tools.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "rpc/rpc_args.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
|
||||
|
@ -172,6 +173,8 @@ namespace tools
|
|||
LOG_PRINT_L0(tr("RPC username/password is stored in file ") << temp);
|
||||
} // end auth enabled
|
||||
|
||||
m_http_client.set_server(m_wallet.get_daemon_address(), m_wallet.get_daemon_login());
|
||||
|
||||
m_net_server.set_threads_prefix("RPC");
|
||||
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
|
||||
std::move(bind_port), std::move(rpc_config->bind_ip), std::move(http_login)
|
||||
|
@ -1424,6 +1427,54 @@ namespace tools
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_start_mining(const wallet_rpc::COMMAND_RPC_START_MINING::request& req, wallet_rpc::COMMAND_RPC_START_MINING::response& res, epee::json_rpc::error& er)
|
||||
{
|
||||
if (!m_trusted_daemon)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = "This command requires a trusted daemon.";
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast<unsigned>(2));
|
||||
if (req.threads_count < 1 || max_mining_threads_count < req.threads_count)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = "The specified number of threads is inappropriate.";
|
||||
return false;
|
||||
}
|
||||
|
||||
cryptonote::COMMAND_RPC_START_MINING::request daemon_req = AUTO_VAL_INIT(daemon_req);
|
||||
daemon_req.miner_address = m_wallet.get_account().get_public_address_str(m_wallet.testnet());
|
||||
daemon_req.threads_count = req.threads_count;
|
||||
daemon_req.do_background_mining = req.do_background_mining;
|
||||
daemon_req.ignore_battery = req.ignore_battery;
|
||||
|
||||
cryptonote::COMMAND_RPC_START_MINING::response daemon_res;
|
||||
bool r = net_utils::invoke_http_json("/start_mining", daemon_req, daemon_res, m_http_client);
|
||||
if (!r || daemon_res.status != CORE_RPC_STATUS_OK)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = "Couldn't start mining due to unknown error.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_stop_mining(const wallet_rpc::COMMAND_RPC_STOP_MINING::request& req, wallet_rpc::COMMAND_RPC_STOP_MINING::response& res, epee::json_rpc::error& er)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_STOP_MINING::request daemon_req;
|
||||
cryptonote::COMMAND_RPC_STOP_MINING::response daemon_res;
|
||||
bool r = net_utils::invoke_http_json("/stop_mining", daemon_req, daemon_res, m_http_client);
|
||||
if (!r || daemon_res.status != CORE_RPC_STATUS_OK)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
er.message = "Couldn't stop mining due to unknown error.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
|
|
@ -93,6 +93,8 @@ namespace tools
|
|||
MAP_JON_RPC_WE("add_address_book", on_add_address_book, wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY)
|
||||
MAP_JON_RPC_WE("delete_address_book",on_delete_address_book,wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY)
|
||||
MAP_JON_RPC_WE("rescan_spent", on_rescan_spent, wallet_rpc::COMMAND_RPC_RESCAN_SPENT)
|
||||
MAP_JON_RPC_WE("start_mining", on_start_mining, wallet_rpc::COMMAND_RPC_START_MINING)
|
||||
MAP_JON_RPC_WE("stop_mining", on_stop_mining, wallet_rpc::COMMAND_RPC_STOP_MINING)
|
||||
END_JSON_RPC_MAP()
|
||||
END_URI_MAP2()
|
||||
|
||||
|
@ -127,6 +129,8 @@ namespace tools
|
|||
bool on_add_address_book(const wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er);
|
||||
bool on_delete_address_book(const wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er);
|
||||
bool on_rescan_spent(const wallet_rpc::COMMAND_RPC_RESCAN_SPENT::request& req, wallet_rpc::COMMAND_RPC_RESCAN_SPENT::response& res, epee::json_rpc::error& er);
|
||||
bool on_start_mining(const wallet_rpc::COMMAND_RPC_START_MINING::request& req, wallet_rpc::COMMAND_RPC_START_MINING::response& res, epee::json_rpc::error& er);
|
||||
bool on_stop_mining(const wallet_rpc::COMMAND_RPC_STOP_MINING::request& req, wallet_rpc::COMMAND_RPC_STOP_MINING::response& res, epee::json_rpc::error& er);
|
||||
|
||||
//json rpc v2
|
||||
bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er);
|
||||
|
@ -141,5 +145,6 @@ namespace tools
|
|||
std::string rpc_login_filename;
|
||||
std::atomic<bool> m_stop;
|
||||
bool m_trusted_daemon;
|
||||
epee::net_utils::http::http_simple_client m_http_client;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -872,5 +872,42 @@ namespace wallet_rpc
|
|||
};
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_START_MINING
|
||||
{
|
||||
struct request
|
||||
{
|
||||
uint64_t threads_count;
|
||||
bool do_background_mining;
|
||||
bool ignore_battery;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(threads_count)
|
||||
KV_SERIALIZE(do_background_mining)
|
||||
KV_SERIALIZE(ignore_battery)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_STOP_MINING
|
||||
{
|
||||
struct request
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue