Skip to content

Commit 3d857f3

Browse files
committed
Merge #9818: Save watch only key timestamps when reimporting keys
7759aa2 Save watch only key timestamps when reimporting keys (Russell Yanofsky) Tree-SHA512: 433b5a78e5626fb2f3166e6c84c22eabd5239d451dc82694da95af237e034612a24f1a8bc959b7d2f2e576ce0b679be1fa4af929ebfae758c7e832056ab67061
2 parents 9c7b7cf + 7759aa2 commit 3d857f3

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

qa/rpc-tests/importmulti.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def run_test (self):
314314
self.nodes[1].generate(100)
315315
transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)
316316
self.nodes[1].generate(1)
317+
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
317318
transaction = self.nodes[1].gettransaction(transactionid)
318319

319320
self.log.info("Should import a p2sh with respective redeem script and private keys")
@@ -409,6 +410,24 @@ def run_test (self):
409410
assert_equal(address_assert['ismine'], False)
410411
assert_equal('timestamp' in address_assert, False)
411412

413+
414+
# Importing existing watch only address with new timestamp should replace saved timestamp.
415+
assert_greater_than(timestamp, watchonly_timestamp)
416+
print("Should replace previously saved watch only timestamp.")
417+
result = self.nodes[1].importmulti([{
418+
"scriptPubKey": {
419+
"address": watchonly_address,
420+
},
421+
"timestamp": "now",
422+
}])
423+
assert_equal(result[0]['success'], True)
424+
address_assert = self.nodes[1].validateaddress(watchonly_address)
425+
assert_equal(address_assert['iswatchonly'], True)
426+
assert_equal(address_assert['ismine'], False)
427+
assert_equal(address_assert['timestamp'], timestamp)
428+
watchonly_timestamp = timestamp
429+
430+
412431
# restart nodes to check for proper serialization/deserialization of watch only address
413432
stop_nodes(self.nodes)
414433
self.nodes = start_nodes(2, self.options.tmpdir)

src/wallet/rpcdump.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
743743

744744
pwallet->MarkDirty();
745745

746-
if (!pwallet->HaveWatchOnly(redeemScript) && !pwallet->AddWatchOnly(redeemScript, timestamp)) {
746+
if (!pwallet->AddWatchOnly(redeemScript, timestamp)) {
747747
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
748748
}
749749

@@ -760,7 +760,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
760760

761761
pwallet->MarkDirty();
762762

763-
if (!pwallet->HaveWatchOnly(redeemDestination) && !pwallet->AddWatchOnly(redeemDestination, timestamp)) {
763+
if (!pwallet->AddWatchOnly(redeemDestination, timestamp)) {
764764
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
765765
}
766766

@@ -853,7 +853,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
853853

854854
pwallet->MarkDirty();
855855

856-
if (!pwallet->HaveWatchOnly(pubKeyScript) && !pwallet->AddWatchOnly(pubKeyScript, timestamp)) {
856+
if (!pwallet->AddWatchOnly(pubKeyScript, timestamp)) {
857857
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
858858
}
859859

@@ -871,7 +871,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
871871

872872
pwallet->MarkDirty();
873873

874-
if (!pwallet->HaveWatchOnly(scriptRawPubKey) && !pwallet->AddWatchOnly(scriptRawPubKey, timestamp)) {
874+
if (!pwallet->AddWatchOnly(scriptRawPubKey, timestamp)) {
875875
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
876876
}
877877

@@ -945,7 +945,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
945945

946946
pwallet->MarkDirty();
947947

948-
if (!pwallet->HaveWatchOnly(script) && !pwallet->AddWatchOnly(script, timestamp)) {
948+
if (!pwallet->AddWatchOnly(script, timestamp)) {
949949
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
950950
}
951951

0 commit comments

Comments
 (0)