commit d1c262def078098599220d6ae189a90700ece0c9
parent 97056ae44dca6775c8aff56033ff461060984079
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 19 Nov 2019 22:17:52 +0100
qt tx dialog: small clean-up in constructors
Diffstat:
3 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/electrum/gui/qt/confirm_tx_dialog.py b/electrum/gui/qt/confirm_tx_dialog.py
@@ -23,14 +23,14 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-from typing import TYPE_CHECKING, Optional
+from typing import TYPE_CHECKING, Optional, Union
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout, QPushButton, QLineEdit
from electrum.i18n import _
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
from electrum.plugin import run_hook
-from electrum.transaction import Transaction
+from electrum.transaction import Transaction, PartialTransaction
from electrum.simple_config import FEERATE_WARNING_HIGH_FEE
from electrum.wallet import InternalAddressCorruption
@@ -45,11 +45,12 @@ if TYPE_CHECKING:
class TxEditor:
- def __init__(self, window: 'ElectrumWindow', make_tx, output_value, is_sweep):
+ def __init__(self, *, window: 'ElectrumWindow', make_tx,
+ output_value: Union[int, str] = None, is_sweep: bool):
self.main_window = window
self.make_tx = make_tx
self.output_value = output_value
- self.tx = None # type: Optional[Transaction]
+ self.tx = None # type: Optional[PartialTransaction]
self.config = window.config
self.wallet = window.wallet
self.not_enough_funds = False
@@ -115,9 +116,9 @@ class TxEditor:
class ConfirmTxDialog(TxEditor, WindowModalDialog):
# set fee and return password (after pw check)
- def __init__(self, window: 'ElectrumWindow', make_tx, output_value, is_sweep):
+ def __init__(self, *, window: 'ElectrumWindow', make_tx, output_value: Union[int, str], is_sweep: bool):
- TxEditor.__init__(self, window, make_tx, output_value, is_sweep)
+ TxEditor.__init__(self, window=window, make_tx=make_tx, output_value=output_value, is_sweep=is_sweep)
WindowModalDialog.__init__(self, window, _("Confirm Transaction"))
vbox = QVBoxLayout()
self.setLayout(vbox)
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
@@ -1478,7 +1478,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def get_manually_selected_coins(self) -> Sequence[PartialTxInput]:
return self.utxo_list.get_spend_list()
- def pay_onchain_dialog(self, inputs, outputs, invoice=None, external_keypairs=None):
+ def pay_onchain_dialog(self, inputs: Sequence[PartialTxInput],
+ outputs: List[PartialTxOutput], *,
+ invoice=None, external_keypairs=None) -> None:
# trustedcoin requires this
if run_hook('abort_send', self):
return
@@ -1493,11 +1495,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.show_error(_("More than one output set to spend max"))
return
if self.config.get('advanced_preview'):
- self.preview_tx_dialog(make_tx, outputs, external_keypairs=external_keypairs, invoice=invoice)
+ self.preview_tx_dialog(make_tx=make_tx,
+ external_keypairs=external_keypairs,
+ invoice=invoice)
return
output_value = '!' if '!' in output_values else sum(output_values)
- d = ConfirmTxDialog(self, make_tx, output_value, is_sweep)
+ d = ConfirmTxDialog(window=self, make_tx=make_tx, output_value=output_value, is_sweep=is_sweep)
d.update_tx()
if d.not_enough_funds:
self.show_message(_('Not Enough Funds'))
@@ -1509,15 +1513,19 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def sign_done(success):
if success:
self.broadcast_or_show(tx, invoice=invoice)
- self.sign_tx_with_password(tx, sign_done, password, external_keypairs)
+ self.sign_tx_with_password(tx, callback=sign_done, password=password,
+ external_keypairs=external_keypairs)
else:
- self.preview_tx_dialog(make_tx, outputs, external_keypairs=external_keypairs, invoice=invoice)
+ self.preview_tx_dialog(make_tx=make_tx,
+ external_keypairs=external_keypairs,
+ invoice=invoice)
- def preview_tx_dialog(self, make_tx, outputs, external_keypairs=None, invoice=None):
- d = PreviewTxDialog(make_tx, outputs, external_keypairs, window=self, invoice=invoice)
+ def preview_tx_dialog(self, *, make_tx, external_keypairs=None, invoice=None):
+ d = PreviewTxDialog(make_tx=make_tx, external_keypairs=external_keypairs,
+ window=self, invoice=invoice)
d.show()
- def broadcast_or_show(self, tx, invoice=None):
+ def broadcast_or_show(self, tx, *, invoice=None):
if not self.network:
self.show_error(_("You can't broadcast a transaction without a live network connection."))
self.show_transaction(tx, invoice=invoice)
@@ -1527,10 +1535,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.broadcast_transaction(tx, invoice=invoice)
@protected
- def sign_tx(self, tx, callback, external_keypairs, password):
- self.sign_tx_with_password(tx, callback, password, external_keypairs=external_keypairs)
+ def sign_tx(self, tx, *, callback, external_keypairs, password):
+ self.sign_tx_with_password(tx, callback=callback, password=password, external_keypairs=external_keypairs)
- def sign_tx_with_password(self, tx: PartialTransaction, callback, password, external_keypairs=None):
+ def sign_tx_with_password(self, tx: PartialTransaction, *, callback, password, external_keypairs=None):
'''Sign the transaction in a separate thread. When done, calls
the callback with a success code of True or False.
'''
@@ -1606,7 +1614,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
# we need to know the fee before we broadcast, because the txid is required
# however, the user must not be allowed to broadcast early
make_tx = self.mktx_for_open_channel(funding_sat)
- d = ConfirmTxDialog(self, make_tx, funding_sat, False)
+ d = ConfirmTxDialog(window=self, make_tx=make_tx, output_value=funding_sat, is_sweep=False)
cancelled, is_send, password, funding_tx = d.run()
if not is_send:
return
diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py
@@ -291,7 +291,7 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
self.sign_button.setDisabled(True)
self.main_window.push_top_level_window(self)
- self.main_window.sign_tx(self.tx, sign_done, self.external_keypairs)
+ self.main_window.sign_tx(self.tx, callback=sign_done, external_keypairs=self.external_keypairs)
def save(self):
self.main_window.push_top_level_window(self)
@@ -601,9 +601,10 @@ class TxDialog(BaseTxDialog):
class PreviewTxDialog(BaseTxDialog, TxEditor):
- def __init__(self, make_tx, outputs, external_keypairs, *, window: 'ElectrumWindow', invoice):
- TxEditor.__init__(self, window, make_tx, outputs, is_sweep=bool(external_keypairs))
- BaseTxDialog.__init__(self, parent=window, invoice=invoice, desc='', prompt_if_unsaved=False, finalized=False, external_keypairs=external_keypairs)
+ def __init__(self, *, make_tx, external_keypairs, window: 'ElectrumWindow', invoice):
+ TxEditor.__init__(self, window=window, make_tx=make_tx, is_sweep=bool(external_keypairs))
+ BaseTxDialog.__init__(self, parent=window, invoice=invoice, desc='', prompt_if_unsaved=False,
+ finalized=False, external_keypairs=external_keypairs)
self.update_tx()
self.update()