aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/command_line.cpp27
-rw-r--r--src/common/command_line.h3
-rw-r--r--src/cryptonote_core/cryptonote_basic_impl.cpp2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h11
-rw-r--r--src/simplewallet/simplewallet.cpp51
-rw-r--r--src/wallet/api/wallet.cpp11
-rw-r--r--src/wallet/api/wallet.h1
-rw-r--r--src/wallet/wallet2.cpp13
-rw-r--r--src/wallet/wallet2.h4
-rw-r--r--src/wallet/wallet2_api.h1
10 files changed, 89 insertions, 35 deletions
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index b3f488447..28879e098 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -29,11 +29,22 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "command_line.h"
-#include "string_tools.h"
+#include <boost/algorithm/string/compare.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include "common/i18n.h"
#include "cryptonote_config.h"
+#include "string_tools.h"
namespace command_line
{
+ namespace
+ {
+ const char* tr(const char* str)
+ {
+ return i18n_translate(str, "command_line");
+ }
+ }
+
std::string input_line(const std::string& prompt)
{
std::cout << prompt;
@@ -45,6 +56,20 @@ namespace command_line
}
+ bool is_yes(const std::string& str)
+ {
+ if (str == "y" || str == "Y")
+ return true;
+
+ boost::algorithm::is_iequal ignore_case{};
+ if (boost::algorithm::equals("yes", str, ignore_case))
+ return true;
+ if (boost::algorithm::equals(command_line::tr("yes"), str, ignore_case))
+ return true;
+
+ return false;
+ }
+
const arg_descriptor<bool> arg_help = {"help", "Produce help message"};
const arg_descriptor<bool> arg_version = {"version", "Output version information"};
const arg_descriptor<std::string> arg_data_dir = {"data-dir", "Specify data directory"};
diff --git a/src/common/command_line.h b/src/common/command_line.h
index 0ea749168..98c115bb7 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -43,6 +43,9 @@ namespace command_line
std::string input_line(const std::string& prompt);
+ //! \return True if `str` is `is_iequal("y" || "yes" || `tr("yes"))`.
+ bool is_yes(const std::string& str);
+
template<typename T, bool required = false>
struct arg_descriptor;
diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp
index 74f44e2af..4f35b8298 100644
--- a/src/cryptonote_core/cryptonote_basic_impl.cpp
+++ b/src/cryptonote_core/cryptonote_basic_impl.cpp
@@ -199,7 +199,7 @@ namespace cryptonote {
uint64_t prefix;
if (!tools::base58::decode_addr(str, prefix, data))
{
- LOG_PRINT_L1("Invalid address format");
+ LOG_PRINT_L2("Invalid address format");
return false;
}
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index e19238c44..23fcb0a92 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -41,7 +41,16 @@ namespace cryptonote
#define CORE_RPC_STATUS_BUSY "BUSY"
#define CORE_RPC_STATUS_NOT_MINING "NOT MINING"
-#define CORE_RPC_VERSION 5
+// When making *any* change here, bump minor
+// If the change is incompatible, then bump major and set minor to 0
+// This ensures CORE_RPC_VERSION always increases, that every change
+// has its own version, and that clients can just test major to see
+// whether they can talk to a given daemon without having to know in
+// advance which version they will stop working with
+// Don't go over 32767 for any of these
+#define CORE_RPC_VERSION_MAJOR 1
+#define CORE_RPC_VERSION_MINOR 0
+#define CORE_RPC_VERSION (((CORE_RPC_VERSION_MAJOR)<<16)|(CORE_RPC_VERSION_MINOR))
struct COMMAND_RPC_GET_HEIGHT
{
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 462cdf58f..faeed31ce 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -212,17 +212,17 @@ namespace
return message_writer(epee::log_space::console_color_red, true, sw::tr("Error: "), LOG_LEVEL_0);
}
- bool is_it_true(std::string s)
+ bool is_it_true(const std::string& s)
{
- std::transform(s.begin(), s.end(), s.begin(), ::tolower);
- if (s == "true")
+ if (s == "1" || command_line::is_yes(s))
return true;
- if (s == "1")
- return true;
- if (s == "y" || s == "yes")
+
+ boost::algorithm::is_iequal ignore_case{};
+ if (boost::algorithm::equals("true", s, ignore_case))
return true;
- if (s == sw::tr("yes"))
+ if (boost::algorithm::equals(simple_wallet::tr("true"), s, ignore_case))
return true;
+
return false;
}
@@ -263,6 +263,10 @@ namespace
return "invalid";
}
+ std::string get_version_string(uint32_t version)
+ {
+ return boost::lexical_cast<std::string>(version >> 16) + "." + boost::lexical_cast<std::string>(version & 0xffff);
+ }
}
@@ -916,7 +920,7 @@ bool simple_wallet::ask_wallet_create_if_needed()
LOG_ERROR("Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed()");
return false;
}
- if(is_it_true(confirm_creation))
+ if(command_line::is_yes(confirm_creation))
{
success_msg_writer() << tr("Generating new wallet...");
m_generate_new = wallet_path;
@@ -1189,8 +1193,8 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
//----------------------------------------------------------------------------------------------------
bool simple_wallet::try_connect_to_daemon(bool silent)
{
- bool same_version = false;
- if (!m_wallet->check_connection(&same_version))
+ uint32_t version = 0;
+ if (!m_wallet->check_connection(&version))
{
if (!silent)
fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_wallet->get_daemon_address() << ". " <<
@@ -1198,11 +1202,10 @@ bool simple_wallet::try_connect_to_daemon(bool silent)
"Please make sure daemon is running or restart the wallet with the correct daemon address.");
return false;
}
- if (!m_allow_mismatched_daemon_version && !same_version)
+ if (!m_allow_mismatched_daemon_version && ((version >> 16) != CORE_RPC_VERSION_MAJOR))
{
if (!silent)
- fail_msg_writer() << tr("Daemon uses a different RPC version that the wallet: ") << m_wallet->get_daemon_address() << ". " <<
- tr("Either update one of them, or use --allow-mismatched-daemon-version.");
+ fail_msg_writer() << boost::format(tr("Daemon uses a different RPC major version (%u) than the wallet (%u): %s. Either update one of them, or use --allow-mismatched-daemon-version.")) % (version>>16) % CORE_RPC_VERSION_MAJOR % m_wallet->get_daemon_address();
return false;
}
return true;
@@ -1977,8 +1980,7 @@ bool simple_wallet::get_address_from_str(const std::string &str, cryptonote::acc
{
return false;
}
- if (confirm_dns_ok != "Y" && confirm_dns_ok != "y" && confirm_dns_ok != "Yes" && confirm_dns_ok != "yes"
- && confirm_dns_ok != tr("yes") && confirm_dns_ok != tr("no"))
+ if (!command_line::is_yes(confirm_dns_ok))
{
fail_msg_writer() << tr("you have cancelled the transfer request");
return false;
@@ -2136,7 +2138,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
std::string accepted = command_line::input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No)"));
if (std::cin.eof())
return true;
- if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
+ if (!command_line::is_yes(accepted))
{
fail_msg_writer() << tr("transaction cancelled.");
@@ -2220,7 +2222,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
std::string accepted = command_line::input_line(prompt.str());
if (std::cin.eof())
return true;
- if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
+ if (!command_line::is_yes(accepted))
{
fail_msg_writer() << tr("transaction cancelled.");
@@ -2399,7 +2401,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
std::string accepted = command_line::input_line(prompt_str);
if (std::cin.eof())
return true;
- if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
+ if (!command_line::is_yes(accepted))
{
fail_msg_writer() << tr("transaction cancelled.");
@@ -2613,7 +2615,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
std::string accepted = command_line::input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No)"));
if (std::cin.eof())
return true;
- if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
+ if (!command_line::is_yes(accepted))
{
fail_msg_writer() << tr("transaction cancelled.");
@@ -2658,7 +2660,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
std::string accepted = command_line::input_line(prompt_str);
if (std::cin.eof())
return true;
- if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
+ if (!command_line::is_yes(accepted))
{
fail_msg_writer() << tr("transaction cancelled.");
@@ -2853,8 +2855,7 @@ bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes,
uint64_t fee = amount - amount_to_dests;
std::string prompt_str = (boost::format(tr("Loaded %lu transactions, for %s, fee %s, %s, %s, with min mixin %lu. %sIs this okay? (Y/Yes/N/No)")) % (unsigned long)get_num_txes() % print_money(amount) % print_money(fee) % dest_string % change_string % (unsigned long)min_mixin % extra_message).str();
- std::string accepted = command_line::input_line(prompt_str);
- return is_it_true(accepted);
+ return command_line::is_yes(command_line::input_line(prompt_str));
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs)
@@ -3564,7 +3565,8 @@ bool simple_wallet::get_tx_note(const std::vector<std::string> &args)
bool simple_wallet::status(const std::vector<std::string> &args)
{
uint64_t local_height = m_wallet->get_blockchain_current_height();
- if (!try_connect_to_daemon())
+ uint32_t version = 0;
+ if (!m_wallet->check_connection(&version))
{
success_msg_writer() << "Refreshed " << local_height << "/?, no daemon connected";
return true;
@@ -3575,7 +3577,8 @@ bool simple_wallet::status(const std::vector<std::string> &args)
if (err.empty())
{
bool synced = local_height == bc_height;
- success_msg_writer() << "Refreshed " << local_height << "/" << bc_height << ", " << (synced ? "synced" : "syncing");
+ success_msg_writer() << "Refreshed " << local_height << "/" << bc_height << ", " << (synced ? "synced" : "syncing")
+ << ", daemon RPC v" << get_version_string(version);
}
else
{
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 215b61aef..97aaf2785 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -399,6 +399,11 @@ std::string WalletImpl::integratedAddress(const std::string &payment_id) const
return m_wallet->get_account().get_public_integrated_address_str(pid, m_wallet->testnet());
}
+std::string WalletImpl::path() const
+{
+ return m_wallet->path();
+}
+
bool WalletImpl::store(const std::string &path)
{
clearStatus();
@@ -906,11 +911,11 @@ bool WalletImpl::connectToDaemon()
Wallet::ConnectionStatus WalletImpl::connected() const
{
- bool same_version = false;
- bool is_connected = m_wallet->check_connection(&same_version);
+ uint32_t version = 0;
+ bool is_connected = m_wallet->check_connection(&version);
if (!is_connected)
return Wallet::ConnectionStatus_Disconnected;
- if (!same_version)
+ if ((version >> 16) != CORE_RPC_VERSION_MAJOR)
return Wallet::ConnectionStatus_WrongVersion;
return Wallet::ConnectionStatus_Connected;
}
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 02a46da8c..5e4a64ff8 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -64,6 +64,7 @@ public:
bool setPassword(const std::string &password);
std::string address() const;
std::string integratedAddress(const std::string &payment_id) const;
+ std::string path() const;
bool store(const std::string &path);
std::string filename() const;
std::string keysFilename() const;
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index ea3994435..a15233a87 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -2221,7 +2221,7 @@ bool wallet2::prepare_file_names(const std::string& file_path)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::check_connection(bool *same_version)
+bool wallet2::check_connection(uint32_t *version)
{
boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
@@ -2239,7 +2239,7 @@ bool wallet2::check_connection(bool *same_version)
return false;
}
- if (same_version)
+ if (version)
{
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);
@@ -2248,9 +2248,9 @@ bool wallet2::check_connection(bool *same_version)
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;
+ *version = 0;
else
- *same_version = resp_t.result.version == CORE_RPC_VERSION;
+ *version = resp_t.result.version;
}
return true;
@@ -2353,6 +2353,11 @@ void wallet2::check_genesis(const crypto::hash& genesis_hash) const {
THROW_WALLET_EXCEPTION_IF(genesis_hash != m_blockchain[0], error::wallet_internal_error, what);
}
//----------------------------------------------------------------------------------------------------
+std::string wallet2::path() const
+{
+ return m_wallet_file;
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::store()
{
store_to("", "");
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index b6d3250b2..f62a0f15b 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -332,6 +332,8 @@ namespace tools
*/
void store_to(const std::string &path, const std::string &password);
+ std::string path() const;
+
/*!
* \brief verifies given password is correct for default wallet keys file
*/
@@ -408,7 +410,7 @@ namespace tools
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, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<wallet2::pending_tx> create_transactions_from(const cryptonote::account_public_address &address, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
- bool check_connection(bool *same_version = NULL);
+ bool check_connection(uint32_t *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;
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index e624ffa69..cc6c5a337 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -195,6 +195,7 @@ struct Wallet
virtual std::string errorString() const = 0;
virtual bool setPassword(const std::string &password) = 0;
virtual std::string address() const = 0;
+ virtual std::string path() const = 0;
/*!
* \brief integratedAddress - returns integrated address for current wallet address and given payment_id.