URI: 
       tbound number of tx inputs in sweep - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 5d44474aeb595ba4fd037188bc41b616825498a0
   DIR parent 1e55f4fda078d7ff1882567101aab5f10c8b9772
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Sat,  8 Oct 2016 11:40:03 +0200
       
       bound number of tx inputs in sweep
       
       Diffstat:
         M lib/commands.py                     |       8 +++++---
         M lib/wallet.py                       |       6 ++++--
       
       2 files changed, 9 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/lib/commands.py b/lib/commands.py
       t@@ -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):
       t@@ -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"),
       t@@ -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,
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -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:
       t@@ -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
       t@@ -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: