From f3822cf06e2813eaa3d673131a16ae9e1d475d0a Mon Sep 17 00:00:00 2001 From: dabura667 Date: Sat, 6 Sep 2014 19:34:42 +0900 Subject: [PATCH 1/2] Multiline Address error on do_send() --- gui/qt/main_window.py | 9 +++++++-- gui/qt/paytoedit.py | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 0cbfde85e..2e3d83bff 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -941,7 +941,7 @@ class ElectrumWindow(QMainWindow): amount = self.amount_e.get_amount() fee = self.fee_e.get_amount() - outputs = self.payto_e.get_outputs() + outputs = self.payto_e.get_outputs(False) if not is_fee: fee = None @@ -1034,7 +1034,12 @@ class ElectrumWindow(QMainWindow): if self.payment_request: outputs = self.payment_request.get_outputs() else: - outputs = self.payto_e.get_outputs() + try: + outputs = self.payto_e.get_outputs() + except ValueError as e: + traceback.print_exc(file=sys.stdout) + self.show_message(str(e)) + return if not outputs: QMessageBox.warning(self, _('Error'), _('No outputs'), _('OK')) diff --git a/gui/qt/paytoedit.py b/gui/qt/paytoedit.py index 8b3e24c3d..18f62505f 100644 --- a/gui/qt/paytoedit.py +++ b/gui/qt/paytoedit.py @@ -23,6 +23,7 @@ from qrtextedit import QRTextEdit import re from decimal import Decimal from electrum import bitcoin +from electrum.i18n import _ RE_ADDRESS = '[1-9A-HJ-NP-Za-km-z]{26,}' RE_ALIAS = '(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>' @@ -42,6 +43,7 @@ class PayToEdit(QRTextEdit): self.c = None self.textChanged.connect(self.check_text) self.outputs = [] + self.errors = [] self.is_pr = False self.scan_f = self.win.pay_from_URI self.update_size() @@ -94,6 +96,7 @@ class PayToEdit(QRTextEdit): def check_text(self): + self.errors = [] if self.is_pr: return @@ -114,10 +117,11 @@ class PayToEdit(QRTextEdit): self.unlock_amount() return - for line in lines: + for i, line in enumerate(lines): try: type, to_address, amount = self.parse_address_and_amount(line) except: + self.errors.append((i, line.strip())) continue outputs.append((type, to_address, amount)) @@ -139,7 +143,7 @@ class PayToEdit(QRTextEdit): self.unlock_amount() - def get_outputs(self): + def get_outputs(self, show_err=True): if self.payto_address: try: amount = self.amount_edit.get_amount() @@ -148,6 +152,12 @@ class PayToEdit(QRTextEdit): self.outputs = [('address', self.payto_address, amount)] + if self.errors != [] and show_err: + errtext = "" + for x in self.errors: + errtext += _("Line #") + str(x[0]+1) + ": " + x[1] + "\n" + raise ValueError(_("ABORTING! Invalid Lines found:") + "\n\n" + errtext) + return self.outputs[:] From 300125422de86605b80c29ac1bbff5e1f3419b2b Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 6 Sep 2014 15:06:31 +0200 Subject: [PATCH 2/2] separate get_errors instead of raising an exception --- gui/qt/main_window.py | 11 +++++------ gui/qt/paytoedit.py | 13 ++++--------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 2e3d83bff..c02aed956 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -941,7 +941,7 @@ class ElectrumWindow(QMainWindow): amount = self.amount_e.get_amount() fee = self.fee_e.get_amount() - outputs = self.payto_e.get_outputs(False) + outputs = self.payto_e.get_outputs() if not is_fee: fee = None @@ -1034,12 +1034,11 @@ class ElectrumWindow(QMainWindow): if self.payment_request: outputs = self.payment_request.get_outputs() else: - try: - outputs = self.payto_e.get_outputs() - except ValueError as e: - traceback.print_exc(file=sys.stdout) - self.show_message(str(e)) + errors = self.payto_e.get_errors() + if errors: + self.show_warning(_("Invalid Lines found:") + "\n\n" + '\n'.join([ _("Line #") + str(x[0]+1) + ": " + x[1] for x in errors])) return + outputs = self.payto_e.get_outputs() if not outputs: QMessageBox.warning(self, _('Error'), _('No outputs'), _('OK')) diff --git a/gui/qt/paytoedit.py b/gui/qt/paytoedit.py index 18f62505f..4fd961755 100644 --- a/gui/qt/paytoedit.py +++ b/gui/qt/paytoedit.py @@ -23,7 +23,6 @@ from qrtextedit import QRTextEdit import re from decimal import Decimal from electrum import bitcoin -from electrum.i18n import _ RE_ADDRESS = '[1-9A-HJ-NP-Za-km-z]{26,}' RE_ALIAS = '(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>' @@ -143,21 +142,17 @@ class PayToEdit(QRTextEdit): self.unlock_amount() - def get_outputs(self, show_err=True): + def get_errors(self): + return self.errors + + def get_outputs(self): if self.payto_address: try: amount = self.amount_edit.get_amount() except: amount = None - self.outputs = [('address', self.payto_address, amount)] - if self.errors != [] and show_err: - errtext = "" - for x in self.errors: - errtext += _("Line #") + str(x[0]+1) + ": " + x[1] + "\n" - raise ValueError(_("ABORTING! Invalid Lines found:") + "\n\n" + errtext) - return self.outputs[:]