mirror of
https://github.com/monero-project/monero.git
synced 2024-12-14 04:16:32 +02:00
Merge pull request #5319
f825055d
wallet_rpc_server: error out on getting the spend key from a hot wallet (moneromooo-monero)67aa4adc
wallet_rpc_server: add a set_daemon RPC (moneromooo-monero)705acbac
wallet2: init some variables to default values if loading old wallets (moneromooo-monero)f82bc29e
wallet_rpc_server: always fill out subaddr_indices in get_transfers (moneromooo-monero)01efdc6a
wallet_rpc_server: set confirmations to 0 for pending/pool txes (moneromooo-monero)
This commit is contained in:
commit
b6726aaa6c
@ -1154,21 +1154,29 @@ std::unique_ptr<wallet2> wallet2::make_dummy(const boost::program_options::varia
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, boost::asio::ip::tcp::endpoint proxy, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::list<std::string> &allowed_certificates, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert)
|
bool wallet2::set_daemon(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, bool trusted_daemon,
|
||||||
|
epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path,
|
||||||
|
const std::list<std::string> &allowed_certificates, const std::vector<std::vector<uint8_t>> &allowed_fingerprints,
|
||||||
|
bool allow_any_cert)
|
||||||
{
|
{
|
||||||
m_checkpoints.init_default_checkpoints(m_nettype);
|
|
||||||
if(m_http_client.is_connected())
|
if(m_http_client.is_connected())
|
||||||
m_http_client.disconnect();
|
m_http_client.disconnect();
|
||||||
m_is_initialized = true;
|
|
||||||
m_upper_transaction_weight_limit = upper_transaction_weight_limit;
|
|
||||||
m_daemon_address = std::move(daemon_address);
|
m_daemon_address = std::move(daemon_address);
|
||||||
m_daemon_login = std::move(daemon_login);
|
m_daemon_login = std::move(daemon_login);
|
||||||
m_trusted_daemon = trusted_daemon;
|
m_trusted_daemon = trusted_daemon;
|
||||||
|
|
||||||
|
MINFO("setting daemon to " << get_daemon_address());
|
||||||
|
return m_http_client.set_server(get_daemon_address(), get_daemon_login(), ssl_support, private_key_and_certificate_path, allowed_certificates, allowed_fingerprints, allow_any_cert);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, boost::asio::ip::tcp::endpoint proxy, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::list<std::string> &allowed_certificates, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert)
|
||||||
|
{
|
||||||
|
m_checkpoints.init_default_checkpoints(m_nettype);
|
||||||
|
m_is_initialized = true;
|
||||||
|
m_upper_transaction_weight_limit = upper_transaction_weight_limit;
|
||||||
if (proxy != boost::asio::ip::tcp::endpoint{})
|
if (proxy != boost::asio::ip::tcp::endpoint{})
|
||||||
m_http_client.set_connector(net::socks::connector{std::move(proxy)});
|
m_http_client.set_connector(net::socks::connector{std::move(proxy)});
|
||||||
|
return set_daemon(daemon_address, daemon_login, trusted_daemon, ssl_support, private_key_and_certificate_path, allowed_certificates, allowed_fingerprints, allow_any_cert);
|
||||||
// When switching from light wallet to full wallet, we need to reset the height we got from lw node.
|
|
||||||
return m_http_client.set_server(get_daemon_address(), get_daemon_login(), ssl_support, private_key_and_certificate_path, allowed_certificates, allowed_fingerprints, allow_any_cert);
|
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool wallet2::is_deterministic() const
|
bool wallet2::is_deterministic() const
|
||||||
@ -3643,13 +3651,16 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
|
|||||||
m_multisig_derivations.clear();
|
m_multisig_derivations.clear();
|
||||||
m_always_confirm_transfers = false;
|
m_always_confirm_transfers = false;
|
||||||
m_print_ring_members = false;
|
m_print_ring_members = false;
|
||||||
|
m_store_tx_info = true;
|
||||||
m_default_mixin = 0;
|
m_default_mixin = 0;
|
||||||
m_default_priority = 0;
|
m_default_priority = 0;
|
||||||
m_auto_refresh = true;
|
m_auto_refresh = true;
|
||||||
m_refresh_type = RefreshType::RefreshDefault;
|
m_refresh_type = RefreshType::RefreshDefault;
|
||||||
|
m_refresh_from_block_height = 0;
|
||||||
m_confirm_missing_payment_id = true;
|
m_confirm_missing_payment_id = true;
|
||||||
m_confirm_non_default_ring_size = true;
|
m_confirm_non_default_ring_size = true;
|
||||||
m_ask_password = AskPasswordToDecrypt;
|
m_ask_password = AskPasswordToDecrypt;
|
||||||
|
cryptonote::set_default_decimal_point(CRYPTONOTE_DISPLAY_DECIMAL_POINT);
|
||||||
m_min_output_count = 0;
|
m_min_output_count = 0;
|
||||||
m_min_output_value = 0;
|
m_min_output_value = 0;
|
||||||
m_merge_destinations = false;
|
m_merge_destinations = false;
|
||||||
|
@ -691,6 +691,12 @@ namespace tools
|
|||||||
const std::pair<std::string, std::string> &private_key_and_certificate_path = {},
|
const std::pair<std::string, std::string> &private_key_and_certificate_path = {},
|
||||||
const std::list<std::string> &allowed_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_fingerprints = {},
|
const std::list<std::string> &allowed_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_fingerprints = {},
|
||||||
bool allow_any_cert = false);
|
bool allow_any_cert = false);
|
||||||
|
bool set_daemon(std::string daemon_address = "http://localhost:8080",
|
||||||
|
boost::optional<epee::net_utils::http::login> daemon_login = boost::none, bool trusted_daemon = true,
|
||||||
|
epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect,
|
||||||
|
const std::pair<std::string, std::string> &private_key_and_certificate_path = {},
|
||||||
|
const std::list<std::string> &allowed_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_fingerprints = {},
|
||||||
|
bool allow_any_cert = false);
|
||||||
|
|
||||||
void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); }
|
void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); }
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ namespace
|
|||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
void set_confirmations(tools::wallet_rpc::transfer_entry &entry, uint64_t blockchain_height, uint64_t block_reward)
|
void set_confirmations(tools::wallet_rpc::transfer_entry &entry, uint64_t blockchain_height, uint64_t block_reward)
|
||||||
{
|
{
|
||||||
if (entry.height >= blockchain_height)
|
if (entry.height >= blockchain_height || (entry.height == 0 && (!strcmp(entry.type.c_str(), "pending") || !strcmp(entry.type.c_str(), "pool"))))
|
||||||
{
|
{
|
||||||
entry.confirmations = 0;
|
entry.confirmations = 0;
|
||||||
entry.suggested_confirmations_threshold = 0;
|
entry.suggested_confirmations_threshold = 0;
|
||||||
@ -302,6 +302,7 @@ namespace tools
|
|||||||
entry.note = m_wallet->get_tx_note(pd.m_tx_hash);
|
entry.note = m_wallet->get_tx_note(pd.m_tx_hash);
|
||||||
entry.type = pd.m_coinbase ? "block" : "in";
|
entry.type = pd.m_coinbase ? "block" : "in";
|
||||||
entry.subaddr_index = pd.m_subaddr_index;
|
entry.subaddr_index = pd.m_subaddr_index;
|
||||||
|
entry.subaddr_indices.push_back(pd.m_subaddr_index);
|
||||||
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
|
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
|
||||||
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
|
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
|
||||||
}
|
}
|
||||||
@ -373,6 +374,7 @@ namespace tools
|
|||||||
entry.double_spend_seen = ppd.m_double_spend_seen;
|
entry.double_spend_seen = ppd.m_double_spend_seen;
|
||||||
entry.type = "pool";
|
entry.type = "pool";
|
||||||
entry.subaddr_index = pd.m_subaddr_index;
|
entry.subaddr_index = pd.m_subaddr_index;
|
||||||
|
entry.subaddr_indices.push_back(pd.m_subaddr_index);
|
||||||
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
|
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
|
||||||
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
|
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward());
|
||||||
}
|
}
|
||||||
@ -1830,7 +1832,7 @@ namespace tools
|
|||||||
if (m_wallet->watch_only())
|
if (m_wallet->watch_only())
|
||||||
{
|
{
|
||||||
er.code = WALLET_RPC_ERROR_CODE_WATCH_ONLY;
|
er.code = WALLET_RPC_ERROR_CODE_WATCH_ONLY;
|
||||||
er.message = "The wallet is watch-only. Cannot display seed.";
|
er.message = "The wallet is watch-only. Cannot retrieve seed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!m_wallet->is_deterministic())
|
if (!m_wallet->is_deterministic())
|
||||||
@ -1855,6 +1857,12 @@ namespace tools
|
|||||||
}
|
}
|
||||||
else if(req.key_type.compare("spend_key") == 0)
|
else if(req.key_type.compare("spend_key") == 0)
|
||||||
{
|
{
|
||||||
|
if (m_wallet->watch_only())
|
||||||
|
{
|
||||||
|
er.code = WALLET_RPC_ERROR_CODE_WATCH_ONLY;
|
||||||
|
er.message = "The wallet is watch-only. Cannot retrieve spend key.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
epee::wipeable_string key = epee::to_hex::wipeable_string(m_wallet->get_account().get_keys().m_spend_secret_key);
|
epee::wipeable_string key = epee::to_hex::wipeable_string(m_wallet->get_account().get_keys().m_spend_secret_key);
|
||||||
res.key = std::string(key.data(), key.size());
|
res.key = std::string(key.data(), key.size());
|
||||||
}
|
}
|
||||||
@ -4031,6 +4039,40 @@ namespace tools
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool wallet_rpc_server::on_set_daemon(const wallet_rpc::COMMAND_RPC_SET_DAEMON::request& req, wallet_rpc::COMMAND_RPC_SET_DAEMON::response& res, epee::json_rpc::error& er, const connection_context *ctx)
|
||||||
|
{
|
||||||
|
if (!m_wallet) return not_open(er);
|
||||||
|
if (m_restricted)
|
||||||
|
{
|
||||||
|
er.code = WALLET_RPC_ERROR_CODE_DENIED;
|
||||||
|
er.message = "Command unavailable in restricted mode.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
epee::net_utils::ssl_support_t ssl_support;
|
||||||
|
if (!epee::net_utils::ssl_support_from_string(ssl_support, req.ssl_support))
|
||||||
|
{
|
||||||
|
er.code = WALLET_RPC_ERROR_CODE_NO_DAEMON_CONNECTION;
|
||||||
|
er.message = std::string("Invalid ssl support mode");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints;
|
||||||
|
ssl_allowed_fingerprints.reserve(req.ssl_allowed_fingerprints.size());
|
||||||
|
for (const std::string &fp: req.ssl_allowed_fingerprints)
|
||||||
|
{
|
||||||
|
ssl_allowed_fingerprints.push_back({});
|
||||||
|
std::vector<uint8_t> &v = ssl_allowed_fingerprints.back();
|
||||||
|
for (auto c: fp)
|
||||||
|
v.push_back(c);
|
||||||
|
}
|
||||||
|
if (!m_wallet->set_daemon(req.address, boost::none, req.trusted, ssl_support, std::make_pair(req.ssl_private_key_path, req.ssl_certificate_path), req.ssl_allowed_certificates, ssl_allowed_fingerprints, req.ssl_allow_any_cert))
|
||||||
|
{
|
||||||
|
er.code = WALLET_RPC_ERROR_CODE_NO_DAEMON_CONNECTION;
|
||||||
|
er.message = std::string("Unable to set daemon");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool wallet_rpc_server::on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx)
|
bool wallet_rpc_server::on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx)
|
||||||
{
|
{
|
||||||
res.version = WALLET_RPC_VERSION;
|
res.version = WALLET_RPC_VERSION;
|
||||||
|
@ -150,6 +150,7 @@ namespace tools
|
|||||||
MAP_JON_RPC_WE("sign_multisig", on_sign_multisig, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG)
|
MAP_JON_RPC_WE("sign_multisig", on_sign_multisig, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG)
|
||||||
MAP_JON_RPC_WE("submit_multisig", on_submit_multisig, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG)
|
MAP_JON_RPC_WE("submit_multisig", on_submit_multisig, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG)
|
||||||
MAP_JON_RPC_WE("validate_address", on_validate_address, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS)
|
MAP_JON_RPC_WE("validate_address", on_validate_address, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS)
|
||||||
|
MAP_JON_RPC_WE("set_daemon", on_set_daemon, wallet_rpc::COMMAND_RPC_SET_DAEMON)
|
||||||
MAP_JON_RPC_WE("get_version", on_get_version, wallet_rpc::COMMAND_RPC_GET_VERSION)
|
MAP_JON_RPC_WE("get_version", on_get_version, wallet_rpc::COMMAND_RPC_GET_VERSION)
|
||||||
END_JSON_RPC_MAP()
|
END_JSON_RPC_MAP()
|
||||||
END_URI_MAP2()
|
END_URI_MAP2()
|
||||||
@ -232,6 +233,7 @@ namespace tools
|
|||||||
bool on_sign_multisig(const wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
bool on_sign_multisig(const wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||||
bool on_submit_multisig(const wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
bool on_submit_multisig(const wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||||
bool on_validate_address(const wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
bool on_validate_address(const wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||||
|
bool on_set_daemon(const wallet_rpc::COMMAND_RPC_SET_DAEMON::request& req, wallet_rpc::COMMAND_RPC_SET_DAEMON::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||||
bool on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
bool on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||||
|
|
||||||
//json rpc v2
|
//json rpc v2
|
||||||
|
@ -2437,5 +2437,39 @@ namespace wallet_rpc
|
|||||||
typedef epee::misc_utils::struct_init<response_t> response;
|
typedef epee::misc_utils::struct_init<response_t> response;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct COMMAND_RPC_SET_DAEMON
|
||||||
|
{
|
||||||
|
struct request_t
|
||||||
|
{
|
||||||
|
std::string address;
|
||||||
|
bool trusted;
|
||||||
|
std::string ssl_support; // disabled, enabled, autodetect
|
||||||
|
std::string ssl_private_key_path;
|
||||||
|
std::string ssl_certificate_path;
|
||||||
|
std::list<std::string> ssl_allowed_certificates;
|
||||||
|
std::vector<std::string> ssl_allowed_fingerprints;
|
||||||
|
bool ssl_allow_any_cert;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(address)
|
||||||
|
KV_SERIALIZE_OPT(trusted, false)
|
||||||
|
KV_SERIALIZE_OPT(ssl_support, (std::string)"autodetect")
|
||||||
|
KV_SERIALIZE(ssl_private_key_path)
|
||||||
|
KV_SERIALIZE(ssl_certificate_path)
|
||||||
|
KV_SERIALIZE(ssl_allowed_certificates)
|
||||||
|
KV_SERIALIZE(ssl_allowed_fingerprints)
|
||||||
|
KV_SERIALIZE_OPT(ssl_allow_any_cert, false)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
typedef epee::misc_utils::struct_init<request_t> request;
|
||||||
|
|
||||||
|
struct response_t
|
||||||
|
{
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
typedef epee::misc_utils::struct_init<response_t> response;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user