payment_identifier: refactor round_2 to need_finalize/finalize stage
This commit is contained in:
@@ -26,7 +26,6 @@ import sys
|
||||
import time
|
||||
import threading
|
||||
import os
|
||||
import traceback
|
||||
import json
|
||||
import weakref
|
||||
import csv
|
||||
@@ -55,13 +54,10 @@ from electrum import (keystore, ecc, constants, util, bitcoin, commands,
|
||||
from electrum.bitcoin import COIN, is_address
|
||||
from electrum.plugin import run_hook, BasePlugin
|
||||
from electrum.i18n import _
|
||||
from electrum.util import (format_time, get_asyncio_loop,
|
||||
UserCancelled, profiler,
|
||||
bfh, InvalidPassword,
|
||||
UserFacingException,
|
||||
get_new_wallet_name, send_exception_to_crash_reporter,
|
||||
from electrum.util import (format_time, UserCancelled, profiler, bfh, InvalidPassword,
|
||||
UserFacingException, get_new_wallet_name, send_exception_to_crash_reporter,
|
||||
AddTransactionException, os_chmod)
|
||||
from electrum.payment_identifier import FailedToParsePaymentIdentifier, BITCOIN_BIP21_URI_SCHEME
|
||||
from electrum.payment_identifier import BITCOIN_BIP21_URI_SCHEME, PaymentIdentifier
|
||||
from electrum.invoices import PR_PAID, Invoice
|
||||
from electrum.transaction import (Transaction, PartialTxInput,
|
||||
PartialTransaction, PartialTxOutput)
|
||||
@@ -1329,11 +1325,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
return None
|
||||
return clayout.selected_index()
|
||||
|
||||
def handle_payment_identifier(self, *args, **kwargs):
|
||||
try:
|
||||
self.send_tab.handle_payment_identifier(*args, **kwargs)
|
||||
except FailedToParsePaymentIdentifier as e:
|
||||
self.show_error(str(e))
|
||||
def handle_payment_identifier(self, text: str):
|
||||
pi = PaymentIdentifier(self.wallet, text)
|
||||
if pi.is_valid():
|
||||
self.send_tab.set_payment_identifier(text)
|
||||
else:
|
||||
if pi.error:
|
||||
self.show_error(str(pi.error))
|
||||
|
||||
def set_frozen_state_of_addresses(self, addrs, freeze: bool):
|
||||
self.wallet.set_frozen_state_of_addresses(addrs, freeze)
|
||||
|
||||
@@ -23,22 +23,16 @@
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import re
|
||||
import decimal
|
||||
from functools import partial
|
||||
from decimal import Decimal
|
||||
from typing import NamedTuple, Sequence, Optional, List, TYPE_CHECKING
|
||||
|
||||
from PyQt5.QtGui import QFontMetrics, QFont
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QTextEdit, QVBoxLayout
|
||||
|
||||
from electrum import bitcoin
|
||||
from electrum.i18n import _
|
||||
from electrum.util import parse_max_spend
|
||||
from electrum.payment_identifier import PaymentIdentifier, FailedToParsePaymentIdentifier
|
||||
from electrum.transaction import PartialTxOutput
|
||||
from electrum.bitcoin import opcodes, construct_script
|
||||
from electrum.payment_identifier import PaymentIdentifier
|
||||
from electrum.logging import Logger
|
||||
from electrum.lnurl import LNURLError
|
||||
|
||||
from .qrtextedit import ScanQRTextEdit
|
||||
from .completion_text_edit import CompletionTextEdit
|
||||
@@ -214,9 +208,15 @@ class PayToEdit(Logger, GenericInputHandler):
|
||||
if self.disable_checks:
|
||||
return
|
||||
pi = PaymentIdentifier(self.send_tab.wallet, text)
|
||||
self.is_multiline = bool(pi.multiline_outputs)
|
||||
self.is_multiline = bool(pi.multiline_outputs) # TODO: why both is_multiline and set_paytomany(True)??
|
||||
self.logger.debug(f'is_multiline {self.is_multiline}')
|
||||
self.send_tab.handle_payment_identifier(pi, can_use_network=full_check)
|
||||
if pi.is_valid():
|
||||
self.send_tab.set_payment_identifier(text)
|
||||
else:
|
||||
if not full_check and pi.error:
|
||||
self.send_tab.show_error(
|
||||
_('Clipboard text is not a valid payment identifier') + '\n' + str(pi.error))
|
||||
return
|
||||
|
||||
def handle_multiline(self, outputs):
|
||||
total = 0
|
||||
|
||||
@@ -4,21 +4,19 @@
|
||||
|
||||
import asyncio
|
||||
from decimal import Decimal
|
||||
from typing import Optional, TYPE_CHECKING, Sequence, List, Callable, Any
|
||||
from typing import Optional, TYPE_CHECKING, Sequence, List, Callable
|
||||
from PyQt5.QtCore import pyqtSignal, QPoint
|
||||
from PyQt5.QtWidgets import (QLabel, QVBoxLayout, QGridLayout,
|
||||
QHBoxLayout, QCompleter, QWidget, QToolTip, QPushButton)
|
||||
|
||||
from electrum import util, paymentrequest
|
||||
from electrum import lnutil
|
||||
from electrum.plugin import run_hook
|
||||
from electrum.i18n import _
|
||||
|
||||
from electrum.util import get_asyncio_loop, NotEnoughFunds, NoDynamicFeeEstimates, InvoiceError, parse_max_spend
|
||||
from electrum.payment_identifier import PaymentIdentifier, FailedToParsePaymentIdentifier, InvalidBitcoinURI
|
||||
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, parse_max_spend
|
||||
from electrum.payment_identifier import PaymentIdentifier
|
||||
from electrum.invoices import PR_PAID, Invoice, PR_BROADCASTING, PR_BROADCAST
|
||||
|
||||
from electrum.transaction import Transaction, PartialTxInput, PartialTransaction, PartialTxOutput
|
||||
from electrum.transaction import Transaction, PartialTxInput, PartialTxOutput
|
||||
from electrum.network import TxBroadcastError, BestEffortRequestFailed
|
||||
from electrum.logging import Logger
|
||||
|
||||
@@ -34,7 +32,7 @@ if TYPE_CHECKING:
|
||||
class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
|
||||
resolve_done_signal = pyqtSignal(object)
|
||||
round_2_signal = pyqtSignal(object)
|
||||
finalize_done_signal = pyqtSignal(object)
|
||||
round_3_signal = pyqtSignal(object)
|
||||
|
||||
def __init__(self, window: 'ElectrumWindow'):
|
||||
@@ -184,7 +182,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
run_hook('create_send_tab', grid)
|
||||
|
||||
self.resolve_done_signal.connect(self.on_resolve_done)
|
||||
self.round_2_signal.connect(self.on_round_2)
|
||||
self.finalize_done_signal.connect(self.on_round_2)
|
||||
self.round_3_signal.connect(self.on_round_3)
|
||||
|
||||
def do_paste(self):
|
||||
@@ -203,7 +201,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.payto_e.text_edit.setText(text)
|
||||
else:
|
||||
self.payto_e.setTextNoCheck(text)
|
||||
self.handle_payment_identifier(can_use_network=True)
|
||||
self._handle_payment_identifier(can_use_network=True)
|
||||
|
||||
def spend_max(self):
|
||||
if run_hook('abort_send', self):
|
||||
@@ -372,7 +370,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
self.set_field_style(self.amount_e, amount, validated)
|
||||
self.set_field_style(self.fiat_send_e, amount, validated)
|
||||
|
||||
def handle_payment_identifier(self, *, can_use_network: bool = True):
|
||||
def _handle_payment_identifier(self, *, can_use_network: bool = True):
|
||||
is_valid = self.payment_identifier.is_valid()
|
||||
self.save_button.setEnabled(is_valid)
|
||||
self.send_button.setEnabled(is_valid)
|
||||
@@ -456,10 +454,10 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
||||
|
||||
def do_pay_or_get_invoice(self):
|
||||
pi = self.payment_identifier
|
||||
if pi.needs_round_2():
|
||||
coro = pi.round_2(self.round_2_signal.emit, amount_sat=self.get_amount(), comment=self.message_e.text())
|
||||
asyncio.run_coroutine_threadsafe(coro, get_asyncio_loop()) # TODO should be cancellable
|
||||
if pi.need_finalize():
|
||||
self.prepare_for_send_tab_network_lookup()
|
||||
pi.finalize(amount_sat=self.get_amount(), comment=self.message_e.text(),
|
||||
on_finished=self.finalize_done_signal.emit)
|
||||
return
|
||||
self.pending_invoice = self.read_invoice()
|
||||
if not self.pending_invoice:
|
||||
|
||||
Reference in New Issue
Block a user