electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 9659e8542d716dc1d87b4064906c444e4f18a95a
parent 9608d9aa86a642e869b45a0af36393563bbb1571
Author: ThomasV <thomasv@electrum.org>
Date:   Wed, 16 Mar 2016 10:31:33 +0100

fix transaction parsing from command line

Diffstat:
Mgui/qt/main_window.py | 16++--------------
Mlib/commands.py | 15+++++++--------
Mlib/transaction.py | 18++++++++++++++++++
3 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -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")) diff --git a/lib/commands.py b/lib/commands.py @@ -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, diff --git a/lib/transaction.py b/lib/transaction.py @@ -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