Skip to content

Commit d5f4ae7

Browse files
committed
wallet: fully migrate address book entries for watchonly/solvable wallets
Currently `migratewallet` migrates the address book (i.e. labels and purposes) for watchonly and solvable wallets only in RAM, but doesn't persist them on disk. Fix this by adding another loop for both of the special wallet types after which writes the corresponding NAME and PURPOSE entries to the database in a single batch.
1 parent e9262ea commit d5f4ae7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,6 +4002,23 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
40024002
}
40034003
}
40044004
}
4005+
4006+
// Persist added address book entries (labels, purpose) for watchonly and solvable wallets
4007+
auto persist_address_book = [](const CWallet& wallet) {
4008+
LOCK(wallet.cs_wallet);
4009+
WalletBatch batch{wallet.GetDatabase()};
4010+
for (const auto& [destination, addr_book_data] : wallet.m_address_book) {
4011+
auto address{EncodeDestination(destination)};
4012+
auto purpose{addr_book_data.purpose};
4013+
auto label{addr_book_data.GetLabel()};
4014+
// don't bother writing default values (unknown purpose, empty label)
4015+
if (purpose != "unknown") batch.WritePurpose(address, purpose);
4016+
if (!label.empty()) batch.WriteName(address, label);
4017+
}
4018+
};
4019+
if (data.watchonly_wallet) persist_address_book(*data.watchonly_wallet);
4020+
if (data.solvable_wallet) persist_address_book(*data.solvable_wallet);
4021+
40054022
// Remove the things to delete
40064023
if (dests_to_delete.size() > 0) {
40074024
for (const auto& dest : dests_to_delete) {

0 commit comments

Comments
 (0)