Fixes #16159.
listreceivedbyaddress/listreceivedbylabel with include_empty=true walk the entire address book and return every entry that has no matching mapTally record — including addresses with a "send" purpose (foreign addresses that got a label via setlabel, the GUI, or addmultisigaddress) that this wallet never received funds to and doesn't own.
This excludes those via IsMine() rather than the address book's purpose field, since purpose is set inconsistently across several code paths and IsMine() is the same check mapTally itself is already built from.
Picks up prior work by kouloumos in #25973 and BrandonOdiwuor in #30972, both closed for inactivity:
- #25973 filtered on
purpose == "send"directly. ryanofsky pointed out purpose "is set pretty haphazardly in code" and suggestedIsMine()instead. - #30972 implemented that, then furszy pointed out
IsMine()only needs to run for addresses missing frommapTally, not every one. rkrux further suggested dropping the redundant re-lock in favor ofEXCLUSIVE_LOCKS_REQUIREDdirectly on the lambda — matching the existing pattern inwallet/interfaces.cpp— and simplifying the branching.
This PR carries that final approach forward on current master. The regression test is a small, standalone addition rather than reviving the test-file "split into subtests" refactor from the earlier PRs, which achow101 flagged on #30972 as unrelated stylistic churn.