fix transaction parsing from command line

This commit is contained in:
ThomasV 2016-03-16 10:31:33 +01:00
parent 9608d9aa86
commit 9659e8542d
3 changed files with 27 additions and 22 deletions

View File

@ -2244,21 +2244,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
def tx_from_text(self, txt):
"json or raw hexadecimal"
txt = txt.strip()
from electrum.transaction import tx_from_str
try:
txt.decode('hex')
is_hex = True
except:
is_hex = False
try:
if is_hex:
return Transaction(txt)
tx_dict = json.loads(str(txt))
assert "hex" in tx_dict.keys()
tx = Transaction(tx_dict["hex"])
return tx
return tx_from_str(txt)
except:
traceback.print_exc(file=sys.stdout)
self.show_critical(_("Electrum was unable to parse your transaction"))

View File

@ -216,24 +216,22 @@ class Commands:
@command('wp')
def signtransaction(self, tx, privkey=None):
"""Sign a transaction. The wallet keys will be used unless a private key is provided."""
t = Transaction(tx)
if privkey:
pubkey = bitcoin.public_key_from_private_key(privkey)
t.sign({pubkey:privkey})
tx.sign({pubkey:privkey})
else:
self.wallet.sign_transaction(t, self._password)
return t.as_dict()
self.wallet.sign_transaction(tx, self._password)
return tx.as_dict()
@command('')
def deserialize(self, tx):
"""Deserialize a serialized transaction"""
return Transaction(tx).deserialize()
return tx.deserialize()
@command('n')
def broadcast(self, tx, timeout=10):
"""Broadcast a transaction to the network. """
t = Transaction(tx)
return self.network.broadcast(t, timeout)
return self.network.broadcast(tx, timeout)
@command('')
def createmultisig(self, num, pubkeys):
@ -667,12 +665,13 @@ command_options = {
# don't use floats because of rounding errors
from transaction import tx_from_str
json_loads = lambda x: json.loads(x, parse_float=lambda x: str(Decimal(x)))
arg_types = {
'num': int,
'nbits': int,
'entropy': long,
'tx': json_loads,
'tx': tx_from_str,
'pubkeys': json_loads,
'inputs': json_loads,
'outputs': json_loads,

View File

@ -859,3 +859,21 @@ class Transaction:
print_error(priority, threshold)
return priority < threshold
def tx_from_str(txt):
"json or raw hexadecimal"
import json
txt = txt.strip()
try:
txt.decode('hex')
is_hex = True
except:
is_hex = False
if is_hex:
return Transaction(txt)
tx_dict = json.loads(str(txt))
assert "hex" in tx_dict.keys()
tx = Transaction(tx_dict["hex"])
return tx