From dfd75a56d7206bd3961aa7010351a762c339a992 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 15 Jul 2018 17:59:46 +0300 Subject: [PATCH] add externl address output --- shuffle/qt.py | 48 ++++++++++++++++++++++++++++++++++++---------- shuffle/shuffle.py | 10 ++++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/shuffle/qt.py b/shuffle/qt.py index 5e424af..e085bb2 100644 --- a/shuffle/qt.py +++ b/shuffle/qt.py @@ -40,7 +40,8 @@ from electroncash.i18n import _ from electroncash_gui.qt.util import EnterButton, Buttons, CloseButton from electroncash_gui.qt.util import OkButton, WindowModalDialog -from .shuffle import InputAdressWidget, ChangeAdressWidget, OutputAdressWidget, ConsoleOutput, AmountSelect, ServersList +from electroncash.address import Address +from .shuffle import InputAdressWidget, ChangeAdressWidget, OutputAdressWidget, ConsoleOutput, AmountSelect, ServersList, ExternalOutput class ShuffleWidget(QWidget): @@ -68,7 +69,9 @@ def __init__(self, window): self.coinshuffle_inputs = InputAdressWidget(decimal_point = self.window.get_decimal_point) self.coinshuffle_changes = ChangeAdressWidget() self.coinshuffle_fresh_changes = QCheckBox(_('Show only fresh change addresses')) + self.coinshuffle_use_external_output = QCheckBox(_('Use external output address')) self.coinshuffle_outputs = OutputAdressWidget() + self.coinshuffle_external_output = ExternalOutput() self.coinshuffle_amount_radio = AmountSelect(self.coinshuffle_amounts, decimal_point = self.window.get_decimal_point) self.coinshuffle_fee = QLabel(_(self.window.format_amount_and_units(self.coinshuffle_fee_constant))) self.coinshuffle_text_output = ConsoleOutput() @@ -77,6 +80,8 @@ def __init__(self, window): self.coinshuffle_inputs.currentIndexChanged.connect(self.check_sufficient_ammount) self.coinshuffle_amount_radio.button_group.buttonClicked.connect(self.check_sufficient_ammount) self.coinshuffle_fresh_changes.stateChanged.connect(lambda: self.coinshuffle_changes.update(self.window.wallet, fresh_only = self.coinshuffle_fresh_changes.isChecked())) + self.coinshuffle_use_external_output.stateChanged.connect(lambda: self.coinshuffle_change_outputs(self.coinshuffle_use_external_output.isChecked())) + self.coinshuffle_external_output.textChanged.connect(self.check_sufficient_ammount) self.coinshuffle_start_button = EnterButton(_("Shuffle"),lambda :self.start_coinshuffle_protocol()) self.coinshuffle_cancel_button = EnterButton(_("Cancel"),lambda :self.cancel_coinshuffle_protocol()) @@ -87,19 +92,21 @@ def __init__(self, window): self.shuffle_grid.addWidget(QLabel(_('Shuffle input address')), 2, 0) self.shuffle_grid.addWidget(QLabel(_('Shuffle change address')), 3, 0) self.shuffle_grid.addWidget(QLabel(_('Shuffle output address')), 5, 0) - self.shuffle_grid.addWidget(QLabel(_('Amount')), 6, 0) - self.shuffle_grid.addWidget(QLabel(_('Fee')), 7, 0) + self.shuffle_grid.addWidget(QLabel(_('Amount')), 8, 0) + self.shuffle_grid.addWidget(QLabel(_('Fee')), 9, 0) self.shuffle_grid.addWidget(self.coinshuffle_servers, 1, 1,1,-1) self.shuffle_grid.addWidget(self.coinshuffle_fresh_changes, 4, 1) + self.shuffle_grid.addWidget(self.coinshuffle_use_external_output, 6, 1) + self.shuffle_grid.addWidget(self.coinshuffle_external_output, 7, 1, 1, -1) self.shuffle_grid.addWidget(self.coinshuffle_inputs,2,1,1,-1) self.shuffle_grid.addWidget(self.coinshuffle_changes,3,1,1,-1) self.shuffle_grid.addWidget(self.coinshuffle_outputs,5,1,1,-1) - self.shuffle_grid.addWidget(self.coinshuffle_amount_radio,6,1) - self.shuffle_grid.addWidget(self.coinshuffle_fee ,7, 1) - self.shuffle_grid.addWidget(self.coinshuffle_start_button, 8, 0) - self.shuffle_grid.addWidget(self.coinshuffle_cancel_button, 8, 1) - self.shuffle_grid.addWidget(self.coinshuffle_timer_output, 8, 2) - self.shuffle_grid.addWidget(self.coinshuffle_text_output,9,0,1,-1) + self.shuffle_grid.addWidget(self.coinshuffle_amount_radio,8,1) + self.shuffle_grid.addWidget(self.coinshuffle_fee, 9, 1) + self.shuffle_grid.addWidget(self.coinshuffle_start_button, 10, 0) + self.shuffle_grid.addWidget(self.coinshuffle_cancel_button, 10, 1) + self.shuffle_grid.addWidget(self.coinshuffle_timer_output, 10, 2) + self.shuffle_grid.addWidget(self.coinshuffle_text_output, 11, 0, 1, -1) vbox0 = QVBoxLayout() vbox0.addLayout(self.shuffle_grid) @@ -110,6 +117,15 @@ def __init__(self, window): vbox.addStretch(1) + def coinshuffle_change_outputs(self, checked): + if checked: + self.coinshuffle_external_output.setEnabled(True) + self.coinshuffle_outputs.setEnabled(False) + else: + self.coinshuffle_external_output.setEnabled(False) + self.coinshuffle_outputs.setEnabled(True) + self.check_sufficient_ammount() + def update_inputs(self): if not self.coinshuffle_cancel_button.isEnabled(): self.coinshuffle_inputs.update(self.window.wallet) @@ -137,6 +153,9 @@ def check_sufficient_ammount(self): if shuffle_amount and fee: if coin_amount > (fee + shuffle_amount): self.coinshuffle_start_button.setEnabled(True) + if self.coinshuffle_use_external_output.isChecked(): + if not Address.is_valid(self.coinshuffle_external_output.text()): + self.coinshuffle_start_button.setEnabled(False) else: self.coinshuffle_start_button.setEnabled(False) else: @@ -151,6 +170,9 @@ def enable_coinshuffle_settings(self): self.coinshuffle_amount_radio.setEnabled(True) self.waiting_timeout = 180 self.coinshuffle_timer_output.setText("") + self.coinshuffle_use_external_output.setEnabled(True) + self.coinshuffle_external_output.setEnabled(True) + self.coinshuffle_fresh_changes.setEnabled(True) def disable_coinshuffle_settings(self): self.coinshuffle_servers.setEnabled(False) @@ -159,6 +181,9 @@ def disable_coinshuffle_settings(self): self.coinshuffle_changes.setEnabled(False) self.coinshuffle_outputs.setEnabled(False) self.coinshuffle_amount_radio.setEnabled(False) + self.coinshuffle_use_external_output.setEnabled(False) + self.coinshuffle_external_output.setEnabled(False) + self.coinshuffle_fresh_changes.setEnabled(False) def process_protocol_messages(self, message): @@ -237,7 +262,10 @@ def start_coinshuffle_protocol(self): change_address = possible_change_address else: change_address = self.coinshuffle_inputs.get_input_address_as_string() - output_address = self.coinshuffle_outputs.get_output_address() + if self.coinshuffle_use_external_output.isChecked(): + output_address = self.coinshuffle_external_output.text() + else: + output_address = self.coinshuffle_outputs.get_output_address() #disable inputs self.disable_coinshuffle_settings() self.coinshuffle_cancel_button.setEnabled(True) diff --git a/shuffle/shuffle.py b/shuffle/shuffle.py index e7c22c0..764c039 100644 --- a/shuffle/shuffle.py +++ b/shuffle/shuffle.py @@ -289,3 +289,13 @@ def get_current_server(self): server = self.servers_list.get(current_server) server["server"] = current_server return server + + +class ExternalOutput(QLineEdit): + + def __init__(self, parent=None): + QLineEdit.__init__(self, parent) + self.setEnabled(False) + self.q_exp = QRegExp("[13][a-km-zA-HJ-NP-Z1-9]{33}") + self.validator = QRegExpValidator(self.q_exp ,self) + self.setValidator(self.validator)