qt send tab: fix tx_size and fee calc in case of payment requests
do_update_fee() was always setting `outputs = self.payto_e.get_outputs(...)` but this only works `if not self.payment_request` Minor refactor to re-use logic instead of duplicating code.
This commit is contained in:
@@ -1423,15 +1423,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
self.not_enough_funds = False
|
self.not_enough_funds = False
|
||||||
self.statusBar().showMessage('')
|
self.statusBar().showMessage('')
|
||||||
else:
|
else:
|
||||||
fee_estimator = self.get_send_fee_estimator()
|
outputs, fee_estimator, tx_desc, coins = self.read_send_tab()
|
||||||
outputs = self.payto_e.get_outputs(self.max_button.isChecked())
|
|
||||||
if not outputs:
|
if not outputs:
|
||||||
_type, addr = self.get_payto_or_dummy()
|
_type, addr = self.get_payto_or_dummy()
|
||||||
outputs = [TxOutput(_type, addr, amount)]
|
outputs = [TxOutput(_type, addr, amount)]
|
||||||
is_sweep = bool(self.tx_external_keypairs)
|
is_sweep = bool(self.tx_external_keypairs)
|
||||||
make_tx = lambda fee_est: \
|
make_tx = lambda fee_est: \
|
||||||
self.wallet.make_unsigned_transaction(
|
self.wallet.make_unsigned_transaction(
|
||||||
self.get_coins(), outputs, self.config,
|
coins, outputs, self.config,
|
||||||
fixed_fee=fee_est, is_sweep=is_sweep)
|
fixed_fee=fee_est, is_sweep=is_sweep)
|
||||||
try:
|
try:
|
||||||
tx = make_tx(fee_estimator)
|
tx = make_tx(fee_estimator)
|
||||||
@@ -1580,19 +1579,28 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
return fee_estimator
|
return fee_estimator
|
||||||
|
|
||||||
def read_send_tab(self):
|
def read_send_tab(self):
|
||||||
if self.payment_request and self.payment_request.has_expired():
|
|
||||||
self.show_error(_('Payment request has expired'))
|
|
||||||
return
|
|
||||||
label = self.message_e.text()
|
label = self.message_e.text()
|
||||||
|
|
||||||
if self.payment_request:
|
if self.payment_request:
|
||||||
outputs = self.payment_request.get_outputs()
|
outputs = self.payment_request.get_outputs()
|
||||||
else:
|
else:
|
||||||
|
outputs = self.payto_e.get_outputs(self.max_button.isChecked())
|
||||||
|
fee_estimator = self.get_send_fee_estimator()
|
||||||
|
coins = self.get_coins()
|
||||||
|
return outputs, fee_estimator, label, coins
|
||||||
|
|
||||||
|
def check_send_tab_outputs_and_show_errors(self, outputs) -> bool:
|
||||||
|
"""Returns whether there are errors with outputs.
|
||||||
|
Also shows error dialog to user if so.
|
||||||
|
"""
|
||||||
|
if self.payment_request and self.payment_request.has_expired():
|
||||||
|
self.show_error(_('Payment request has expired'))
|
||||||
|
return True
|
||||||
|
|
||||||
|
if not self.payment_request:
|
||||||
errors = self.payto_e.get_errors()
|
errors = self.payto_e.get_errors()
|
||||||
if errors:
|
if errors:
|
||||||
self.show_warning(_("Invalid Lines found:") + "\n\n" + '\n'.join([ _("Line #") + str(x[0]+1) + ": " + x[1] for x in errors]))
|
self.show_warning(_("Invalid Lines found:") + "\n\n" + '\n'.join([ _("Line #") + str(x[0]+1) + ": " + x[1] for x in errors]))
|
||||||
return
|
return True
|
||||||
outputs = self.payto_e.get_outputs(self.max_button.isChecked())
|
|
||||||
|
|
||||||
if self.payto_e.is_alias and self.payto_e.validated is False:
|
if self.payto_e.is_alias and self.payto_e.validated is False:
|
||||||
alias = self.payto_e.toPlainText()
|
alias = self.payto_e.toPlainText()
|
||||||
@@ -1600,26 +1608,24 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
'security check, DNSSEC, and thus may not be correct.').format(alias) + '\n'
|
'security check, DNSSEC, and thus may not be correct.').format(alias) + '\n'
|
||||||
msg += _('Do you wish to continue?')
|
msg += _('Do you wish to continue?')
|
||||||
if not self.question(msg):
|
if not self.question(msg):
|
||||||
return
|
return True
|
||||||
|
|
||||||
if not outputs:
|
if not outputs:
|
||||||
self.show_error(_('No outputs'))
|
self.show_error(_('No outputs'))
|
||||||
return
|
return True
|
||||||
|
|
||||||
for o in outputs:
|
for o in outputs:
|
||||||
if o.address is None:
|
if o.address is None:
|
||||||
self.show_error(_('Bitcoin Address is None'))
|
self.show_error(_('Bitcoin Address is None'))
|
||||||
return
|
return True
|
||||||
if o.type == TYPE_ADDRESS and not bitcoin.is_address(o.address):
|
if o.type == TYPE_ADDRESS and not bitcoin.is_address(o.address):
|
||||||
self.show_error(_('Invalid Bitcoin Address'))
|
self.show_error(_('Invalid Bitcoin Address'))
|
||||||
return
|
return True
|
||||||
if o.value is None:
|
if o.value is None:
|
||||||
self.show_error(_('Invalid Amount'))
|
self.show_error(_('Invalid Amount'))
|
||||||
return
|
return True
|
||||||
|
|
||||||
fee_estimator = self.get_send_fee_estimator()
|
return False # no errors
|
||||||
coins = self.get_coins()
|
|
||||||
return outputs, fee_estimator, label, coins
|
|
||||||
|
|
||||||
def do_preview(self):
|
def do_preview(self):
|
||||||
self.do_send(preview = True)
|
self.do_send(preview = True)
|
||||||
@@ -1627,10 +1633,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||||||
def do_send(self, preview = False):
|
def do_send(self, preview = False):
|
||||||
if run_hook('abort_send', self):
|
if run_hook('abort_send', self):
|
||||||
return
|
return
|
||||||
r = self.read_send_tab()
|
outputs, fee_estimator, tx_desc, coins = self.read_send_tab()
|
||||||
if not r:
|
if self.check_send_tab_outputs_and_show_errors(outputs):
|
||||||
return
|
return
|
||||||
outputs, fee_estimator, tx_desc, coins = r
|
|
||||||
try:
|
try:
|
||||||
is_sweep = bool(self.tx_external_keypairs)
|
is_sweep = bool(self.tx_external_keypairs)
|
||||||
tx = self.wallet.make_unsigned_transaction(
|
tx = self.wallet.make_unsigned_transaction(
|
||||||
|
|||||||
Reference in New Issue
Block a user