diff --git a/src/UniversalIdentifier.cpp b/src/UniversalIdentifier.cpp index c998810..eecd3c7 100644 --- a/src/UniversalIdentifier.cpp +++ b/src/UniversalIdentifier.cpp @@ -278,6 +278,28 @@ Output::identify(transaction const& tx, { auto& out = identified_outputs.back(); out.subaddr_idx = *subaddr_idx; + + // now need to check if we need to expand + // list of initial 10'000 of subaddresses. + // we do this only if account id (subaddress_idx.major) + // is greater than 0. + + auto next_subaddr_acc_id + = pacc->get_next_subbaddress_acc_id(); + + auto no_of_new_accounts = std::min( + static_cast(out.subaddr_idx.major + + PrimaryAccount::SUBADDRESS_LOOKAHEAD_MAJOR) + - next_subaddr_acc_id + , 50); + + if (no_of_new_accounts > 0) + { + auto new_last_acc_id + = pacc->get_next_subbaddress_acc_id() + + no_of_new_accounts; + pacc->expand_subaddresses(new_last_acc_id); + } } total_xmr += amount; diff --git a/tests/universalidentifier_tests.cpp b/tests/universalidentifier_tests.cpp index 3dabe60..fbc4641 100644 --- a/tests/universalidentifier_tests.cpp +++ b/tests/universalidentifier_tests.cpp @@ -557,6 +557,11 @@ TEST(Subaddresses, MultiOutputTxToSubaddress) EXPECT_TRUE(result.empty()); + // check if expansion of subbaddress list worked + EXPECT_EQ(racc->get_next_subbaddress_acc_id(), + PrimaryAccount::SUBADDRESS_LOOKAHEAD_MAJOR + 49); + + EXPECT_EQ(racc->get_subaddress_map().size(), 10'000 + 49*200); } @@ -633,6 +638,9 @@ TEST(Subaddresses, GuessInputFromSubaddress) EXPECT_EQ(outputs_found[i].subaddr_idx, expected_indices[i]); } + + EXPECT_EQ(primary_account->get_next_subbaddress_acc_id(), + PrimaryAccount::SUBADDRESS_LOOKAHEAD_MAJOR); } TEST(Subaddresses, RealInputsToSubaddress)