mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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.
This commit is contained in:
parent
e9262ea32a
commit
d5f4ae7fac
1 changed files with 17 additions and 0 deletions
|
@ -4002,6 +4002,23 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Persist added address book entries (labels, purpose) for watchonly and solvable wallets
|
||||
auto persist_address_book = [](const CWallet& wallet) {
|
||||
LOCK(wallet.cs_wallet);
|
||||
WalletBatch batch{wallet.GetDatabase()};
|
||||
for (const auto& [destination, addr_book_data] : wallet.m_address_book) {
|
||||
auto address{EncodeDestination(destination)};
|
||||
auto purpose{addr_book_data.purpose};
|
||||
auto label{addr_book_data.GetLabel()};
|
||||
// don't bother writing default values (unknown purpose, empty label)
|
||||
if (purpose != "unknown") batch.WritePurpose(address, purpose);
|
||||
if (!label.empty()) batch.WriteName(address, label);
|
||||
}
|
||||
};
|
||||
if (data.watchonly_wallet) persist_address_book(*data.watchonly_wallet);
|
||||
if (data.solvable_wallet) persist_address_book(*data.solvable_wallet);
|
||||
|
||||
// Remove the things to delete
|
||||
if (dests_to_delete.size() > 0) {
|
||||
for (const auto& dest : dests_to_delete) {
|
||||
|
|
Loading…
Add table
Reference in a new issue