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']
|
return out['address']
|
||||||
|
|
||||||
@command('nw')
|
@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
|
"""Sweep private keys. Returns a transaction that spends UTXOs from
|
||||||
privkey to a destination address. The transaction is not
|
privkey to a destination address. The transaction is not
|
||||||
broadcasted."""
|
broadcasted."""
|
||||||
privkeys = privkey if type(privkey) is list else [privkey]
|
privkeys = privkey if type(privkey) is list else [privkey]
|
||||||
self.nocheck = nocheck
|
self.nocheck = nocheck
|
||||||
dest = self._resolver(destination)
|
dest = self._resolver(destination)
|
||||||
tx = self.wallet.sweep(privkeys, self.network, self.config, dest, tx_fee)
|
tx = self.wallet.sweep(privkeys, self.network, self.config, dest, tx_fee, imax)
|
||||||
return tx.as_dict()
|
return tx.as_dict() if tx else None
|
||||||
|
|
||||||
@command('wp')
|
@command('wp')
|
||||||
def signmessage(self, address, message):
|
def signmessage(self, address, message):
|
||||||
@ -652,6 +652,7 @@ command_options = {
|
|||||||
'show_balance':("-b", "--balance", "Show the balances of listed addresses"),
|
'show_balance':("-b", "--balance", "Show the balances of listed addresses"),
|
||||||
'show_labels': ("-l", "--labels", "Show the labels of listed addresses"),
|
'show_labels': ("-l", "--labels", "Show the labels of listed addresses"),
|
||||||
'nocheck': (None, "--nocheck", "Do not verify aliases"),
|
'nocheck': (None, "--nocheck", "Do not verify aliases"),
|
||||||
|
'imax': (None, "--imax", "Maximum number of inputs"),
|
||||||
'tx_fee': ("-f", "--fee", "Transaction fee (in BTC)"),
|
'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."),
|
'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"),
|
'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 = {
|
arg_types = {
|
||||||
'num': int,
|
'num': int,
|
||||||
'nbits': int,
|
'nbits': int,
|
||||||
|
'imax': int,
|
||||||
'tx': tx_from_str,
|
'tx': tx_from_str,
|
||||||
'pubkeys': json_loads,
|
'pubkeys': json_loads,
|
||||||
'jsontx': json_loads,
|
'jsontx': json_loads,
|
||||||
|
|||||||
@ -854,7 +854,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
self.sign_transaction(tx, password)
|
self.sign_transaction(tx, password)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def sweep(self, privkeys, network, config, recipient, fee):
|
def sweep(self, privkeys, network, config, recipient, fee=None, imax=100):
|
||||||
inputs = []
|
inputs = []
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
for privkey in privkeys:
|
for privkey in privkeys:
|
||||||
@ -863,6 +863,8 @@ class Abstract_Wallet(PrintError):
|
|||||||
u = network.synchronous_get(('blockchain.address.listunspent', [address]))
|
u = network.synchronous_get(('blockchain.address.listunspent', [address]))
|
||||||
pay_script = Transaction.pay_script(TYPE_ADDRESS, address)
|
pay_script = Transaction.pay_script(TYPE_ADDRESS, address)
|
||||||
for item in u:
|
for item in u:
|
||||||
|
if len(inputs) >= imax:
|
||||||
|
break
|
||||||
item['scriptPubKey'] = pay_script
|
item['scriptPubKey'] = pay_script
|
||||||
item['redeemPubkey'] = pubkey
|
item['redeemPubkey'] = pubkey
|
||||||
item['address'] = address
|
item['address'] = address
|
||||||
@ -872,7 +874,7 @@ class Abstract_Wallet(PrintError):
|
|||||||
item['x_pubkeys'] = [pubkey]
|
item['x_pubkeys'] = [pubkey]
|
||||||
item['signatures'] = [None]
|
item['signatures'] = [None]
|
||||||
item['num_sig'] = 1
|
item['num_sig'] = 1
|
||||||
inputs += u
|
inputs.append(item)
|
||||||
keypairs[pubkey] = privkey
|
keypairs[pubkey] = privkey
|
||||||
|
|
||||||
if not inputs:
|
if not inputs:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user