aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp100
-rw-r--r--src/simplewallet/simplewallet.h5
2 files changed, 96 insertions, 9 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 4a7a70b8c..2bcd8ae4c 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -115,6 +115,7 @@ namespace
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false};
const command_line::arg_descriptor<bool> arg_trusted_daemon = {"trusted-daemon", sw::tr("Enable commands which rely on a trusted daemon"), false};
+ const command_line::arg_descriptor<bool> arg_allow_mismatched_daemon_version = {"allow-mismatched-daemon-version", sw::tr("Allow communicating with a daemon that uses a different RPC version"), false};
const command_line::arg_descriptor<uint64_t> arg_restore_height = {"restore-height", sw::tr("Restore from specific blockchain height"), 0};
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
@@ -623,7 +624,8 @@ bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<st
}
simple_wallet::simple_wallet()
- : m_daemon_port(0)
+ : m_allow_mismatched_daemon_version(false)
+ , m_daemon_port(0)
, m_refresh_progress_reporter(*this)
, m_auto_refresh_run(false)
, m_auto_refresh_refreshing(false)
@@ -658,6 +660,8 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("set_tx_note", boost::bind(&simple_wallet::set_tx_note, this, _1), tr("Set an arbitrary string note for a txid"));
m_cmd_binder.set_handler("get_tx_note", boost::bind(&simple_wallet::get_tx_note, this, _1), tr("Get a string note for a txid"));
m_cmd_binder.set_handler("status", boost::bind(&simple_wallet::status, this, _1), tr("Show wallet status information"));
+ m_cmd_binder.set_handler("sign", boost::bind(&simple_wallet::sign, this, _1), tr("Sign the contents of a file"));
+ m_cmd_binder.set_handler("verify", boost::bind(&simple_wallet::verify, this, _1), tr("Verify a signature on the contents of a file"));
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), tr("Show this help"));
}
//----------------------------------------------------------------------------------------------------
@@ -1439,18 +1443,28 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_restore_deterministic_wallet = command_line::get_arg(vm, arg_restore_deterministic_wallet);
m_non_deterministic = command_line::get_arg(vm, arg_non_deterministic);
m_trusted_daemon = command_line::get_arg(vm, arg_trusted_daemon);
+ m_allow_mismatched_daemon_version = command_line::get_arg(vm, arg_allow_mismatched_daemon_version);
m_restore_height = command_line::get_arg(vm, arg_restore_height);
return true;
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::try_connect_to_daemon()
+bool simple_wallet::try_connect_to_daemon(bool silent)
{
- if (!m_wallet->check_connection())
+ bool same_version = false;
+ if (!m_wallet->check_connection(&same_version))
{
- fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_daemon_address << ". " <<
- tr("Daemon either is not started or wrong port was passed. "
- "Please make sure daemon is running or restart the wallet with the correct daemon address.");
+ if (!silent)
+ fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_daemon_address << ". " <<
+ tr("Daemon either is not started or wrong port was passed. "
+ "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 (!silent)
+ fail_msg_writer() << tr("Daemon uses a different RPC version that the wallet: ") << m_daemon_address << ". " <<
+ tr("Either update one of them, or use --allow-mismatched-daemon-version.");
return false;
}
return true;
@@ -3207,7 +3221,8 @@ void simple_wallet::wallet_refresh_thread()
try
{
uint64_t fetched_blocks;
- m_wallet->refresh(0, fetched_blocks);
+ if (try_connect_to_daemon(true))
+ m_wallet->refresh(0, fetched_blocks);
}
catch(...) {}
m_auto_refresh_refreshing = false;
@@ -3219,6 +3234,9 @@ void simple_wallet::wallet_refresh_thread()
//----------------------------------------------------------------------------------------------------
bool simple_wallet::run()
{
+ // check and display warning, but go on anyway
+ try_connect_to_daemon();
+
std::string addr_start = m_wallet->get_account().get_public_address_str(m_wallet->testnet()).substr(0, 6);
m_auto_refresh_run = m_wallet->auto_refresh();
if (m_auto_refresh_run)
@@ -3348,7 +3366,7 @@ 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 (!m_wallet->check_connection())
+ if (!try_connect_to_daemon())
{
success_msg_writer() << "Refreshed " << local_height << "/?, no daemon connected";
return true;
@@ -3368,6 +3386,71 @@ bool simple_wallet::status(const std::vector<std::string> &args)
return true;
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::sign(const std::vector<std::string> &args)
+{
+ if (args.size() != 1)
+ {
+ fail_msg_writer() << tr("usage: sign <filename>");
+ return true;
+ }
+ if (m_wallet->watch_only())
+ {
+ fail_msg_writer() << tr("wallet is watch-only and cannot sign");
+ return true;
+ }
+ std::string filename = args[0];
+ std::string data;
+ bool r = epee::file_io_utils::load_file_to_string(filename, data);
+ if (!r)
+ {
+ fail_msg_writer() << tr("failed to read file ") << filename;
+ return true;
+ }
+ std::string signature = m_wallet->sign(data);
+ success_msg_writer() << signature;
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
+bool simple_wallet::verify(const std::vector<std::string> &args)
+{
+ if (args.size() != 3)
+ {
+ fail_msg_writer() << tr("usage: verify <filename> <address> <signature>");
+ return true;
+ }
+ std::string filename = args[0];
+ std::string address_string = args[1];
+ std::string signature= args[2];
+
+ std::string data;
+ bool r = epee::file_io_utils::load_file_to_string(filename, data);
+ if (!r)
+ {
+ fail_msg_writer() << tr("failed to read file ") << filename;
+ return true;
+ }
+
+ cryptonote::account_public_address address;
+ bool has_payment_id;
+ crypto::hash8 payment_id;
+ if(!get_account_integrated_address_from_str(address, has_payment_id, payment_id, m_wallet->testnet(), address_string))
+ {
+ fail_msg_writer() << tr("failed to parse address");
+ return true;
+ }
+
+ r = m_wallet->verify(data, address, signature);
+ if (!r)
+ {
+ fail_msg_writer() << tr("Bad signature from ") << address_string;
+ }
+ else
+ {
+ success_msg_writer() << tr("Good signature from ") << address_string;
+ }
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::process_command(const std::vector<std::string> &args)
{
return m_cmd_binder.process_command_vec(args);
@@ -3444,6 +3527,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_testnet);
command_line::add_arg(desc_params, arg_restricted);
command_line::add_arg(desc_params, arg_trusted_daemon);
+ command_line::add_arg(desc_params, arg_allow_mismatched_daemon_version);
command_line::add_arg(desc_params, arg_restore_height);
tools::wallet_rpc_server::init_options(desc_params);
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index e0478eb6e..7d8e7730c 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -143,9 +143,11 @@ namespace cryptonote
bool get_tx_note(const std::vector<std::string> &args);
bool status(const std::vector<std::string> &args);
bool set_default_fee_multiplier(const std::vector<std::string> &args);
+ bool sign(const std::vector<std::string> &args);
+ bool verify(const std::vector<std::string> &args);
uint64_t get_daemon_blockchain_height(std::string& err);
- bool try_connect_to_daemon();
+ bool try_connect_to_daemon(bool silent = false);
bool ask_wallet_create_if_needed();
bool get_address_from_str(const std::string &str, cryptonote::account_public_address &address, bool &has_payment_id, crypto::hash8 &payment_id);
@@ -238,6 +240,7 @@ namespace cryptonote
bool m_restore_deterministic_wallet; // recover flag
bool m_non_deterministic; // old 2-random generation
bool m_trusted_daemon;
+ bool m_allow_mismatched_daemon_version;
uint64_t m_restore_height; // optional
std::string m_daemon_address;