aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2.cpp
diff options
context:
space:
mode:
authorbenevanoff <benjaminevanoff99@gmail.com>2023-11-03 13:07:17 -0500
committernahuhh <50635951+nahuhh@users.noreply.github.com>2025-07-03 16:10:29 +0000
commit8f5a7b0f1a0c2954a249318cf2f3760096991b67 (patch)
tree9c00f654bebbe8ced6297f32deebccc96c02a849 /src/wallet/wallet2.cpp
parentdf765433699ee53f4ee0fef1b3991ab14e9f2267 (diff)
downloadmonzero-core-8f5a7b0f1a0c2954a249318cf2f3760096991b67.tar.gz
monzero-core-8f5a7b0f1a0c2954a249318cf2f3760096991b67.tar.xz
monzero-core-8f5a7b0f1a0c2954a249318cf2f3760096991b67.zip
wallet: ensure subaddress keys table is at least size of requested lookahead
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r--src/wallet/wallet2.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 65ec6fd7c..808a6fdc2 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1964,6 +1964,25 @@ void wallet2::set_subaddress_lookahead(size_t major, size_t minor)
THROW_WALLET_EXCEPTION_IF(major > 0xffffffff, error::wallet_internal_error, "Subaddress major lookahead is too large");
THROW_WALLET_EXCEPTION_IF(minor == 0, error::wallet_internal_error, "Subaddress minor lookahead may not be zero");
THROW_WALLET_EXCEPTION_IF(minor > 0xffffffff, error::wallet_internal_error, "Subaddress minor lookahead is too large");
+
+ if (major > m_subaddress_lookahead_major) { // if increasing the lookahead
+ // then generate new subaddress pubkeys and add them to m_subaddresses table
+ for (uint32_t i = m_subaddress_labels.size()+m_subaddress_lookahead_major; i < m_subaddress_labels.size()+major; i++) { // m_subaddress_labels are the accounts the user is conciously keeping track of. We want that number plus the lookahead major accounts in our key table
+ for (uint32_t j = 0; j < minor; j++) { // these are newly made accounts, minor index will start from zero
+ cryptonote::subaddress_index idx = {i,j};
+ create_one_off_subaddress(idx); // then generate the key and add it to the table
+ }
+ }
+ }
+ if (minor > m_subaddress_lookahead_minor) { // if increasing the minor lookahead we need to also go back and expand the existing accounts
+ for (uint32_t i = 0; i < m_subaddress_labels.size()+m_subaddress_lookahead_major; i++) {
+ uint32_t minor_idx_start = i < m_subaddress_labels.size() ? m_subaddress_labels[i].size()+m_subaddress_lookahead_minor : m_subaddress_lookahead_minor; // if there are existing minor indices being tracked under this account we need to account for that
+ for (uint32_t j = minor_idx_start; j < minor; j++) {
+ cryptonote::subaddress_index idx = {i,j};
+ create_one_off_subaddress(idx);
+ }
+ }
+ }
m_subaddress_lookahead_major = major;
m_subaddress_lookahead_minor = minor;
}