diff --git a/joinmarket/blockchaininterface.py b/joinmarket/blockchaininterface.py index 1b175533..d8dc732a 100644 --- a/joinmarket/blockchaininterface.py +++ b/joinmarket/blockchaininterface.py @@ -2,6 +2,7 @@ import BaseHTTPServer import abc +import ast import json import os import pprint @@ -613,7 +614,13 @@ def sync_unspent(self, wallet): st = time.time() wallet_name = self.get_wallet_name(wallet) wallet.unspent = {} - unspent_list = self.rpc('listunspent', []) + + listunspent_args = [] + if 'listunspent_args' in jm_single().config.options('POLICY'): + listunspent_args = ast.literal_eval( + jm_single().config.get('POLICY', 'listunspent_args')) + + unspent_list = self.rpc('listunspent', listunspent_args) for u in unspent_list: if 'account' not in u: continue @@ -621,11 +628,9 @@ def sync_unspent(self, wallet): continue if u['address'] not in wallet.addr_cache: continue - wallet.unspent[u['txid'] + ':' + str(u[ - 'vout'])] = { + wallet.unspent[u['txid'] + ':' + str(u['vout'])] = { 'address': u['address'], - 'value': - int(Decimal(str(u['amount'])) * Decimal('1e8'))} + 'value': int(Decimal(str(u['amount'])) * Decimal('1e8'))} et = time.time() log.debug('bitcoind sync_unspent took ' + str((et - st)) + 'sec') diff --git a/joinmarket/configure.py b/joinmarket/configure.py index 6a15088d..d88f8455 100644 --- a/joinmarket/configure.py +++ b/joinmarket/configure.py @@ -135,6 +135,19 @@ def jm_single(): # as our default. Note that for clients not using a local blockchain # instance, we retrieve an estimate from the API at blockcypher.com, currently. tx_fees = 3 +# the range of confirmations passed to the `listunspent` bitcoind RPC call +# 1st value is the inclusive minimum, defaults to one confirmation +# 2nd value is the exclusive maximum, defaults to most-positive-bignum (Google Me!) +# leaving it unset or empty defers to bitcoind's default values, ie [1, 9999999] +#listunspent_args = [] +# that's what you should do, unless you have a specific reason, eg: +# spend from unconfirmed transactions: listunspent_args = [0] +# display only unconfirmed transactions: listunspent_args = [0, 1] +# defend against small reorganizations: listunspent_args = [3] +# who is at risk of reorganization?: listunspent_args = [0, 2] +# NB: using 0 for the 1st value with scripts other than wallet-tool could cause +# spends from unconfirmed inputs, which may then get malleated or double-spent! +# other counterparties are likely to reject unconfirmed inputs... don't do it. """ diff --git a/wallet-tool.py b/wallet-tool.py index 6947dc34..980e913c 100644 --- a/wallet-tool.py +++ b/wallet-tool.py @@ -99,6 +99,10 @@ extend_mixdepth=not maxmixdepth_configured, storepassword=(method == 'importprivkey')) if method not in noscan_methods: + # if nothing was configured, we override bitcoind's options so that + # unconfirmed balance is included in the wallet display by default + if 'listunspent_args' not in jm_single().config.options('POLICY'): + jm_single().config.set('POLICY','listunspent_args', '[0]') jm_single().bc_interface.sync_wallet(wallet) if method == 'display' or method == 'displayall' or method == 'summary':