From 5610d654d9acd721160c97c41372a61c2f9b074d Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 4 Mar 2013 17:05:26 +0100 Subject: [PATCH 1/4] WIP New raw tx window --- gui/gui_classic.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/gui/gui_classic.py b/gui/gui_classic.py index 035dd85c..0d405762 100644 --- a/gui/gui_classic.py +++ b/gui/gui_classic.py @@ -790,7 +790,7 @@ class ElectrumWindow(QMainWindow): self.show_message(str(e)) return - self.run_hook('send_tx', (wallet, self, tx)) + self.run_hook('send_tx', (self.wallet, self, tx)) if label: self.wallet.labels[tx.hash()] = label @@ -1753,6 +1753,41 @@ class ElectrumWindow(QMainWindow): else: self.show_message("There was a problem sending your transaction:\n %s" % (result_message)) + def do_process_from_file(self): + tx_dict = self.read_tx_from_file() + if tx_dict: + self.create_process_transaction_window(tx_dict) + + def create_process_transaction_window(self, tx_dict): + tx = Transaction(tx_dict["hex"]) + + dialog = QDialog(self) + dialog.setMinimumWidth(500) + dialog.setWindowTitle(_('Process raw transaction')) + dialog.setModal(1) + + l = QGridLayout() + dialog.setLayout(l) + + l.addWidget(QLabel(_("Transaction status: ")), 0,0) + l.addWidget(QLabel(_("Actions")), 1,0) + + if tx_dict["complete"] == False: + l.addWidget(QLabel(_("Unsigned")), 0,1) + if self.wallet.seed : + b = QPushButton("Sign transaction") + l.addWidget(b, 1, 1) + else: + l.addWidget(QLabel(_("Wallet is de-seeded, can't sign.")), 1,1) + else: + l.addWidget(QLabel(_("Signed")), 0,1) + b = QPushButton("Broadcast transaction") + l.addWidget(b,1,1) + + l.addWidget( self.generate_transaction_information_widget(tx), 2,0,2,3) + + if dialog.exec_(): + self.send_raw_transaction(tx_dict["hex"]) def create_send_transaction_window(self, tx_dict): tx = Transaction(tx_dict["hex"]) @@ -1775,7 +1810,6 @@ class ElectrumWindow(QMainWindow): if dialog.exec_(): self.send_raw_transaction(tx_dict["hex"]) - def do_send_from_file(self): tx_dict = self.read_tx_from_file() if tx_dict: @@ -2039,6 +2073,11 @@ class ElectrumWindow(QMainWindow): grid_raw.addWidget(EnterButton(_("From file"), self.do_send_from_file),2,1) grid_raw.addWidget(EnterButton(_("From text"), self.do_send_from_text),2,2) grid_raw.addWidget(HelpButton(_("This will broadcast a transaction to the network.")),2,3) + + grid_raw.addWidget(QLabel(_("Process raw transaction")), 3, 0) + grid_raw.addWidget(EnterButton(_("From file"), self.do_process_from_file),3,1) + grid_raw.addWidget(EnterButton(_("From text"), self.do_process_from_file),3,2) + grid_raw.addWidget(HelpButton(_("This will sign or broadcast a transaction.")),3,3) grid_raw.setRowStretch(3,1) # plugins From 15c7fafd492df322680384145d616df189443b8b Mon Sep 17 00:00:00 2001 From: Maran Date: Fri, 8 Mar 2013 16:30:38 +0100 Subject: [PATCH 2/4] Further work on raw transactions --- gui/gui_classic.py | 101 +++++---------------------------------------- 1 file changed, 11 insertions(+), 90 deletions(-) diff --git a/gui/gui_classic.py b/gui/gui_classic.py index d24870e8..e59a798b 100644 --- a/gui/gui_classic.py +++ b/gui/gui_classic.py @@ -1680,7 +1680,7 @@ class ElectrumWindow(QMainWindow): @protected - def sign_raw_transaction(self, tx, input_info, password): + def sign_raw_transaction(self, tx, input_info, dialog ="", password = ""): try: self.wallet.signrawtransaction(tx, input_info, [], password) @@ -1689,53 +1689,18 @@ class ElectrumWindow(QMainWindow): with open(fileName, "w+") as f: f.write(json.dumps(tx.as_dict(),indent=4) + '\n') self.show_message(_("Transaction saved succesfully")) + if dialog: + dialog.done(0) except BaseException, e: self.show_message(str(e)) - - - def create_sign_transaction_window(self, tx_dict): - tx = Transaction(tx_dict["hex"]) - - dialog = QDialog(self) - dialog.setMinimumWidth(500) - dialog.setWindowTitle(_('Sign unsigned transaction')) - dialog.setModal(1) - - vbox = QVBoxLayout() - dialog.setLayout(vbox) - vbox.addWidget( self.generate_transaction_information_widget(tx) ) - - if tx_dict["complete"] == True: - vbox.addWidget(QLabel(_("This transaction is already signed."))) - else: - vbox.addWidget(QLabel(_("Create a signed transaction."))) - vbox.addLayout(ok_cancel_buttons(dialog)) - input_info = json.loads(tx_dict["input_info"]) - - if dialog.exec_(): - self.sign_raw_transaction(tx, input_info) - - - - def do_sign_from_text(self): - txt, ok = QInputDialog.getText(QTextEdit(), _('Sign raw transaction'), _('Transaction data in JSON') + ':') - if not ok: - return - tx_dict = self.tx_dict_from_text(unicode(txt)) - if tx_dict: - self.create_sign_transaction_window(tx_dict) - - - def do_sign_from_file(self): - tx_dict = self.read_tx_from_file() - if tx_dict: - self.create_sign_transaction_window(tx_dict) - def send_raw_transaction(self, raw_tx): + def send_raw_transaction(self, raw_tx, dialog = ""): result, result_message = self.wallet.sendtx( raw_tx ) if result: self.show_message("Transaction succesfully sent: %s" % (result_message)) + if dialog: + dialog.done(0) else: self.show_message("There was a problem sending your transaction:\n %s" % (result_message)) @@ -1746,7 +1711,7 @@ class ElectrumWindow(QMainWindow): def create_process_transaction_window(self, tx_dict): tx = Transaction(tx_dict["hex"]) - + dialog = QDialog(self) dialog.setMinimumWidth(500) dialog.setWindowTitle(_('Process raw transaction')) @@ -1762,53 +1727,20 @@ class ElectrumWindow(QMainWindow): l.addWidget(QLabel(_("Unsigned")), 0,1) if self.wallet.seed : b = QPushButton("Sign transaction") + input_info = json.loads(tx_dict["input_info"]) + b.clicked.connect(lambda: self.sign_raw_transaction(tx, input_info, dialog)) l.addWidget(b, 1, 1) else: l.addWidget(QLabel(_("Wallet is de-seeded, can't sign.")), 1,1) else: l.addWidget(QLabel(_("Signed")), 0,1) b = QPushButton("Broadcast transaction") + b.clicked.connect(lambda: self.send_raw_transaction(tx, dialog)) l.addWidget(b,1,1) l.addWidget( self.generate_transaction_information_widget(tx), 2,0,2,3) - if dialog.exec_(): - self.send_raw_transaction(tx_dict["hex"]) - - def create_send_transaction_window(self, tx_dict): - tx = Transaction(tx_dict["hex"]) - - dialog = QDialog(self) - dialog.setMinimumWidth(500) - dialog.setWindowTitle(_('Send raw transaction')) - dialog.setModal(1) - - vbox = QVBoxLayout() - dialog.setLayout(vbox) - vbox.addWidget( self.generate_transaction_information_widget(tx)) - - if tx_dict["complete"] == False: - vbox.addWidget(QLabel(_("This transaction is not signed yet."))) - else: - vbox.addWidget(QLabel(_("Broadcast this transaction"))) - vbox.addLayout(ok_cancel_buttons(dialog)) - - if dialog.exec_(): - self.send_raw_transaction(tx_dict["hex"]) - - def do_send_from_file(self): - tx_dict = self.read_tx_from_file() - if tx_dict: - self.create_send_transaction_window(tx_dict) - - - def do_send_from_text(self): - txt, ok = QInputDialog.getText(QTextEdit(), _('Send raw transaction'), _('Transaction data in JSON') + ':') - if not ok: - return - tx_dict = self.tx_dict_from_text(unicode(txt)) - if tx_dict: - self.create_send_transaction_window(tx_dict) + dialog.exec_() @protected @@ -2041,17 +1973,6 @@ class ElectrumWindow(QMainWindow): grid_raw.setColumnStretch(0,1) tabs.addTab(tab4, _('Raw tx') ) # move this to wallet tab - if self.wallet.seed: - grid_raw.addWidget(QLabel(_("Sign transaction")), 1, 0) - grid_raw.addWidget(EnterButton(_("From file"), self.do_sign_from_file),1,1) - grid_raw.addWidget(EnterButton(_("From text"), self.do_sign_from_text),1,2) - grid_raw.addWidget(HelpButton(_("Sign an unsigned transaction generated by a watching-only wallet")),1,3) - - grid_raw.addWidget(QLabel(_("Send signed transaction")), 2, 0) - grid_raw.addWidget(EnterButton(_("From file"), self.do_send_from_file),2,1) - grid_raw.addWidget(EnterButton(_("From text"), self.do_send_from_text),2,2) - grid_raw.addWidget(HelpButton(_("This will broadcast a transaction to the network.")),2,3) - grid_raw.addWidget(QLabel(_("Process raw transaction")), 3, 0) grid_raw.addWidget(EnterButton(_("From file"), self.do_process_from_file),3,1) grid_raw.addWidget(EnterButton(_("From text"), self.do_process_from_file),3,2) From f5758d291b4415fa77fbb78d193a37d668b59683 Mon Sep 17 00:00:00 2001 From: Maran Date: Fri, 8 Mar 2013 16:48:40 +0100 Subject: [PATCH 3/4] Final tweaks for raw transaction processing --- gui/gui_classic.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gui/gui_classic.py b/gui/gui_classic.py index e59a798b..f76d4e14 100644 --- a/gui/gui_classic.py +++ b/gui/gui_classic.py @@ -1704,6 +1704,27 @@ class ElectrumWindow(QMainWindow): else: self.show_message("There was a problem sending your transaction:\n %s" % (result_message)) + def do_process_from_text(self): + dialog = QDialog(self) + dialog.setMinimumWidth(500) + dialog.setWindowTitle(_('Input raw transaction')) + dialog.setModal(1) + l = QVBoxLayout() + dialog.setLayout(l) + l.addWidget(QLabel(_("Transaction:"))) + txt = QTextEdit() + l.addWidget(txt) + + ok_button = QPushButton(_("Process transaction")) + ok_button.setDefault(True) + ok_button.clicked.connect(dialog.accept) + l.addWidget(ok_button) + + dialog.exec_() + tx_dict = self.tx_dict_from_text(unicode(txt.toPlainText())) + if tx_dict: + self.create_process_transaction_window(tx_dict) + def do_process_from_file(self): tx_dict = self.read_tx_from_file() if tx_dict: @@ -1973,10 +1994,10 @@ class ElectrumWindow(QMainWindow): grid_raw.setColumnStretch(0,1) tabs.addTab(tab4, _('Raw tx') ) # move this to wallet tab - grid_raw.addWidget(QLabel(_("Process raw transaction")), 3, 0) - grid_raw.addWidget(EnterButton(_("From file"), self.do_process_from_file),3,1) - grid_raw.addWidget(EnterButton(_("From text"), self.do_process_from_file),3,2) - grid_raw.addWidget(HelpButton(_("This will sign or broadcast a transaction.")),3,3) + grid_raw.addWidget(QLabel(_("Process raw transaction")), 0, 0) + grid_raw.addWidget(EnterButton(_("From file"), self.do_process_from_file),0,1) + grid_raw.addWidget(EnterButton(_("From text"), self.do_process_from_text),0,2) + grid_raw.addWidget(HelpButton(_("This will give you the option to sign or broadcast a transaction based on it's status.")),0,3) grid_raw.setRowStretch(3,1) # plugins From 80975ecf04a906f56fe92d9d7f9b205c2a8500a4 Mon Sep 17 00:00:00 2001 From: Maran Date: Sun, 10 Mar 2013 12:14:42 +0100 Subject: [PATCH 4/4] Moved rawtx to wallet tab and added small usability tweaks --- gui/gui_classic.py | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/gui/gui_classic.py b/gui/gui_classic.py index f76d4e14..836e8f13 100644 --- a/gui/gui_classic.py +++ b/gui/gui_classic.py @@ -1715,7 +1715,7 @@ class ElectrumWindow(QMainWindow): txt = QTextEdit() l.addWidget(txt) - ok_button = QPushButton(_("Process transaction")) + ok_button = QPushButton(_("Load transaction")) ok_button.setDefault(True) ok_button.clicked.connect(dialog.accept) l.addWidget(ok_button) @@ -1741,25 +1741,28 @@ class ElectrumWindow(QMainWindow): l = QGridLayout() dialog.setLayout(l) - l.addWidget(QLabel(_("Transaction status: ")), 0,0) - l.addWidget(QLabel(_("Actions")), 1,0) + l.addWidget(QLabel(_("Transaction status: ")), 3,0) + l.addWidget(QLabel(_("Actions")), 4,0) if tx_dict["complete"] == False: - l.addWidget(QLabel(_("Unsigned")), 0,1) + l.addWidget(QLabel(_("Unsigned")), 3,1) if self.wallet.seed : b = QPushButton("Sign transaction") input_info = json.loads(tx_dict["input_info"]) b.clicked.connect(lambda: self.sign_raw_transaction(tx, input_info, dialog)) - l.addWidget(b, 1, 1) + l.addWidget(b, 4, 1) else: - l.addWidget(QLabel(_("Wallet is de-seeded, can't sign.")), 1,1) + l.addWidget(QLabel(_("Wallet is de-seeded, can't sign.")), 4,1) else: - l.addWidget(QLabel(_("Signed")), 0,1) + l.addWidget(QLabel(_("Signed")), 3,1) b = QPushButton("Broadcast transaction") b.clicked.connect(lambda: self.send_raw_transaction(tx, dialog)) - l.addWidget(b,1,1) + l.addWidget(b,4,1) - l.addWidget( self.generate_transaction_information_widget(tx), 2,0,2,3) + l.addWidget( self.generate_transaction_information_widget(tx), 0,0,2,3) + cancelButton = QPushButton(_("Cancel")) + cancelButton.clicked.connect(lambda: dialog.done(0)) + l.addWidget(cancelButton, 4,2) dialog.exec_() @@ -1919,14 +1922,19 @@ class ElectrumWindow(QMainWindow): grid_wallet.setColumnStretch(0,1) tabs.addTab(tab2, _('Wallet') ) + grid_wallet.addWidget(QLabel(_("Load raw transaction")), 3, 0) + grid_wallet.addWidget(EnterButton(_("From file"), self.do_process_from_file),3,1) + grid_wallet.addWidget(EnterButton(_("From text"), self.do_process_from_text),3,2) + grid_wallet.addWidget(HelpButton(_("This will give you the option to sign or broadcast a transaction based on it's status.")),3,3) + fee_label = QLabel(_('Transaction fee')) grid_wallet.addWidget(fee_label, 0, 0) fee_e = QLineEdit() fee_e.setText("%s"% str( Decimal( self.wallet.fee)/100000000 ) ) - grid_wallet.addWidget(fee_e, 0, 1) + grid_wallet.addWidget(fee_e, 0, 2) msg = _('Fee per transaction input. Transactions involving multiple inputs tend to require a higher fee.') + ' ' \ + _('Recommended value') + ': 0.001' - grid_wallet.addWidget(HelpButton(msg), 0, 2) + grid_wallet.addWidget(HelpButton(msg), 0, 3) fee_e.textChanged.connect(lambda: numbify(fee_e,False)) if not self.config.is_modifiable('fee'): for w in [fee_e, fee_label]: w.setEnabled(False) @@ -1936,15 +1944,15 @@ class ElectrumWindow(QMainWindow): usechange_combo = QComboBox() usechange_combo.addItems([_('Yes'), _('No')]) usechange_combo.setCurrentIndex(not self.wallet.use_change) - grid_wallet.addWidget(usechange_combo, 1, 1) - grid_wallet.addWidget(HelpButton(_('Using change addresses makes it more difficult for other people to track your transactions.')+' '), 1, 2) + grid_wallet.addWidget(usechange_combo, 1, 2) + grid_wallet.addWidget(HelpButton(_('Using change addresses makes it more difficult for other people to track your transactions.')+' '), 1, 3) if not self.config.is_modifiable('use_change'): usechange_combo.setEnabled(False) gap_label = QLabel(_('Gap limit')) grid_wallet.addWidget(gap_label, 2, 0) gap_e = QLineEdit() gap_e.setText("%d"% self.wallet.gap_limit) - grid_wallet.addWidget(gap_e, 2, 1) + grid_wallet.addWidget(gap_e, 2, 2) msg = _('The gap limit is the maximal number of contiguous unused addresses in your sequence of receiving addresses.') + '\n' \ + _('You may increase it if you need more receiving addresses.') + '\n\n' \ + _('Your current gap limit is') + ': %d'%self.wallet.gap_limit + '\n' \ @@ -1952,7 +1960,7 @@ class ElectrumWindow(QMainWindow): + _('Warning') + ': ' \ + _('The gap limit parameter must be provided in order to recover your wallet from seed.') + ' ' \ + _('Do not modify it if you do not understand what you are doing, or if you expect to recover your wallet without knowing it!') + '\n\n' - grid_wallet.addWidget(HelpButton(msg), 2, 2) + grid_wallet.addWidget(HelpButton(msg), 2, 3) gap_e.textChanged.connect(lambda: numbify(nz_e,True)) if not self.config.is_modifiable('gap_limit'): for w in [gap_e, gap_label]: w.setEnabled(False) @@ -1989,16 +1997,6 @@ class ElectrumWindow(QMainWindow): grid_io.setRowStretch(4,1) - tab4 = QWidget() - grid_raw = QGridLayout(tab4) - grid_raw.setColumnStretch(0,1) - tabs.addTab(tab4, _('Raw tx') ) # move this to wallet tab - - grid_raw.addWidget(QLabel(_("Process raw transaction")), 0, 0) - grid_raw.addWidget(EnterButton(_("From file"), self.do_process_from_file),0,1) - grid_raw.addWidget(EnterButton(_("From text"), self.do_process_from_text),0,2) - grid_raw.addWidget(HelpButton(_("This will give you the option to sign or broadcast a transaction based on it's status.")),0,3) - grid_raw.setRowStretch(3,1) # plugins if self.plugins: