bound number of tx inputs in sweep
This commit is contained in:
parent
1e55f4fda0
commit
5d44474aeb
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue