aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
authorstoffu <stoffu@protonmail.ch>2018-07-29 21:29:56 +0900
committerstoffu <stoffu@protonmail.ch>2018-07-30 20:50:05 +0900
commita3fe1c56ee782caa54e3159738f19589855d504e (patch)
treef5e30d93eb8003816c45cd36546aa060f13b9eaa /src/simplewallet
parentMerge pull request #4088 (diff)
downloadmonero-a3fe1c56ee782caa54e3159738f19589855d504e.tar.xz
simplewallet: add set_tx_key for importing tx keys from 3rd party wallets
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp62
-rw-r--r--src/simplewallet/simplewallet.h1
2 files changed, 63 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 193b62571..43e8cb72f 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -2298,6 +2298,10 @@ simple_wallet::simple_wallet()
boost::bind(&simple_wallet::get_tx_key, this, _1),
tr("get_tx_key <txid>"),
tr("Get the transaction key (r) for a given <txid>."));
+ m_cmd_binder.set_handler("set_tx_key",
+ boost::bind(&simple_wallet::set_tx_key, this, _1),
+ tr("set_tx_key <txid> <tx_key>"),
+ tr("Set the transaction key (r) for a given <txid> in case the tx was made by some other device or 3rd party wallet."));
m_cmd_binder.set_handler("check_tx_key",
boost::bind(&simple_wallet::check_tx_key, this, _1),
tr("check_tx_key <txid> <txkey> <address>"),
@@ -5765,6 +5769,64 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
}
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::set_tx_key(const std::vector<std::string> &args_)
+{
+ std::vector<std::string> local_args = args_;
+
+ if(local_args.size() != 2) {
+ fail_msg_writer() << tr("usage: set_tx_key <txid> <tx_key>");
+ return true;
+ }
+
+ crypto::hash txid;
+ if (!epee::string_tools::hex_to_pod(local_args[0], txid))
+ {
+ fail_msg_writer() << tr("failed to parse txid");
+ return true;
+ }
+
+ crypto::secret_key tx_key;
+ std::vector<crypto::secret_key> additional_tx_keys;
+ try
+ {
+ if (!epee::string_tools::hex_to_pod(local_args[1].substr(0, 64), tx_key))
+ {
+ fail_msg_writer() << tr("failed to parse tx_key");
+ return true;
+ }
+ while(true)
+ {
+ local_args[1] = local_args[1].substr(64);
+ if (local_args[1].empty())
+ break;
+ additional_tx_keys.resize(additional_tx_keys.size() + 1);
+ if (!epee::string_tools::hex_to_pod(local_args[1].substr(0, 64), additional_tx_keys.back()))
+ {
+ fail_msg_writer() << tr("failed to parse tx_key");
+ return true;
+ }
+ }
+ }
+ catch (const std::out_of_range &e)
+ {
+ fail_msg_writer() << tr("failed to parse tx_key");
+ return true;
+ }
+
+ LOCK_IDLE_SCOPE();
+
+ try
+ {
+ m_wallet->set_tx_key(txid, tx_key, additional_tx_keys);
+ success_msg_writer() << tr("Tx key successfully stored.");
+ }
+ catch (const std::exception &e)
+ {
+ fail_msg_writer() << tr("Failed to store tx key: ") << e.what();
+ }
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_tx_proof(const std::vector<std::string> &args)
{
if (m_wallet->key_on_device())
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 1f2765055..e78cdcc31 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -176,6 +176,7 @@ namespace cryptonote
bool rescan_spent(const std::vector<std::string> &args);
bool set_log(const std::vector<std::string> &args);
bool get_tx_key(const std::vector<std::string> &args);
+ bool set_tx_key(const std::vector<std::string> &args);
bool check_tx_key(const std::vector<std::string> &args);
bool get_tx_proof(const std::vector<std::string> &args);
bool check_tx_proof(const std::vector<std::string> &args);