aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorS3RK <1466284+S3RK@users.noreply.github.com>2021-09-09 08:31:47 +0200
committerS3RK <1466284+S3RK@users.noreply.github.com>2021-10-06 10:01:48 +0200
commit9f3a622b1cea37e452560f2f82d8e82d3b48a73a (patch)
treeb8baef26ffba8298f823525f009b2eecc307a0dd /src/wallet
parentc1b99c088c54eb101c0a28a67237965576ccf5ad (diff)
downloadbitcoin-9f3a622b1cea37e452560f2f82d8e82d3b48a73a.tar.xz
Automatically add labels to detected receiving addresses
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index c67a8f77da..0418cf4c9b 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1062,8 +1062,23 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, CWalletTx::Co
// loop though all outputs
for (const CTxOut& txout: tx.vout) {
- for (const auto& spk_man_pair : m_spk_managers) {
- spk_man_pair.second->MarkUnusedAddresses(txout.scriptPubKey);
+ for (const auto& spk_man : GetScriptPubKeyMans(txout.scriptPubKey)) {
+ for (auto &dest : spk_man->MarkUnusedAddresses(txout.scriptPubKey)) {
+ // If internal flag is not defined try to infer it from the ScriptPubKeyMan
+ if (!dest.internal.has_value()) {
+ dest.internal = IsInternalScriptPubKeyMan(spk_man);
+ }
+
+ // skip if can't determine whether it's a receiving address or not
+ if (!dest.internal.has_value()) continue;
+
+ // If this is a receiving address and it's not in the address book yet
+ // (e.g. it wasn't generated on this node or we're restoring from backup)
+ // add it to the address book for proper transaction accounting
+ if (!*dest.internal && !FindAddressBookEntry(dest.dest, /* allow_change= */ false)) {
+ SetAddressBook(dest.dest, "", "receive");
+ }
+ }
}
}