rename decodetx and sendtx commands. merge mktx and payto commands.

This commit is contained in:
ThomasV 2015-06-10 23:21:25 +02:00
parent e067e34313
commit 145bf5cf0a
2 changed files with 24 additions and 29 deletions

View File

@ -184,9 +184,12 @@ def run_cmdline(config):
cmd.requires_wallet = False cmd.requires_wallet = False
cmd.requires_password = False cmd.requires_password = False
if cmdname in ['mktx', 'mktx_csv'] and config.get('unsigned'): if cmdname in ['payto', 'paytomany'] and config.get('unsigned'):
cmd.requires_password = False cmd.requires_password = False
if cmdname in ['payto', 'paytomany'] and config.get('broadcast'):
cmd.requires_network = True
if cmdname in ['createrawtx'] and config.get('unsigned'): if cmdname in ['createrawtx'] and config.get('unsigned'):
cmd.requires_password = False cmd.requires_password = False
cmd.requires_wallet = False cmd.requires_wallet = False

View File

@ -206,13 +206,13 @@ class Commands:
return t return t
@command('') @command('')
def decodetx(self, tx): def deserialize(self, tx):
"""Decode serialized transaction""" """Deserialize a serialized transaction"""
t = Transaction(tx) t = Transaction(tx)
return t.deserialize() return t.deserialize()
@command('n') @command('n')
def sendtx(self, tx): def broadcast(self, tx):
"""Broadcast a transaction to the network. """ """Broadcast a transaction to the network. """
t = Transaction(tx) t = Transaction(tx)
return self.network.synchronous_get([('blockchain.transaction.broadcast', [str(t)])])[0] return self.network.synchronous_get([('blockchain.transaction.broadcast', [str(t)])])[0]
@ -357,7 +357,7 @@ class Commands:
"""Verify a signature.""" """Verify a signature."""
return bitcoin.verify_message(address, signature, message) return bitcoin.verify_message(address, signature, message)
def _mktx(self, outputs, fee, change_addr, domain, nocheck, unsigned, deserialized): def _mktx(self, outputs, fee, change_addr, domain, nocheck, unsigned):
resolver = lambda x: None if x is None else self.contacts.resolve(x, nocheck)['address'] resolver = lambda x: None if x is None else self.contacts.resolve(x, nocheck)['address']
change_addr = resolver(change_addr) change_addr = resolver(change_addr)
domain = None if domain is None else map(resolver, domain) domain = None if domain is None else map(resolver, domain)
@ -386,7 +386,7 @@ class Commands:
str(tx) #this serializes str(tx) #this serializes
if not unsigned: if not unsigned:
self.wallet.sign_transaction(tx, self.password) self.wallet.sign_transaction(tx, self.password)
return tx.deserialize() if deserialized else tx return tx
def _read_csv(self, csvpath): def _read_csv(self, csvpath):
import csv import csv
@ -401,36 +401,27 @@ class Commands:
return outputs return outputs
@command('wp') @command('wp')
def mktx(self, destination, amount, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, deserialized=False): def payto(self, destination, amount, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, deserialized=False, broadcast=False):
"""Create a transaction. """ """Create a transaction. """
domain = [from_addr] if from_addr else None domain = [from_addr] if from_addr else None
tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck, unsigned, deserialized) tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck, unsigned)
return tx if broadcast:
r, h = self.wallet.sendtx(tx)
return h
else:
return tx.deserialize() if deserialized else tx
@command('wp') @command('wp')
def mktx_csv(self, csv_file, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, deserialized=False): def paytomany(self, csv_file, tx_fee=None, from_addr=None, change_addr=None, nocheck=False, unsigned=False, deserialized=False, broadcast=False):
"""Create a multi-output transaction. """ """Create a multi-output transaction. """
domain = [from_addr] if from_addr else None domain = [from_addr] if from_addr else None
outputs = self._read_csv(csv_file) outputs = self._read_csv(csv_file)
tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck, unsigned, deserialized) tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck, unsigned)
return tx if broadcast:
r, h = self.wallet.sendtx(tx)
@command('wpn') return h
def payto(self, destination, amount, tx_fee=None, from_addr=None, change_addr=None, nocheck=False): else:
"""Create and broadcast a transaction.. """ return tx.deserialize() if deserialized else tx
domain = [from_addr] if from_addr else None
tx = self._mktx([(destination, amount)], tx_fee, change_addr, domain, nocheck)
r, h = self.wallet.sendtx(tx)
return h
@command('wpn')
def payto_csv(self, csv_file, tx_fee=None, from_addr=None, change_addr=None, nocheck=False):
"""Create and broadcast multi-output transaction.. """
domain = [from_addr] if from_addr else None
outputs = self._read_csv(csv_file)
tx = self._mktx(outputs, tx_fee, change_addr, domain, nocheck)
r, h = self.wallet.sendtx(tx)
return h
@command('wn') @command('wn')
def history(self): def history(self):
@ -581,6 +572,7 @@ param_descriptions = {
} }
command_options = { command_options = {
'broadcast': (None, "--broadcast", "Broadcast the transaction to the Bitcoin network"),
'password': ("-W", "--password", "Password"), 'password': ("-W", "--password", "Password"),
'concealed': ("-C", "--concealed", "Don't echo seed to console when restoring"), 'concealed': ("-C", "--concealed", "Don't echo seed to console when restoring"),
'show_all': ("-a", "--all", "Include change addresses"), 'show_all': ("-a", "--all", "Include change addresses"),