payment_identifier: imports, typing declarations
This commit is contained in:
@@ -11,12 +11,12 @@ from .contacts import AliasNotFoundException
|
|||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .invoices import Invoice
|
from .invoices import Invoice
|
||||||
from .logging import Logger
|
from .logging import Logger
|
||||||
from .util import parse_max_spend, format_satoshis_plain, InvoiceError
|
from .util import parse_max_spend, InvoiceError
|
||||||
from .util import get_asyncio_loop, log_exceptions
|
from .util import get_asyncio_loop, log_exceptions
|
||||||
from .transaction import PartialTxOutput
|
from .transaction import PartialTxOutput
|
||||||
from .lnurl import decode_lnurl, request_lnurl, callback_lnurl, LNURLError, lightning_address_to_url
|
from .lnurl import decode_lnurl, request_lnurl, callback_lnurl, LNURLError, lightning_address_to_url
|
||||||
from .bitcoin import COIN, TOTAL_COIN_SUPPLY_LIMIT_IN_BTC, opcodes, construct_script
|
from .bitcoin import opcodes, construct_script
|
||||||
from .lnaddr import lndecode, LnDecodeException, LnInvoiceException
|
from .lnaddr import LnInvoiceException
|
||||||
from .lnutil import IncompatibleOrInsaneFeatures
|
from .lnutil import IncompatibleOrInsaneFeatures
|
||||||
from .bip21 import parse_bip21_URI, InvalidBitcoinURI, LIGHTNING_URI_SCHEME, BITCOIN_BIP21_URI_SCHEME
|
from .bip21 import parse_bip21_URI, InvalidBitcoinURI, LIGHTNING_URI_SCHEME, BITCOIN_BIP21_URI_SCHEME
|
||||||
from . import paymentrequest
|
from . import paymentrequest
|
||||||
@@ -504,7 +504,7 @@ class PaymentIdentifier(Logger):
|
|||||||
self.logger.debug(f'multiline: {outputs!r}, {self.error}')
|
self.logger.debug(f'multiline: {outputs!r}, {self.error}')
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def parse_address_and_amount(self, line: str) -> 'PartialTxOutput':
|
def parse_address_and_amount(self, line: str) -> PartialTxOutput:
|
||||||
try:
|
try:
|
||||||
x, y = line.split(',')
|
x, y = line.split(',')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -515,7 +515,7 @@ class PaymentIdentifier(Logger):
|
|||||||
amount = self.parse_amount(y)
|
amount = self.parse_amount(y)
|
||||||
return PartialTxOutput(scriptpubkey=scriptpubkey, value=amount)
|
return PartialTxOutput(scriptpubkey=scriptpubkey, value=amount)
|
||||||
|
|
||||||
def parse_output(self, x: str) -> Tuple[bytes, bool]:
|
def parse_output(self, x: str) -> Tuple[Optional[bytes], bool]:
|
||||||
try:
|
try:
|
||||||
address = self.parse_address(x)
|
address = self.parse_address(x)
|
||||||
return bytes.fromhex(bitcoin.address_to_script(address)), True
|
return bytes.fromhex(bitcoin.address_to_script(address)), True
|
||||||
@@ -530,7 +530,7 @@ class PaymentIdentifier(Logger):
|
|||||||
|
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
def parse_script(self, x: str):
|
def parse_script(self, x: str) -> str:
|
||||||
script = ''
|
script = ''
|
||||||
for word in x.split():
|
for word in x.split():
|
||||||
if word[0:3] == 'OP_':
|
if word[0:3] == 'OP_':
|
||||||
@@ -541,7 +541,7 @@ class PaymentIdentifier(Logger):
|
|||||||
script += construct_script([word])
|
script += construct_script([word])
|
||||||
return script
|
return script
|
||||||
|
|
||||||
def parse_amount(self, x: str):
|
def parse_amount(self, x: str) -> str | int:
|
||||||
x = x.strip()
|
x = x.strip()
|
||||||
if not x:
|
if not x:
|
||||||
raise Exception("Amount is empty")
|
raise Exception("Amount is empty")
|
||||||
|
|||||||
Reference in New Issue
Block a user