pass wallet to PaymentIdentifier instead of config and contacts
This commit is contained in:
@@ -213,9 +213,9 @@ class PayToEdit(Logger, GenericInputHandler):
|
|||||||
self.previous_payto = text
|
self.previous_payto = text
|
||||||
if self.disable_checks:
|
if self.disable_checks:
|
||||||
return
|
return
|
||||||
pi = PaymentIdentifier(self.config, self.win.contacts, text)
|
pi = PaymentIdentifier(self.send_tab.wallet, text)
|
||||||
self.is_multiline = bool(pi.multiline_outputs)
|
self.is_multiline = bool(pi.multiline_outputs)
|
||||||
print('is_multiline', self.is_multiline)
|
self.logger.debug(f'is_multiline {self.is_multiline}')
|
||||||
self.send_tab.handle_payment_identifier(pi, can_use_network=full_check)
|
self.send_tab.handle_payment_identifier(pi, can_use_network=full_check)
|
||||||
|
|
||||||
def handle_multiline(self, outputs):
|
def handle_multiline(self, outputs):
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
|||||||
self.set_payment_identifier(text)
|
self.set_payment_identifier(text)
|
||||||
|
|
||||||
def set_payment_identifier(self, text):
|
def set_payment_identifier(self, text):
|
||||||
pi = PaymentIdentifier(self.config, self.window.contacts, text)
|
pi = PaymentIdentifier(self.wallet, text)
|
||||||
if pi.error:
|
if pi.error:
|
||||||
self.show_error(_('Clipboard text is not a valid payment identifier') + '\n' + pi.error)
|
self.show_error(_('Clipboard text is not a valid payment identifier') + '\n' + pi.error)
|
||||||
return
|
return
|
||||||
@@ -356,7 +356,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
|||||||
w.setReadOnly(False)
|
w.setReadOnly(False)
|
||||||
|
|
||||||
def update_fields(self, pi):
|
def update_fields(self, pi):
|
||||||
recipient, amount, description, comment, validated = pi.get_fields_for_GUI(self.wallet)
|
recipient, amount, description, comment, validated = pi.get_fields_for_GUI()
|
||||||
if recipient:
|
if recipient:
|
||||||
self.payto_e.setTextNoCheck(recipient)
|
self.payto_e.setTextNoCheck(recipient)
|
||||||
elif pi.multiline_outputs:
|
elif pi.multiline_outputs:
|
||||||
@@ -408,7 +408,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
|||||||
self.show_error(_('No amount'))
|
self.show_error(_('No amount'))
|
||||||
return
|
return
|
||||||
|
|
||||||
invoice = self.payment_identifier.get_invoice(self.wallet, amount_sat, self.get_message())
|
invoice = self.payment_identifier.get_invoice(amount_sat, self.get_message())
|
||||||
#except Exception as e:
|
#except Exception as e:
|
||||||
if not invoice:
|
if not invoice:
|
||||||
self.show_error('error getting invoice' + self.payment_identifier.error)
|
self.show_error('error getting invoice' + self.payment_identifier.error)
|
||||||
@@ -449,7 +449,7 @@ class SendTab(QWidget, MessageBoxMixin, Logger):
|
|||||||
self.do_clear()
|
self.do_clear()
|
||||||
return
|
return
|
||||||
self.update_fields(pi)
|
self.update_fields(pi)
|
||||||
invoice = pi.get_invoice(self.wallet, self.get_amount(), self.get_message())
|
invoice = pi.get_invoice(self.get_amount(), self.get_message())
|
||||||
self.pending_invoice = invoice
|
self.pending_invoice = invoice
|
||||||
self.do_pay_invoice(invoice)
|
self.do_pay_invoice(invoice)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import asyncio
|
|||||||
import urllib
|
import urllib
|
||||||
import re
|
import re
|
||||||
from decimal import Decimal, InvalidOperation
|
from decimal import Decimal, InvalidOperation
|
||||||
from typing import NamedTuple, Optional, Callable, Any, Sequence, List
|
from typing import NamedTuple, Optional, Callable, Any, Sequence, List, TYPE_CHECKING
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
@@ -16,6 +16,9 @@ from .bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC, opcodes, construct_sc
|
|||||||
from .lnaddr import lndecode, LnDecodeException, LnInvoiceException
|
from .lnaddr import lndecode, LnDecodeException, LnInvoiceException
|
||||||
from .lnutil import IncompatibleOrInsaneFeatures
|
from .lnutil import IncompatibleOrInsaneFeatures
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .wallet import Abstract_Wallet
|
||||||
|
|
||||||
|
|
||||||
def maybe_extract_lightning_payment_identifier(data: str) -> Optional[str]:
|
def maybe_extract_lightning_payment_identifier(data: str) -> Optional[str]:
|
||||||
data = data.strip() # whitespaces
|
data = data.strip() # whitespaces
|
||||||
@@ -184,12 +187,14 @@ class PaymentIdentifier(Logger):
|
|||||||
* lightning-URI (containing bolt11 or lnurl)
|
* lightning-URI (containing bolt11 or lnurl)
|
||||||
* bolt11 invoice
|
* bolt11 invoice
|
||||||
* lnurl
|
* lnurl
|
||||||
|
* TODO: lightning address
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config, contacts, text):
|
def __init__(self, wallet: 'Abstract_Wallet', text):
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
self.contacts = contacts
|
self.wallet = wallet
|
||||||
self.config = config
|
self.contacts = wallet.contacts if wallet is not None else None
|
||||||
|
self.config = wallet.config if wallet is not None else None
|
||||||
self.text = text
|
self.text = text
|
||||||
self._type = None
|
self._type = None
|
||||||
self.error = None # if set, GUI should show error and stop
|
self.error = None # if set, GUI should show error and stop
|
||||||
@@ -307,7 +312,7 @@ class PaymentIdentifier(Logger):
|
|||||||
total += output.value
|
total += output.value
|
||||||
if is_multiline and errors:
|
if is_multiline and errors:
|
||||||
self.error = str(errors) if errors else None
|
self.error = str(errors) if errors else None
|
||||||
print(outputs, self.error)
|
self.logger.debug(f'multiline: {outputs!r}, {self.error}')
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def parse_address_and_amount(self, line) -> 'PartialTxOutput':
|
def parse_address_and_amount(self, line) -> 'PartialTxOutput':
|
||||||
@@ -364,7 +369,7 @@ class PaymentIdentifier(Logger):
|
|||||||
assert bitcoin.is_address(address)
|
assert bitcoin.is_address(address)
|
||||||
return address
|
return address
|
||||||
|
|
||||||
def get_fields_for_GUI(self, wallet):
|
def get_fields_for_GUI(self):
|
||||||
""" sets self.error as side effect"""
|
""" sets self.error as side effect"""
|
||||||
recipient = None
|
recipient = None
|
||||||
amount = None
|
amount = None
|
||||||
@@ -429,7 +434,7 @@ class PaymentIdentifier(Logger):
|
|||||||
if label and not description:
|
if label and not description:
|
||||||
description = label
|
description = label
|
||||||
lightning = self.bip21.get('lightning')
|
lightning = self.bip21.get('lightning')
|
||||||
if lightning and wallet.has_lightning():
|
if lightning and self.wallet.has_lightning():
|
||||||
# maybe set self.bolt11?
|
# maybe set self.bolt11?
|
||||||
recipient, amount, description = self.get_bolt11_fields(lightning)
|
recipient, amount, description = self.get_bolt11_fields(lightning)
|
||||||
if not amount:
|
if not amount:
|
||||||
@@ -540,8 +545,7 @@ class PaymentIdentifier(Logger):
|
|||||||
self.logger.info(f"Payment ACK: {ack_status}. Ack message: {ack_msg}")
|
self.logger.info(f"Payment ACK: {ack_status}. Ack message: {ack_msg}")
|
||||||
on_success(self)
|
on_success(self)
|
||||||
|
|
||||||
def get_invoice(self, wallet, amount_sat, message):
|
def get_invoice(self, amount_sat, message):
|
||||||
# fixme: wallet not really needed, only height
|
|
||||||
from .invoices import Invoice
|
from .invoices import Invoice
|
||||||
if self.is_lightning():
|
if self.is_lightning():
|
||||||
invoice_str = self.bolt11
|
invoice_str = self.bolt11
|
||||||
@@ -555,7 +559,7 @@ class PaymentIdentifier(Logger):
|
|||||||
outputs = self.get_onchain_outputs(amount_sat)
|
outputs = self.get_onchain_outputs(amount_sat)
|
||||||
message = self.bip21.get('message') if self.bip21 else message
|
message = self.bip21.get('message') if self.bip21 else message
|
||||||
bip70_data = self.bip70_data if self.bip70 else None
|
bip70_data = self.bip70_data if self.bip70 else None
|
||||||
return wallet.create_invoice(
|
return self.wallet.create_invoice(
|
||||||
outputs=outputs,
|
outputs=outputs,
|
||||||
message=message,
|
message=message,
|
||||||
pr=bip70_data,
|
pr=bip70_data,
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ def main():
|
|||||||
|
|
||||||
# check if we received a valid payment identifier
|
# check if we received a valid payment identifier
|
||||||
uri = config_options.get('url')
|
uri = config_options.get('url')
|
||||||
if uri and not PaymentIdentifier(None, None, uri).is_valid():
|
if uri and not PaymentIdentifier(None, uri).is_valid():
|
||||||
print_stderr('unknown command:', uri)
|
print_stderr('unknown command:', uri)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user