From e3a03e9d987b7c33941e8e89abae68b49f89731e Mon Sep 17 00:00:00 2001 From: akildemir Date: Mon, 14 Jul 2025 10:43:41 +0300 Subject: [PATCH] add carrot subaddress derive type when inserting new subaddresses --- src/carrot_impl/account.cpp | 6 ++---- src/carrot_impl/account.h | 2 +- src/wallet/wallet2.cpp | 22 +++++++++++++++++++--- src/wallet/wallet2.h | 3 +++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/carrot_impl/account.cpp b/src/carrot_impl/account.cpp index f19d88d71..57593b07f 100644 --- a/src/carrot_impl/account.cpp +++ b/src/carrot_impl/account.cpp @@ -336,12 +336,10 @@ void carrot_and_legacy_account::set_carrot_keys(const AddressDeriveType default_ generate_subaddress_map(); } //---------------------------------------------------------------------------------------------------------------------- -void carrot_and_legacy_account::insert_subaddresses(const std::unordered_map& subaddress_map_cn) +void carrot_and_legacy_account::insert_subaddresses(const std::unordered_map& subaddress_map_cn) { - // if AddressDeriveType::Auto causing a problem, this function can take it as a parameter, you then have to update - // all inserts to `subaddress_map`, and only use this function to insert into it with appropriate derive type. for (const auto &p : subaddress_map_cn) - subaddress_map.insert({p.first, {{p.second.major, p.second.minor}, AddressDeriveType::Auto}}); + subaddress_map.insert({p.first, {{p.second.index.major, p.second.index.minor}, p.second.derive_type}}); } //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/carrot_impl/account.h b/src/carrot_impl/account.h index 74a317079..b864b0140 100644 --- a/src/carrot_impl/account.h +++ b/src/carrot_impl/account.h @@ -107,7 +107,7 @@ namespace carrot ); void set_carrot_keys(const AddressDeriveType default_derive_type = AddressDeriveType::Carrot); - void insert_subaddresses(const std::unordered_map& subaddress_map); + void insert_subaddresses(const std::unordered_map& subaddress_map); AddressDeriveType resolve_derive_type(const AddressDeriveType derive_type) const; }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index fd3e4c6ac..c3adc024a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2841,10 +2841,17 @@ void wallet2::process_new_scanned_transaction( // from protocol or return txs for (const auto entry: tx_amounts_individual_outs[i->first]) { const crypto::public_key &onetime_address = std::get<1>(entry); - m_account.insert_subaddresses({{onetime_address, {i->first.major, i->first.minor}}}); + carrot::AddressDeriveType derive_type; + if (use_fork_rules(HF_VERSION_CARROT, 0)) { + derive_type = carrot::AddressDeriveType::Carrot; + } else { + derive_type = carrot::AddressDeriveType::PreCarrot; + } + const carrot::subaddress_index_extended subaddr_ext = {i->first.major, i->first.minor, derive_type}; + m_account.insert_subaddresses({{onetime_address, subaddr_ext}}); // save to m_subaddresses as well, so that we can populate account subaddress map // when we open the wallet first time. - m_subaddresses[onetime_address] = i->first; + m_subaddresses_extended[onetime_address] = subaddr_ext; // update m_salvium_txs m_salvium_txs.insert({onetime_address, m_transfers.size()-1}); @@ -6574,7 +6581,16 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass if (get_num_subaddress_accounts() == 0) add_subaddress_account(tr("Primary account")); - m_account.insert_subaddresses(m_subaddresses); + m_account.insert_subaddresses(m_subaddresses_extended); + if (!m_subaddresses.empty()) + { + // if we have subaddresses, we need to insert them into the account + for (const auto &subaddress : m_subaddresses) + m_account.insert_subaddresses( + {{subaddress.first, {{subaddress.second.major, subaddress.second.minor}, carrot::AddressDeriveType::PreCarrot}}} + ); + } + try { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 55ce376c7..398de5934 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1402,6 +1402,7 @@ private: if (ver < 20) return; a & m_subaddresses.parent(); + a & m_subaddresses_extended.parent(); std::unordered_map dummy_subaddresses_inv; a & dummy_subaddresses_inv; a & m_subaddress_labels; @@ -1468,6 +1469,7 @@ private: FIELD(m_scanned_pool_txs[0]) FIELD(m_scanned_pool_txs[1]) FIELD(m_subaddresses) + FIELD(m_subaddresses_extended) FIELD(m_subaddress_labels) FIELD(m_additional_tx_keys) FIELD(m_attributes) @@ -2130,6 +2132,7 @@ private: serializable_unordered_map m_pub_keys; cryptonote::account_public_address m_account_public_address; serializable_unordered_map m_subaddresses; + serializable_unordered_map m_subaddresses_extended; std::vector> m_subaddress_labels; serializable_unordered_map m_tx_notes; serializable_unordered_map m_attributes;