Automatically add labels to detected receiving addresses

pull/22929/head
S3RK 3 years ago
parent c1b99c088c
commit 9f3a622b1c

@ -1062,8 +1062,23 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, CWalletTx::Co
// loop though all outputs // loop though all outputs
for (const CTxOut& txout: tx.vout) { for (const CTxOut& txout: tx.vout) {
for (const auto& spk_man_pair : m_spk_managers) { for (const auto& spk_man : GetScriptPubKeyMans(txout.scriptPubKey)) {
spk_man_pair.second->MarkUnusedAddresses(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");
}
}
} }
} }

Loading…
Cancel
Save