Skip to content

Commit a44a215

Browse files
author
Pedro Branco
committed
Fix importmulti bug when importing an already imported key
1 parent 364da2c commit a44a215

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/wallet/rpcdump.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
961961
pwallet->SetAddressBook(vchAddress, label, "receive");
962962

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

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

test/functional/importmulti.py

+12
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ def run_test (self):
160160
assert_equal(address_assert['ismine'], True)
161161
assert_equal(address_assert['timestamp'], timestamp)
162162

163+
self.log.info("Should not import an address with private key if is already imported")
164+
result = self.nodes[1].importmulti([{
165+
"scriptPubKey": {
166+
"address": address['address']
167+
},
168+
"timestamp": "now",
169+
"keys": [ self.nodes[0].dumpprivkey(address['address']) ]
170+
}])
171+
assert_equal(result[0]['success'], False)
172+
assert_equal(result[0]['error']['code'], -4)
173+
assert_equal(result[0]['error']['message'], 'The wallet already contains the private key for this address or script')
174+
163175
# Address + Private key + watchonly
164176
self.log.info("Should not import an address with private key and with watchonly")
165177
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())

0 commit comments

Comments
 (0)