try:
import PyQt4
-except:
+except Exception:
sys.exit("Error: Could not import PyQt4 on Linux systems, you may try 'sudo apt-get install python-qt4'")
from PyQt4.QtGui import *
import PyQt4.QtCore as QtCore
from electrum import transaction
+from electrum.plugins import run_hook
+
from util import MyTreeWidget
class TxDialog(QDialog):
buttons.addWidget(b)
self.broadcast_button = b = QPushButton(_("Broadcast"))
- b.clicked.connect(self.broadcast)
+ b.clicked.connect(lambda: self.parent.broadcast_transaction(self.tx))
+
b.hide()
buttons.addWidget(b)
cancelButton.clicked.connect(lambda: self.done(0))
buttons.addWidget(cancelButton)
cancelButton.setDefault(True)
-
+
+ b = QPushButton(_("Show QR code"))
+ b.clicked.connect(self.show_qr)
+ buttons.insertWidget(1,b)
self.update()
+ def show_qr(self):
+ try:
+ json_text = json.dumps(self.tx.as_dict()).replace(' ', '')
+ self.parent.show_qrcode(json_text, 'Transaction')
+ except Exception as e:
+ self.show_message(str(e))
def sign(self):
def save(self):
- fileName = self.parent.getSaveFileName(_("Select where to save your signed transaction"), 'signed_%s.txn' % (self.tx.hash()[0:8]), "*.txn")
+ name = 'signed_%s.txn' % (self.tx.hash()[0:8]) if self.tx.is_complete() else 'unsigned.txn'
+ fileName = self.parent.getSaveFileName(_("Select where to save your signed transaction"), name, "*.txn")
if fileName:
with open(fileName, "w+") as f:
f.write(json.dumps(self.tx.as_dict(),indent=4) + '\n')
def update(self):
- tx_hash = self.tx.hash()
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(self.tx)
- if self.tx.is_complete:
+ if self.tx.is_complete():
status = _("Status: Signed")
self.sign_button.hide()
+ tx_hash = self.tx.hash()
if tx_hash in self.wallet.transactions.keys():
conf, timestamp = self.wallet.verifier.get_confirmations(tx_hash)
else:
status = _("Status: Unsigned")
time_str = None
- self.sign_button.show()
+ if not self.wallet.is_watching_only():
+ self.sign_button.show()
+ else:
+ self.sign_button.hide()
self.broadcast_button.hide()
+ tx_hash = 'unknown'
self.tx_hash_e.setText(tx_hash)
self.status_label.setText(status)
else:
self.date_label.hide()
+ # if we are not synchronized, we cannot tell
+ if self.parent.network is None or not self.parent.network.is_running() or not self.parent.network.is_connected():
+ return
+ if not self.wallet.up_to_date:
+ return
+
if is_relevant:
if is_mine:
if fee is not None:
self.amount_label.setText(_("Transaction unrelated to your wallet"))
- def exec_menu(self, position,l):
- item = l.itemAt(position)
- if not item: return
- addr = unicode(item.text(0))
- menu = QMenu()
- menu.addAction(_("Copy to clipboard"), lambda: self.parent.app.clipboard().setText(addr))
- menu.exec_(l.viewport().mapToGlobal(position))
-
def add_io(self, vbox):
- vbox.addWidget(QLabel(_("Inputs")))
- lines = map(lambda x: x.get('address') , self.tx.inputs )
+ if self.tx.locktime > 0:
+ vbox.addWidget(QLabel("LockTime: %d\n" % self.tx.locktime))
- i_text = QTextEdit('\n'.join(lines))
+ vbox.addWidget(QLabel(_("Inputs")))
+ def format_input(x):
+ if x.get('is_coinbase'):
+ return 'coinbase'
+ else:
+ _hash = x.get('prevout_hash')
+ return _hash[0:16] + '...' + _hash[-8:] + ":%d"%x.get('prevout_n') + u'\t' + "%s"%x.get('address')
+ lines = map(format_input, self.tx.inputs )
+ i_text = QTextEdit()
+ i_text.setText('\n'.join(lines))
i_text.setReadOnly(True)
i_text.setMaximumHeight(100)
vbox.addWidget(i_text)
vbox.addWidget(QLabel(_("Outputs")))
lines = map(lambda x: x[0] + u'\t\t' + self.parent.format_amount(x[1]), self.tx.outputs)
-
o_text = QTextEdit()
o_text.setText('\n'.join(lines))
o_text.setReadOnly(True)
-
- def broadcast(self):
- result, result_message = self.wallet.sendtx( self.tx )
- if result:
- self.show_message(_("Transaction successfully sent")+': %s' % (result_message))
- if dialog:
- dialog.done(0)
- else:
- self.show_message(_("There was a problem sending your transaction:") + '\n %s' % (result_message))
-
def show_message(self, msg):
QMessageBox.information(self, _('Message'), msg, _('OK'))