aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2024-01-08 14:41:02 +0000
committerfanquake <fanquake@gmail.com>2024-01-08 14:44:47 +0000
commitc2d04f1319a6af6140d17339c4814e0cfc605dd2 (patch)
treeafe78dcd386ab65eb41337bab8e683c55c5421d9 /src/wallet/wallet.cpp
parent04b9df0f9fd95e907b2e8bf823d63e9dfb37b4ad (diff)
parent406b71abcb72f234ddf9245a3f57e748343c774f (diff)
downloadbitcoin-c2d04f1319a6af6140d17339c4814e0cfc605dd2.tar.xz
Merge bitcoin/bitcoin#28610: wallet: Migrate entire address book entries to watchonly and solvables too
406b71abcb72f234ddf9245a3f57e748343c774f wallet: Migrate entire address book entries (Andrew Chow) Pull request description: Not all of the data in an address book entry was being copied to the watchonly and solvables wallets. This includes information such as whether the address was previously spent, and any receive requests that may exist. A test has been added to check that the previously spent information is copied, although it passes without the changes in this PR since this information is also regenerated when a transaction is loaded/added into a wallet. ACKs for top commit: ryanofsky: Code review ACK 406b71abcb72f234ddf9245a3f57e748343c774f. Just suggested change since last review furszy: Code review ACK 406b71ab Tree-SHA512: 13de42b16a1d8524fe0555764744139566b2e7d29741ceffc1158a905dd537136b762330568b3b5cac28cbee1bfd363a20de97d0a6c5296738cb3aa99133945b
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp40
1 files changed, 13 insertions, 27 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 70fb375efa..bf8cfcb082 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3989,12 +3989,8 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
if (data.watchonly_wallet) {
LOCK(data.watchonly_wallet->cs_wallet);
if (data.watchonly_wallet->IsMine(addr_pair.first)) {
- // Add to the watchonly. Preserve the labels, purpose, and change-ness
- std::string label = addr_pair.second.GetLabel();
- data.watchonly_wallet->m_address_book[addr_pair.first].purpose = addr_pair.second.purpose;
- if (!addr_pair.second.IsChange()) {
- data.watchonly_wallet->m_address_book[addr_pair.first].SetLabel(label);
- }
+ // Add to the watchonly. Copy the entire address book entry
+ data.watchonly_wallet->m_address_book[addr_pair.first] = addr_pair.second;
dests_to_delete.push_back(addr_pair.first);
continue;
}
@@ -4002,12 +3998,8 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
if (data.solvable_wallet) {
LOCK(data.solvable_wallet->cs_wallet);
if (data.solvable_wallet->IsMine(addr_pair.first)) {
- // Add to the solvable. Preserve the labels, purpose, and change-ness
- std::string label = addr_pair.second.GetLabel();
- data.solvable_wallet->m_address_book[addr_pair.first].purpose = addr_pair.second.purpose;
- if (!addr_pair.second.IsChange()) {
- data.solvable_wallet->m_address_book[addr_pair.first].SetLabel(label);
- }
+ // Add to the solvable. Copy the entire address book entry
+ data.solvable_wallet->m_address_book[addr_pair.first] = addr_pair.second;
dests_to_delete.push_back(addr_pair.first);
continue;
}
@@ -4027,21 +4019,13 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
// Labels for everything else ("send") should be cloned to all
if (data.watchonly_wallet) {
LOCK(data.watchonly_wallet->cs_wallet);
- // Add to the watchonly. Preserve the labels, purpose, and change-ness
- std::string label = addr_pair.second.GetLabel();
- data.watchonly_wallet->m_address_book[addr_pair.first].purpose = addr_pair.second.purpose;
- if (!addr_pair.second.IsChange()) {
- data.watchonly_wallet->m_address_book[addr_pair.first].SetLabel(label);
- }
+ // Add to the watchonly. Copy the entire address book entry
+ data.watchonly_wallet->m_address_book[addr_pair.first] = addr_pair.second;
}
if (data.solvable_wallet) {
LOCK(data.solvable_wallet->cs_wallet);
- // Add to the solvable. Preserve the labels, purpose, and change-ness
- std::string label = addr_pair.second.GetLabel();
- data.solvable_wallet->m_address_book[addr_pair.first].purpose = addr_pair.second.purpose;
- if (!addr_pair.second.IsChange()) {
- data.solvable_wallet->m_address_book[addr_pair.first].SetLabel(label);
- }
+ // Add to the solvable. Copy the entire address book entry
+ data.solvable_wallet->m_address_book[addr_pair.first] = addr_pair.second;
}
}
}
@@ -4052,10 +4036,12 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
WalletBatch batch{wallet.GetDatabase()};
for (const auto& [destination, addr_book_data] : wallet.m_address_book) {
auto address{EncodeDestination(destination)};
- std::optional<std::string> label = addr_book_data.IsChange() ? std::nullopt : std::make_optional(addr_book_data.GetLabel());
- // don't bother writing default values (unknown purpose)
if (addr_book_data.purpose) batch.WritePurpose(address, PurposeToString(*addr_book_data.purpose));
- if (label) batch.WriteName(address, *label);
+ if (addr_book_data.label) batch.WriteName(address, *addr_book_data.label);
+ for (const auto& [id, request] : addr_book_data.receive_requests) {
+ batch.WriteAddressReceiveRequest(destination, id, request);
+ }
+ if (addr_book_data.previously_spent) batch.WriteAddressPreviouslySpent(destination, true);
}
};
if (data.watchonly_wallet) persist_address_book(*data.watchonly_wallet);