aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-07-20 13:55:59 +0200
committerRiccardo Spagni <ric@spagni.net>2016-07-20 13:55:59 +0200
commitfc3e135b8387b8aab2eb9917240e7d312c7b0c2f (patch)
tree269e1979f4c347bacc955857b5837cc637caf009 /src/wallet
parentMerge pull request #900 (diff)
parentAdd a daemon RPC version, and make simplewallet check it (diff)
downloadmonero-fc3e135b8387b8aab2eb9917240e7d312c7b0c2f.tar.xz
Merge pull request #902
014f3a0 Add a daemon RPC version, and make simplewallet check it (moneromooo-monero)
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp33
-rw-r--r--src/wallet/wallet2.h2
2 files changed, 26 insertions, 9 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 6d676c6bd..d18681f36 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1436,22 +1436,39 @@ bool wallet2::prepare_file_names(const std::string& file_path)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::check_connection()
+bool wallet2::check_connection(bool *same_version)
{
boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
- if(m_http_client.is_connected())
- return true;
+ if(!m_http_client.is_connected())
+ {
+ net_utils::http::url_content u;
+ net_utils::parse_url(m_daemon_address, u);
- net_utils::http::url_content u;
- net_utils::parse_url(m_daemon_address, u);
+ if(!u.port)
+ {
+ u.port = m_testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT;
+ }
- if(!u.port)
+ if (!m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT))
+ return false;
+ }
+
+ if (same_version)
{
- u.port = m_testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT;
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_VERSION::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_VERSION::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
+ req_t.jsonrpc = "2.0";
+ req_t.id = epee::serialization::storage_entry(0);
+ req_t.method = "get_version";
+ bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
+ if (!r || resp_t.result.status != CORE_RPC_STATUS_OK)
+ *same_version = false;
+ else
+ *same_version = resp_t.result.version == CORE_RPC_VERSION;
}
- return m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT);
+ return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::generate_chacha8_key_from_secret_keys(crypto::chacha8_key &key) const
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index ca5cec43c..d004b7da9 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -296,7 +296,7 @@ namespace tools
std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint64_t fee_multiplier, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<wallet2::pending_tx> create_transactions_all(const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, uint64_t fee_multiplier, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
- bool check_connection();
+ bool check_connection(bool *same_version = NULL);
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height, uint64_t max_height = (uint64_t)-1) const;