JoinMarket-Org / joinmarket

CoinJoin implementation with incentive structure to convince people to take part
398 stars 119 forks source link

wallet-tool.py: Handle rescan state gracefully. #132

Open whipsch opened 9 years ago

whipsch commented 9 years ago

Enhancement/QOL: wallet-tool.py (and probably the other tools), should gracefully handle expected 'error' states, like when bitcoind is currently rescanning:

$ python wallet-tool.py wallet.json                                                                                                 
Enter wallet decryption passphrase:
[2015/07/05 14:13:01] requesting wallet history
[2015/07/05 14:13:13] rpc: ['bitcoin-cli', 'getaddressesbyaccount', 'joinmarket-wallet-...']
error: {"code":-28,"message":"Rescanning..."}
Traceback (most recent call last):
  File "wallet-tool.py", line 54, in <module>
    common.bc_interface.sync_wallet(wallet)
  File "/usr/home/btc/joinmarket/lib/blockchaininterface.py", line 31, in sync_wallet
    self.sync_addresses(wallet)
  File "/usr/home/btc/joinmarket/lib/blockchaininterface.py", line 388, in sync_addresses
    imported_addr_list = json.loads(self.rpc(['getaddressesbyaccount', wallet_name]))
  File "/usr/home/btc/joinmarket/lib/blockchaininterface.py", line 365, in rpc
    res = subprocess.check_output(self.command_params + args)
  File "/usr/local/lib/python2.7/subprocess.py", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['bitcoin-cli', 'getaddressesbyaccount', 'joinmarket-wallet-...']'
  returned non-zero exit status 28

All that really should be done is to print out a useful message to the user that bitcoind is currently still performing a rescan. There are likely some other error codes that should be handled similarly, but I'm not sure what they would be.

chris-belcher commented 9 years ago

Another option could be to sleep for a while and try again in a loop until rescan is finished.