Merge pull request #1113 from romanz/transaction-fixes
Fix a few issues with transaction serialization and deserialization
This commit is contained in:
commit
41cf7603d8
|
@ -2229,7 +2229,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
if is_hex:
|
if is_hex:
|
||||||
try:
|
try:
|
||||||
return Transaction.deserialize(txt)
|
return Transaction(txt)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction"))
|
QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction"))
|
||||||
|
@ -2238,7 +2238,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
try:
|
try:
|
||||||
tx_dict = json.loads(str(txt))
|
tx_dict = json.loads(str(txt))
|
||||||
assert "hex" in tx_dict.keys()
|
assert "hex" in tx_dict.keys()
|
||||||
tx = Transaction.deserialize(tx_dict["hex"])
|
tx = Transaction(tx_dict["hex"])
|
||||||
#if tx_dict.has_key("input_info"):
|
#if tx_dict.has_key("input_info"):
|
||||||
# input_info = json.loads(tx_dict['input_info'])
|
# input_info = json.loads(tx_dict['input_info'])
|
||||||
# tx.add_input_info(input_info)
|
# tx.add_input_info(input_info)
|
||||||
|
@ -2312,7 +2312,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
if ok and txid:
|
if ok and txid:
|
||||||
r = self.network.synchronous_get([ ('blockchain.transaction.get',[str(txid)]) ])[0]
|
r = self.network.synchronous_get([ ('blockchain.transaction.get',[str(txid)]) ])[0]
|
||||||
if r:
|
if r:
|
||||||
tx = transaction.Transaction.deserialize(r)
|
tx = transaction.Transaction(r)
|
||||||
if tx:
|
if tx:
|
||||||
self.show_transaction(tx)
|
self.show_transaction(tx)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -176,22 +176,22 @@ class Commands:
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def signtxwithkey(self, raw_tx, sec):
|
def signtxwithkey(self, raw_tx, sec):
|
||||||
tx = Transaction.deserialize(raw_tx)
|
tx = Transaction(raw_tx)
|
||||||
pubkey = bitcoin.public_key_from_private_key(sec)
|
pubkey = bitcoin.public_key_from_private_key(sec)
|
||||||
tx.sign({ pubkey:sec })
|
tx.sign({ pubkey:sec })
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def signtxwithwallet(self, raw_tx):
|
def signtxwithwallet(self, raw_tx):
|
||||||
tx = Transaction.deserialize(raw_tx)
|
tx = Transaction(raw_tx)
|
||||||
self.wallet.sign_transaction(tx, self.password)
|
self.wallet.sign_transaction(tx, self.password)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def decoderawtransaction(self, raw):
|
def decoderawtransaction(self, raw):
|
||||||
tx = Transaction.deserialize(raw)
|
tx = Transaction(raw)
|
||||||
return {'inputs':tx.inputs, 'outputs':tx.outputs}
|
return {'inputs':tx.inputs, 'outputs':tx.outputs}
|
||||||
|
|
||||||
def sendrawtransaction(self, raw):
|
def sendrawtransaction(self, raw):
|
||||||
tx = Transaction.deserialize(raw)
|
tx = Transaction(raw)
|
||||||
return self.network.synchronous_get([('blockchain.transaction.broadcast', [str(tx)])])[0]
|
return self.network.synchronous_get([('blockchain.transaction.broadcast', [str(tx)])])[0]
|
||||||
|
|
||||||
def createmultisig(self, num, pubkeys):
|
def createmultisig(self, num, pubkeys):
|
||||||
|
@ -403,7 +403,7 @@ class Commands:
|
||||||
|
|
||||||
raw = self.network.synchronous_get([ ('blockchain.transaction.get',[tx_hash]) ])[0]
|
raw = self.network.synchronous_get([ ('blockchain.transaction.get',[tx_hash]) ])[0]
|
||||||
if raw:
|
if raw:
|
||||||
return Transaction.deserialize(raw)
|
return Transaction(raw)
|
||||||
else:
|
else:
|
||||||
return "unknown transaction"
|
return "unknown transaction"
|
||||||
|
|
||||||
|
|
|
@ -755,13 +755,13 @@ class Transaction:
|
||||||
def has_address(self, addr):
|
def has_address(self, addr):
|
||||||
return (addr in self.get_output_addresses()) or (addr in (tx.get("address") for tx in self.inputs))
|
return (addr in self.get_output_addresses()) or (addr in (tx.get("address") for tx in self.inputs))
|
||||||
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
|
if self.raw is None:
|
||||||
|
self.raw = self.serialize()
|
||||||
self.deserialize()
|
self.deserialize()
|
||||||
import json
|
|
||||||
out = {
|
out = {
|
||||||
"hex":str(self),
|
'hex': self.raw,
|
||||||
"complete":self.is_complete()
|
'complete': self.is_complete()
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ class Plugin(BasePlugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.listener.clear()
|
self.listener.clear()
|
||||||
tx = transaction.Transaction.deserialize(message)
|
tx = transaction.Transaction(message)
|
||||||
d = transaction_dialog.TxDialog(tx, self.win)
|
d = transaction_dialog.TxDialog(tx, self.win)
|
||||||
d.saved = False
|
d.saved = False
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
|
@ -299,7 +299,7 @@ class Authenticator:
|
||||||
data = r['extras']['SCAN_RESULT']
|
data = r['extras']['SCAN_RESULT']
|
||||||
data = base_decode(data.encode('utf8'), None, base=43)
|
data = base_decode(data.encode('utf8'), None, base=43)
|
||||||
data = ''.join(chr(ord(b)) for b in data).encode('hex')
|
data = ''.join(chr(ord(b)) for b in data).encode('hex')
|
||||||
tx = Transaction.deserialize(data)
|
tx = Transaction(data)
|
||||||
#except:
|
#except:
|
||||||
# modal_dialog('Error', 'Cannot parse transaction')
|
# modal_dialog('Error', 'Cannot parse transaction')
|
||||||
# continue
|
# continue
|
||||||
|
|
Loading…
Reference in New Issue