implementing mksendmanytx
A simple argument parsing change from mktx to allow passing multiple recipients
This commit is contained in:
parent
bc4671ac34
commit
8afb03e45a
10
electrum
10
electrum
|
@ -326,6 +326,16 @@ if __name__ == '__main__':
|
||||||
domain = [options.from_addr] if options.from_addr else None
|
domain = [options.from_addr] if options.from_addr else None
|
||||||
args = [ 'mktx', args[1], Decimal(args[2]), Decimal(options.tx_fee) if options.tx_fee else None, options.change_addr, domain ]
|
args = [ 'mktx', args[1], Decimal(args[2]), Decimal(options.tx_fee) if options.tx_fee else None, options.change_addr, domain ]
|
||||||
|
|
||||||
|
elif cmd == 'mksendmanytx':
|
||||||
|
domain = [options.from_addr] if options.from_addr else None
|
||||||
|
outputs = []
|
||||||
|
for i in range(1, len(args), 2):
|
||||||
|
if len(args) < i+2:
|
||||||
|
print_msg("Error: Mismatched arguments.")
|
||||||
|
exit(1)
|
||||||
|
outputs.append((args[i], Decimal(args[i+1])))
|
||||||
|
args = [ 'mksendmanytx', outputs, Decimal(options.tx_fee) if options.tx_fee else None, options.change_addr, domain ]
|
||||||
|
|
||||||
elif cmd == 'help':
|
elif cmd == 'help':
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
|
@ -59,6 +59,7 @@ register_command('importprivkey', 1, 1, True, True, 'Import a private k
|
||||||
register_command('listaddresses', 3, 3, False, True, 'Returns your list of addresses.', '', listaddr_options)
|
register_command('listaddresses', 3, 3, False, True, 'Returns your list of addresses.', '', listaddr_options)
|
||||||
register_command('listunspent', 0, 0, False, True, 'Returns a list of unspent inputs in your wallet.')
|
register_command('listunspent', 0, 0, False, True, 'Returns a list of unspent inputs in your wallet.')
|
||||||
register_command('mktx', 5, 5, True, True, 'Create a signed transaction', 'mktx <recipient> <amount> [label]', payto_options)
|
register_command('mktx', 5, 5, True, True, 'Create a signed transaction', 'mktx <recipient> <amount> [label]', payto_options)
|
||||||
|
register_command('mksendmanytx', 4, 4, True, True, 'Create a signed transaction', 'mktx <recipient> <amount> [<recipient> <amount> ...]', payto_options)
|
||||||
register_command('payto', 5, 5, True, False, 'Create and broadcast a transaction.', "payto <recipient> <amount> [label]\n<recipient> can be a bitcoin address or a label", payto_options)
|
register_command('payto', 5, 5, True, False, 'Create and broadcast a transaction.', "payto <recipient> <amount> [label]\n<recipient> can be a bitcoin address or a label", payto_options)
|
||||||
register_command('password', 0, 0, True, True, 'Change your password')
|
register_command('password', 0, 0, True, True, 'Change your password')
|
||||||
register_command('prioritize', 1, 1, False, True, 'Coins at prioritized addresses are spent first.', 'prioritize <address>')
|
register_command('prioritize', 1, 1, False, True, 'Coins at prioritized addresses are spent first.', 'prioritize <address>')
|
||||||
|
@ -208,8 +209,9 @@ class Commands:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _mktx(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
def _mktx(self, outputs, fee = None, change_addr = None, domain = None):
|
||||||
|
|
||||||
|
for to_address, amount in outputs:
|
||||||
if not is_valid(to_address):
|
if not is_valid(to_address):
|
||||||
raise BaseException("Invalid Bitcoin address", to_address)
|
raise BaseException("Invalid Bitcoin address", to_address)
|
||||||
|
|
||||||
|
@ -225,26 +227,36 @@ class Commands:
|
||||||
if not self.wallet.is_mine(addr):
|
if not self.wallet.is_mine(addr):
|
||||||
raise BaseException("address not in wallet", addr)
|
raise BaseException("address not in wallet", addr)
|
||||||
|
|
||||||
|
for k, v in self.wallet.labels.items():
|
||||||
|
if change_addr and v == change_addr:
|
||||||
|
change_addr = k
|
||||||
|
|
||||||
|
final_outputs = []
|
||||||
|
for to_address, amount in outputs:
|
||||||
for k, v in self.wallet.labels.items():
|
for k, v in self.wallet.labels.items():
|
||||||
if v == to_address:
|
if v == to_address:
|
||||||
to_address = k
|
to_address = k
|
||||||
print_msg("alias", to_address)
|
print_msg("alias", to_address)
|
||||||
break
|
break
|
||||||
if change_addr and v == change_addr:
|
|
||||||
change_addr = k
|
|
||||||
|
|
||||||
amount = int(100000000*amount)
|
amount = int(100000000*amount)
|
||||||
|
final_outputs.append((to_address, amount))
|
||||||
|
|
||||||
if fee: fee = int(100000000*fee)
|
if fee: fee = int(100000000*fee)
|
||||||
return self.wallet.mktx( [(to_address, amount)], self.password, fee , change_addr, domain)
|
return self.wallet.mktx(final_outputs, self.password, fee , change_addr, domain)
|
||||||
|
|
||||||
|
|
||||||
def mktx(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
def mktx(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
||||||
tx = self._mktx(to_address, amount, fee, change_addr, domain)
|
tx = self._mktx([(to_address, amount)], fee, change_addr, domain)
|
||||||
|
return tx.as_dict()
|
||||||
|
|
||||||
|
def mksendmanytx(self, outputs, fee = None, change_addr = None, domain = None):
|
||||||
|
tx = self._mktx(outputs, fee, change_addr, domain)
|
||||||
return tx.as_dict()
|
return tx.as_dict()
|
||||||
|
|
||||||
|
|
||||||
def payto(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
def payto(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
||||||
tx = self._mktx(to_address, amount, fee, change_addr, domain)
|
tx = self._mktx([(to_address, amount)], fee, change_addr, domain)
|
||||||
r, h = self.wallet.sendtx( tx )
|
r, h = self.wallet.sendtx( tx )
|
||||||
return h
|
return h
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue