diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-07-11 23:14:58 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-28 21:29:24 +0100 |
commit | e81a2b2cfabfb1ad9aaade752a863f1448fc89cd (patch) | |
tree | db73ec65efcabf1d6d0d9dacda8de58b325d006c /src/simplewallet/simplewallet.cpp | |
parent | tests: add basic tests for simple rct api (diff) | |
download | monero-e81a2b2cfabfb1ad9aaade752a863f1448fc89cd.tar.xz |
port get_tx_key/check_tx_key to rct
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index c8c440a04..c8fae6edd 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -58,6 +58,7 @@ #include "mnemonics/electrum-words.h" #include "rapidjson/document.h" #include "common/json_util.h" +#include "ringct/rctSigs.h" #include <stdexcept> #if defined(WIN32) @@ -2957,15 +2958,18 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_) LOCK_IDLE_SCOPE(); crypto::secret_key tx_key; - bool r = m_wallet->get_tx_key(txid, tx_key); - if (r) + std::vector<crypto::secret_key> amount_keys; + if (m_wallet->get_tx_keys(txid, tx_key, amount_keys)) { - success_msg_writer() << tr("Tx key: ") << tx_key; + std::string s = epee::string_tools::pod_to_hex(tx_key); + for (const auto &k: amount_keys) + s += epee::string_tools::pod_to_hex(k); + success_msg_writer() << tr("Tx key: ") << s; return true; } else { - fail_msg_writer() << tr("no tx key found for this txid"); + fail_msg_writer() << tr("no tx keys found for this txid"); return true; } } @@ -2992,13 +2996,22 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_) LOCK_IDLE_SCOPE(); - cryptonote::blobdata tx_key_data; - if(!epee::string_tools::parse_hexstr_to_binbuff(local_args[1], tx_key_data)) + if (local_args[1].size() < 64 || local_args[1].size() % 64) { fail_msg_writer() << tr("failed to parse tx key"); return true; } - crypto::secret_key tx_key = *reinterpret_cast<const crypto::secret_key*>(tx_key_data.data()); + std::vector<crypto::secret_key> tx_keys; + for (size_t start = 0; start < local_args[1].size(); start += 64) + { + cryptonote::blobdata tx_key_data; + if(!epee::string_tools::parse_hexstr_to_binbuff(std::string(&local_args[1][start], 64), tx_key_data)) + { + fail_msg_writer() << tr("failed to parse tx key"); + return true; + } + tx_keys.push_back(*reinterpret_cast<const crypto::secret_key*>(tx_key_data.data())); + } cryptonote::account_public_address address; bool has_payment_id; @@ -3043,12 +3056,18 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_) } crypto::key_derivation derivation; - if (!crypto::generate_key_derivation(address.m_view_public_key, tx_key, derivation)) + if (!crypto::generate_key_derivation(address.m_view_public_key, tx_keys[0], derivation)) { fail_msg_writer() << tr("failed to generate key derivation from supplied parameters"); return true; } + if (tx_keys.size() != tx.vout.size() * 2 + 1) + { + fail_msg_writer() << tr("tx keys don't match tx vout"); + return true; + } + uint64_t received = 0; try { for (size_t n = 0; n < tx.vout.size(); ++n) @@ -3059,13 +3078,33 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_) crypto::public_key pubkey; derive_public_key(derivation, n, address.m_spend_public_key, pubkey); if (pubkey == tx_out_to_key.key) - received += tx.vout[n].amount; + { + uint64_t amount; + if (tx.version == 1) + { + amount = tx.vout[n].amount; + } + else + { + try + { + rct::key Ctmp; + rct::addKeys2(Ctmp, rct::sk2rct(tx_keys[n * 2 + 2]), rct::sk2rct(tx_keys[n * 2 + 1]), rct::H); + if (rct::equalKeys(tx.rct_signatures.outPk[n].mask, Ctmp)) + amount = rct::h2d(rct::sk2rct(tx_keys[n * 2 + 1])); + else + amount = 0; + } + catch (...) { amount = 0; } + } + received += amount; + } } } - catch(...) + catch(const std::exception &e) { - LOG_ERROR("unknown error"); - fail_msg_writer() << tr("unknown error"); + LOG_ERROR("error: " << e.what()); + fail_msg_writer() << tr("error: ") << e.what(); return true; } |