From c6a70af86a4a9e6eeca340f80634c1c09b26a0eb Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 5 Mar 2019 22:31:29 +0000 Subject: [PATCH] wallet2: key image import fixes - return the right output data when offset is not zero - do not consider import failed if result height is zero (it can be 0 if unknown) - select the right tx pubkey when using subaddresses (it's faster, and we might select the wrong one if we got an output using one of the additional tx keys) - account for skipped outputs for spent/unspent balance info "spent" is arguably wrong, since it will count spent change multiple times as it goes through receive/spend cycles. --- src/simplewallet/simplewallet.cpp | 9 ++------- src/wallet/wallet2.cpp | 32 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8c0b300ad..520d6a9d9 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -8597,13 +8597,8 @@ bool simple_wallet::import_key_images(const std::vector &args) { uint64_t spent = 0, unspent = 0; uint64_t height = m_wallet->import_key_images(filename, spent, unspent); - if (height > 0) - { - success_msg_writer() << "Signed key images imported to height " << height << ", " - << print_money(spent) << " spent, " << print_money(unspent) << " unspent"; - } else { - fail_msg_writer() << "Failed to import key images"; - } + success_msg_writer() << "Signed key images imported to height " << height << ", " + << print_money(spent) << " spent, " << print_money(unspent) << " unspent"; } catch (const std::exception &e) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a476ecdc5..32365cd94 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -11002,15 +11002,6 @@ crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::walle size_t pk_index = 0; hw::device &hwdev = m_account.get_device(); - const std::vector additional_tx_pub_keys = get_additional_tx_pub_keys_from_extra(td.m_tx); - std::vector additional_derivations; - for (size_t i = 0; i < additional_tx_pub_keys.size(); ++i) - { - additional_derivations.push_back({}); - bool r = hwdev.generate_key_derivation(additional_tx_pub_keys[i], keys.m_view_secret_key, additional_derivations.back()); - THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to generate key derivation"); - } - while (find_tx_extra_field_by_type(tx_extra_fields, pub_key_field, pk_index++)) { const crypto::public_key tx_pub_key = pub_key_field.pub_key; crypto::key_derivation derivation; @@ -11020,16 +11011,15 @@ crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::walle for (size_t i = 0; i < td.m_tx.vout.size(); ++i) { tx_scan_info_t tx_scan_info; - check_acc_out_precomp(td.m_tx.vout[i], derivation, additional_derivations, i, tx_scan_info); + check_acc_out_precomp(td.m_tx.vout[i], derivation, {}, i, tx_scan_info); if (!tx_scan_info.error && tx_scan_info.received) return tx_pub_key; } } - // we found no key yielding an output - THROW_WALLET_EXCEPTION_IF(true, error::wallet_internal_error, - "Public key yielding at least one output wasn't found in the transaction extra"); - return crypto::null_pkey; + // we found no key yielding an output, but it might be in the additional + // tx pub keys only, which we do not need to check, so return the first one + return tx_pub_key; } bool wallet2::export_key_images(const std::string &filename) const @@ -11271,6 +11261,17 @@ uint64_t wallet2::import_key_images(const std::vector key_images)