From 20e8bf6c92cee6932cb0c18f705b7d28c3935f46 Mon Sep 17 00:00:00 2001 From: AdamISZ Date: Thu, 12 Apr 2018 17:22:13 +0200 Subject: [PATCH] Give user feedback when importaddress fails due to conflict with Core wallet. This fails (sys.exit) when importaddress throws the error corresponding to Core wallet already owning the key corresponding to an address, and gives brief advice how the error can be fixed. It is not considered safe to simply ignore this error in case address reuse or coins being sent to an address the user doesn't control, occurs. --- jmclient/jmclient/blockchaininterface.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index 2040599..510d791 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -350,7 +350,19 @@ class BitcoinCoreInterface(BlockchainInterface): log.debug('importing ' + str(len(addr_list)) + ' addresses into account ' + wallet_name) for addr in addr_list: - self.rpc('importaddress', [addr, wallet_name, False]) + try: + self.rpc('importaddress', [addr, wallet_name, False]) + except JsonRpcError as e: + if e.code == -4 and e.message == "The wallet already " + \ + "contains the private key for this address or script": + log.warn("Fatal sync error: import of address: " + addr + + " failed, since it's already owned by this Bitcoin Core " + "wallet in another account. To prevent coin or privacy " + "loss, Joinmarket will not load a wallet in this conflicted " + "state. To fix: use a new Bitcoin Core wallet to sync this " + "Joinmarket wallet, or use a new Joinmarket wallet.") + sys.exit(1) + raise def add_watchonly_addresses(self, addr_list, wallet_name, restart_cb=None): """For backwards compatibility, this fn name is preserved