fix lnaddress mypy issue
This commit is contained in:
parent
301a784e95
commit
8b60c64ade
8 changed files with 31 additions and 32 deletions
|
|
@ -16,7 +16,7 @@ async def cloudflare_create_record(domain: Domains, ip: str):
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
cf_response = ""
|
cf_response = {}
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
try:
|
||||||
r = await client.post(
|
r = await client.post(
|
||||||
|
|
@ -31,9 +31,9 @@ async def cloudflare_create_record(domain: Domains, ip: str):
|
||||||
},
|
},
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
cf_response = json.loads(r.text)
|
cf_response = r.json()
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
cf_response = "Error occured"
|
cf_response = {"error": "Error occured"}
|
||||||
return cf_response
|
return cf_response
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,3 +53,4 @@ async def cloudflare_deleterecord(domain: Domains, domain_id: str):
|
||||||
cf_response = r.text
|
cf_response = r.text
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
cf_response = "Error occured"
|
cf_response = "Error occured"
|
||||||
|
return cf_response
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ async def get_addresses(wallet_ids: Union[str, List[str]]) -> List[Addresses]:
|
||||||
|
|
||||||
async def set_address_paid(payment_hash: str) -> Addresses:
|
async def set_address_paid(payment_hash: str) -> Addresses:
|
||||||
address = await get_address(payment_hash)
|
address = await get_address(payment_hash)
|
||||||
|
assert address
|
||||||
|
|
||||||
if address.paid == False:
|
if address.paid == False:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
|
|
@ -146,6 +147,7 @@ async def set_address_paid(payment_hash: str) -> Addresses:
|
||||||
|
|
||||||
async def set_address_renewed(address_id: str, duration: int):
|
async def set_address_renewed(address_id: str, duration: int):
|
||||||
address = await get_address(address_id)
|
address = await get_address(address_id)
|
||||||
|
assert address
|
||||||
|
|
||||||
extend_duration = int(address.duration) + duration
|
extend_duration = int(address.duration) + duration
|
||||||
await db.execute(
|
await db.execute(
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,9 @@
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi.params import Query
|
from fastapi import Query, Request
|
||||||
from lnurl import ( # type: ignore
|
from lnurl import LnurlErrorResponse
|
||||||
LnurlErrorResponse,
|
|
||||||
LnurlPayActionResponse,
|
|
||||||
LnurlPayResponse,
|
|
||||||
)
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from starlette.requests import Request
|
|
||||||
from starlette.responses import HTMLResponse
|
|
||||||
|
|
||||||
from . import lnaddress_ext
|
from . import lnaddress_ext
|
||||||
from .crud import get_address, get_address_by_username, get_domain
|
from .crud import get_address, get_address_by_username, get_domain
|
||||||
|
|
@ -52,6 +44,7 @@ async def lnurl_callback(address_id, amount: int = Query(...)):
|
||||||
amount_received = amount
|
amount_received = amount
|
||||||
|
|
||||||
domain = await get_domain(address.domain)
|
domain = await get_domain(address.domain)
|
||||||
|
assert domain
|
||||||
|
|
||||||
base_url = (
|
base_url = (
|
||||||
address.wallet_endpoint[:-1]
|
address.wallet_endpoint[:-1]
|
||||||
|
|
@ -79,7 +72,7 @@ async def lnurl_callback(address_id, amount: int = Query(...)):
|
||||||
)
|
)
|
||||||
|
|
||||||
r = call.json()
|
r = call.json()
|
||||||
except AssertionError as e:
|
except Exception:
|
||||||
return LnurlErrorResponse(reason="ERROR")
|
return LnurlErrorResponse(reason="ERROR")
|
||||||
|
|
||||||
# resp = LnurlPayActionResponse(pr=r["payment_request"], routes=[])
|
# resp = LnurlPayActionResponse(pr=r["payment_request"], routes=[])
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import json
|
import json
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from fastapi.params import Query
|
from fastapi import Query
|
||||||
from lnurl.types import LnurlPayMetadata
|
from lnurl.types import LnurlPayMetadata
|
||||||
from pydantic.main import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class CreateDomain(BaseModel):
|
class CreateDomain(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from lnbits.core.models import Payment
|
from lnbits.core.models import Payment
|
||||||
from lnbits.helpers import get_current_extension_name
|
from lnbits.helpers import get_current_extension_name
|
||||||
|
|
@ -21,7 +22,9 @@ async def wait_for_paid_invoices():
|
||||||
async def call_webhook_on_paid(payment_hash):
|
async def call_webhook_on_paid(payment_hash):
|
||||||
### Use webhook to notify about cloudflare registration
|
### Use webhook to notify about cloudflare registration
|
||||||
address = await get_address(payment_hash)
|
address = await get_address(payment_hash)
|
||||||
|
assert address
|
||||||
domain = await get_domain(address.domain)
|
domain = await get_domain(address.domain)
|
||||||
|
assert domain
|
||||||
|
|
||||||
if not domain.webhook:
|
if not domain.webhook:
|
||||||
return
|
return
|
||||||
|
|
@ -39,24 +42,24 @@ async def call_webhook_on_paid(payment_hash):
|
||||||
},
|
},
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
except AssertionError:
|
r.raise_for_status()
|
||||||
webhook = None
|
except Exception as e:
|
||||||
|
logger.error(f"lnaddress: error calling webhook on paid: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
async def on_invoice_paid(payment: Payment) -> None:
|
async def on_invoice_paid(payment: Payment) -> None:
|
||||||
|
if not payment.extra:
|
||||||
|
return
|
||||||
if payment.extra.get("tag") == "lnaddress":
|
if payment.extra.get("tag") == "lnaddress":
|
||||||
|
|
||||||
await payment.set_pending(False)
|
await payment.set_pending(False)
|
||||||
await set_address_paid(payment_hash=payment.payment_hash)
|
await set_address_paid(payment_hash=payment.payment_hash)
|
||||||
await call_webhook_on_paid(payment_hash=payment.payment_hash)
|
await call_webhook_on_paid(payment_hash=payment.payment_hash)
|
||||||
|
|
||||||
elif payment.extra.get("tag") == "renew lnaddress":
|
elif payment.extra.get("tag") == "renew lnaddress":
|
||||||
|
|
||||||
await payment.set_pending(False)
|
await payment.set_pending(False)
|
||||||
await set_address_renewed(
|
await set_address_renewed(
|
||||||
address_id=payment.extra["id"], duration=payment.extra["duration"]
|
address_id=payment.extra["id"], duration=payment.extra["duration"]
|
||||||
)
|
)
|
||||||
await call_webhook_on_paid(payment_hash=payment.payment_hash)
|
await call_webhook_on_paid(payment_hash=payment.payment_hash)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Depends, HTTPException, Request
|
||||||
from fastapi.params import Depends
|
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.exceptions import HTTPException
|
|
||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from lnbits.core.crud import get_wallet
|
from lnbits.core.crud import get_wallet
|
||||||
|
|
@ -35,6 +33,7 @@ async def display(domain_id, request: Request):
|
||||||
await purge_addresses(domain_id)
|
await purge_addresses(domain_id)
|
||||||
|
|
||||||
wallet = await get_wallet(domain.wallet)
|
wallet = await get_wallet(domain.wallet)
|
||||||
|
assert wallet
|
||||||
url = urlparse(str(request.url))
|
url = urlparse(str(request.url))
|
||||||
|
|
||||||
return lnaddress_renderer().TemplateResponse(
|
return lnaddress_renderer().TemplateResponse(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Depends, HTTPException, Query, Request
|
||||||
from fastapi.params import Depends, Query
|
|
||||||
from starlette.exceptions import HTTPException
|
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.core.services import check_transaction_status, create_invoice
|
from lnbits.core.services import check_transaction_status, create_invoice
|
||||||
|
|
@ -11,7 +9,7 @@ from lnbits.decorators import WalletTypeInfo, get_key_type
|
||||||
from lnbits.extensions.lnaddress.models import CreateAddress, CreateDomain
|
from lnbits.extensions.lnaddress.models import CreateAddress, CreateDomain
|
||||||
|
|
||||||
from . import lnaddress_ext
|
from . import lnaddress_ext
|
||||||
from .cloudflare import cloudflare_create_record, cloudflare_deleterecord
|
from .cloudflare import cloudflare_create_record
|
||||||
from .crud import (
|
from .crud import (
|
||||||
check_address_available,
|
check_address_available,
|
||||||
create_address,
|
create_address,
|
||||||
|
|
@ -35,7 +33,8 @@ async def api_domains(
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(g.wallet.user)).wallet_ids
|
user = await get_user(g.wallet.user)
|
||||||
|
wallet_ids = user.wallet_ids if user else []
|
||||||
|
|
||||||
return [domain.dict() for domain in await get_domains(wallet_ids)]
|
return [domain.dict() for domain in await get_domains(wallet_ids)]
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ async def api_domain_create(
|
||||||
|
|
||||||
cf_response = await cloudflare_create_record(domain=domain, ip=root_url)
|
cf_response = await cloudflare_create_record(domain=domain, ip=root_url)
|
||||||
|
|
||||||
if not cf_response or cf_response["success"] != True:
|
if not cf_response or not cf_response["success"]:
|
||||||
await delete_domain(domain.id)
|
await delete_domain(domain.id)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
|
|
@ -106,7 +105,8 @@ async def api_addresses(
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
wallet_ids = (await get_user(g.wallet.user)).wallet_ids
|
user = await get_user(g.wallet.user)
|
||||||
|
wallet_ids = user.wallet_ids if user else []
|
||||||
|
|
||||||
return [address.dict() for address in await get_addresses(wallet_ids)]
|
return [address.dict() for address in await get_addresses(wallet_ids)]
|
||||||
|
|
||||||
|
|
@ -227,7 +227,9 @@ async def api_lnaddress_make_address(
|
||||||
@lnaddress_ext.get("/api/v1/addresses/{payment_hash}")
|
@lnaddress_ext.get("/api/v1/addresses/{payment_hash}")
|
||||||
async def api_address_send_address(payment_hash):
|
async def api_address_send_address(payment_hash):
|
||||||
address = await get_address(payment_hash)
|
address = await get_address(payment_hash)
|
||||||
|
assert address
|
||||||
domain = await get_domain(address.domain)
|
domain = await get_domain(address.domain)
|
||||||
|
assert domain
|
||||||
try:
|
try:
|
||||||
status = await check_transaction_status(domain.wallet, payment_hash)
|
status = await check_transaction_status(domain.wallet, payment_hash)
|
||||||
is_paid = not status.pending
|
is_paid = not status.pending
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ exclude = """(?x)(
|
||||||
| ^lnbits/extensions/boltz.
|
| ^lnbits/extensions/boltz.
|
||||||
| ^lnbits/extensions/boltcards.
|
| ^lnbits/extensions/boltcards.
|
||||||
| ^lnbits/extensions/livestream.
|
| ^lnbits/extensions/livestream.
|
||||||
| ^lnbits/extensions/lnaddress.
|
|
||||||
| ^lnbits/extensions/lnurldevice.
|
| ^lnbits/extensions/lnurldevice.
|
||||||
| ^lnbits/extensions/satspay.
|
| ^lnbits/extensions/satspay.
|
||||||
| ^lnbits/extensions/watchonly.
|
| ^lnbits/extensions/watchonly.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue