Skip to content

Commit 9f3a622

Browse files
committed
Automatically add labels to detected receiving addresses
1 parent c1b99c0 commit 9f3a622

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,23 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, CWalletTx::Co
10621062

10631063
// loop though all outputs
10641064
for (const CTxOut& txout: tx.vout) {
1065-
for (const auto& spk_man_pair : m_spk_managers) {
1066-
spk_man_pair.second->MarkUnusedAddresses(txout.scriptPubKey);
1065+
for (const auto& spk_man : GetScriptPubKeyMans(txout.scriptPubKey)) {
1066+
for (auto &dest : spk_man->MarkUnusedAddresses(txout.scriptPubKey)) {
1067+
// If internal flag is not defined try to infer it from the ScriptPubKeyMan
1068+
if (!dest.internal.has_value()) {
1069+
dest.internal = IsInternalScriptPubKeyMan(spk_man);
1070+
}
1071+
1072+
// skip if can't determine whether it's a receiving address or not
1073+
if (!dest.internal.has_value()) continue;
1074+
1075+
// If this is a receiving address and it's not in the address book yet
1076+
// (e.g. it wasn't generated on this node or we're restoring from backup)
1077+
// add it to the address book for proper transaction accounting
1078+
if (!*dest.internal && !FindAddressBookEntry(dest.dest, /* allow_change= */ false)) {
1079+
SetAddressBook(dest.dest, "", "receive");
1080+
}
1081+
}
10671082
}
10681083
}
10691084

0 commit comments

Comments
 (0)