electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 5d44474aeb595ba4fd037188bc41b616825498a0
parent 1e55f4fda078d7ff1882567101aab5f10c8b9772
Author: ThomasV <thomasv@electrum.org>
Date:   Sat,  8 Oct 2016 11:40:03 +0200

bound number of tx inputs in sweep

Diffstat:
Mlib/commands.py | 8+++++---
Mlib/wallet.py | 6++++--
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/commands.py b/lib/commands.py @@ -369,15 +369,15 @@ class Commands: return out['address'] @command('nw') - def sweep(self, privkey, destination, tx_fee=None, nocheck=False): + def sweep(self, privkey, destination, tx_fee=None, nocheck=False, imax=100): """Sweep private keys. Returns a transaction that spends UTXOs from privkey to a destination address. The transaction is not broadcasted.""" privkeys = privkey if type(privkey) is list else [privkey] self.nocheck = nocheck dest = self._resolver(destination) - tx = self.wallet.sweep(privkeys, self.network, self.config, dest, tx_fee) - return tx.as_dict() + tx = self.wallet.sweep(privkeys, self.network, self.config, dest, tx_fee, imax) + return tx.as_dict() if tx else None @command('wp') def signmessage(self, address, message): @@ -652,6 +652,7 @@ command_options = { 'show_balance':("-b", "--balance", "Show the balances of listed addresses"), 'show_labels': ("-l", "--labels", "Show the labels of listed addresses"), 'nocheck': (None, "--nocheck", "Do not verify aliases"), + 'imax': (None, "--imax", "Maximum number of inputs"), 'tx_fee': ("-f", "--fee", "Transaction fee (in BTC)"), 'from_addr': ("-F", "--from", "Source address. If it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet."), 'change_addr': ("-c", "--change", "Change address. Default is a spare address, or the source address if it's not in the wallet"), @@ -678,6 +679,7 @@ json_loads = lambda x: json.loads(x, parse_float=lambda x: str(Decimal(x))) arg_types = { 'num': int, 'nbits': int, + 'imax': int, 'tx': tx_from_str, 'pubkeys': json_loads, 'jsontx': json_loads, diff --git a/lib/wallet.py b/lib/wallet.py @@ -854,7 +854,7 @@ class Abstract_Wallet(PrintError): self.sign_transaction(tx, password) return tx - def sweep(self, privkeys, network, config, recipient, fee): + def sweep(self, privkeys, network, config, recipient, fee=None, imax=100): inputs = [] keypairs = {} for privkey in privkeys: @@ -863,6 +863,8 @@ class Abstract_Wallet(PrintError): u = network.synchronous_get(('blockchain.address.listunspent', [address])) pay_script = Transaction.pay_script(TYPE_ADDRESS, address) for item in u: + if len(inputs) >= imax: + break item['scriptPubKey'] = pay_script item['redeemPubkey'] = pubkey item['address'] = address @@ -872,7 +874,7 @@ class Abstract_Wallet(PrintError): item['x_pubkeys'] = [pubkey] item['signatures'] = [None] item['num_sig'] = 1 - inputs += u + inputs.append(item) keypairs[pubkey] = privkey if not inputs: