Motivation
importprunedfunds previously only allowed importing transactions that credit the wallet (IsMine check). This prevented users from importing transactions that spend funds from the wallet if the transaction had no outputs belonging to the wallet (e.g. sending entire balance to an external address).
Users typically want to import spending transactions to correctly reflect the debit and update the balance/history in a pruned wallet.
Fixes #21647.
Solution
Updated importprunedfunds in src/wallet/rpc/backup.cpp to check pwallet->IsFromMe(*tx_ref) in addition to pwallet->IsMine(*tx_ref).
Testing
Added a regression test case in test/functional/wallet_importprunedfunds.py that:
- Funds a wallet address.
- Sends the entire balance to an external address (creating a spending transaction with no change output).
- Removes the transaction.
- Verifies that
importprunedfundscan successfully re-import this spending transaction.