Skip to content

Commit 3abdbbb

Browse files
promagfjahr
andcommitted
rpc, wallet: Document and test mempool scan after importaddress
co-authored-by: Fabian Jahr <[email protected]>
1 parent 236239b commit 3abdbbb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ RPCHelpMan importaddress()
201201
"\nAdds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.\n"
202202
"\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
203203
"may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
204+
"The rescan parameter can be set to false if the key was never used to create transactions. If it is set to false,\n"
205+
"but the key was used to create transactions, rescanwallet needs to be called with the appropriate block range.\n"
204206
"If you have the full public key, you should call importpubkey instead of this.\n"
205207
"Hint: use importmulti to import more than one address.\n"
206208
"\nNote: If you import a non-standard raw script in hex form, outputs sending to it will be treated\n"
@@ -209,7 +211,7 @@ RPCHelpMan importaddress()
209211
{
210212
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The Bitcoin address (or hex-encoded script)"},
211213
{"label", RPCArg::Type::STR, RPCArg::Default{""}, "An optional label"},
212-
{"rescan", RPCArg::Type::BOOL, RPCArg::Default{true}, "Rescan the wallet for transactions"},
214+
{"rescan", RPCArg::Type::BOOL, RPCArg::Default{true}, "Scan the chain and mempool for wallet transactions."},
213215
{"p2sh", RPCArg::Type::BOOL, RPCArg::Default{false}, "Add the P2SH version of the script as well"},
214216
},
215217
RPCResult{RPCResult::Type::NONE, "", ""},

test/functional/wallet_balance.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ def test_balances(*, fee_node_1=0):
273273
self.generatetoaddress(self.nodes[1], 1, ADDRESS_WATCHONLY)
274274
assert_equal(self.nodes[0].getbalance(minconf=0), total_amount + 1) # The reorg recovered our fee of 1 coin
275275

276+
if not self.options.descriptors:
277+
self.log.info('Check if mempool is taken into account after import*')
278+
address = self.nodes[0].getnewaddress()
279+
privkey = self.nodes[0].dumpprivkey(address)
280+
self.nodes[0].sendtoaddress(address, 0.1)
281+
self.nodes[0].unloadwallet('')
282+
# check importaddress on fresh wallet
283+
self.nodes[0].createwallet('w1', False, True)
284+
self.nodes[0].importaddress(address)
285+
assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], 0)
286+
assert_equal(self.nodes[0].getbalances()['watchonly']['untrusted_pending'], Decimal('0.1'))
287+
self.nodes[0].importprivkey(privkey)
288+
assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], Decimal('0.1'))
289+
assert_equal(self.nodes[0].getbalances()['watchonly']['untrusted_pending'], 0)
290+
self.nodes[0].unloadwallet('w1')
291+
276292

277293
if __name__ == '__main__':
278294
WalletTest().main()

0 commit comments

Comments
 (0)