Skip to content

Commit 20cdc2b

Browse files
Pedro BrancoMarcoFalke
authored andcommitted
Fix importmulti bug when importing an already imported key
Github-Pull: #11483 Rebased-From: a44a215
1 parent 405e069 commit 20cdc2b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
960960
pwallet->SetAddressBook(vchAddress, label, "receive");
961961

962962
if (pwallet->HaveKey(vchAddress)) {
963-
return false;
963+
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
964964
}
965965

966966
pwallet->mapKeyMetadata[vchAddress].nCreateTime = timestamp;

test/functional/importmulti.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ def run_test (self):
170170
assert_equal(address_assert['ismine'], True)
171171
assert_equal(address_assert['timestamp'], timestamp)
172172

173+
self.log.info("Should not import an address with private key if is already imported")
174+
result = self.nodes[1].importmulti([{
175+
"scriptPubKey": {
176+
"address": address['address']
177+
},
178+
"timestamp": "now",
179+
"keys": [ self.nodes[0].dumpprivkey(address['address']) ]
180+
}])
181+
assert_equal(result[0]['success'], False)
182+
assert_equal(result[0]['error']['code'], -4)
183+
assert_equal(result[0]['error']['message'], 'The wallet already contains the private key for this address or script')
184+
173185
# Address + Private key + watchonly
174186
self.log.info("Should not import an address with private key and with watchonly")
175187
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())

0 commit comments

Comments
 (0)