Black
This commit is contained in:
parent
8d4337679f
commit
0057d75422
|
@ -13,11 +13,13 @@ lnurldevice_ext: APIRouter = APIRouter(prefix="/lnurldevice", tags=["lnurldevice
|
||||||
def lnurldevice_renderer():
|
def lnurldevice_renderer():
|
||||||
return template_renderer(["lnbits/extensions/lnurldevice/templates"])
|
return template_renderer(["lnbits/extensions/lnurldevice/templates"])
|
||||||
|
|
||||||
|
|
||||||
from .tasks import wait_for_paid_invoices
|
from .tasks import wait_for_paid_invoices
|
||||||
from .lnurl import * # noqa
|
from .lnurl import * # noqa
|
||||||
from .views import * # noqa
|
from .views import * # noqa
|
||||||
from .views_api import * # noqa
|
from .views_api import * # noqa
|
||||||
|
|
||||||
|
|
||||||
def lnurldevice_start():
|
def lnurldevice_start():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||||
|
|
|
@ -122,7 +122,7 @@ async def lnurl_v1_params(
|
||||||
return {
|
return {
|
||||||
"tag": "payRequest",
|
"tag": "payRequest",
|
||||||
"callback": request.url_for(
|
"callback": request.url_for(
|
||||||
"lnurldevice.lnurl_callback", paymentid=lnurldevicepayment.id
|
"lnurldevice.lnurl_callback", paymentid=lnurldevicepayment.id
|
||||||
),
|
),
|
||||||
"minSendable": price_msat,
|
"minSendable": price_msat,
|
||||||
"maxSendable": price_msat,
|
"maxSendable": price_msat,
|
||||||
|
|
|
@ -80,8 +80,11 @@ async def m002_redux(db):
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def m003_redux(db):
|
async def m003_redux(db):
|
||||||
"""
|
"""
|
||||||
Add 'meta' for storing various metadata about the wallet
|
Add 'meta' for storing various metadata about the wallet
|
||||||
"""
|
"""
|
||||||
await db.execute("ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount INT DEFAULT 0;")
|
await db.execute(
|
||||||
|
"ALTER TABLE lnurldevice.lnurldevices ADD COLUMN amount INT DEFAULT 0;"
|
||||||
|
)
|
||||||
|
|
|
@ -35,9 +35,7 @@ class lnurldevices(BaseModel):
|
||||||
return cls(**dict(row))
|
return cls(**dict(row))
|
||||||
|
|
||||||
def lnurl(self, req: Request) -> Lnurl:
|
def lnurl(self, req: Request) -> Lnurl:
|
||||||
url = req.url_for(
|
url = req.url_for("lnurldevice.lnurl_v1_params", device_id=self.id)
|
||||||
"lnurldevice.lnurl_v1_params", device_id=self.id
|
|
||||||
)
|
|
||||||
return lnurl_encode(url)
|
return lnurl_encode(url)
|
||||||
|
|
||||||
async def lnurlpay_metadata(self) -> LnurlPayMetadata:
|
async def lnurlpay_metadata(self) -> LnurlPayMetadata:
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .crud import get_lnurldevice, get_lnurldevicepayment, update_lnurldevicepay
|
||||||
from .views import updater
|
from .views import updater
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_paid_invoices():
|
async def wait_for_paid_invoices():
|
||||||
invoice_queue = asyncio.Queue()
|
invoice_queue = asyncio.Queue()
|
||||||
register_invoice_listener(invoice_queue, get_current_extension_name())
|
register_invoice_listener(invoice_queue, get_current_extension_name())
|
||||||
|
@ -24,6 +25,7 @@ async def wait_for_paid_invoices():
|
||||||
payment = await invoice_queue.get()
|
payment = await invoice_queue.get()
|
||||||
await on_invoice_paid(payment)
|
await on_invoice_paid(payment)
|
||||||
|
|
||||||
|
|
||||||
async def on_invoice_paid(payment: Payment) -> None:
|
async def on_invoice_paid(payment: Payment) -> None:
|
||||||
# (avoid loops)
|
# (avoid loops)
|
||||||
if "Switch" == payment.extra.get("tag"):
|
if "Switch" == payment.extra.get("tag"):
|
||||||
|
@ -33,7 +35,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
if lnurldevicepayment.payhash == "used":
|
if lnurldevicepayment.payhash == "used":
|
||||||
return
|
return
|
||||||
lnurldevicepayment = await update_lnurldevicepayment(
|
lnurldevicepayment = await update_lnurldevicepayment(
|
||||||
lnurldevicepayment_id=payment.extra.get("id"), payhash="used"
|
lnurldevicepayment_id=payment.extra.get("id"), payhash="used"
|
||||||
)
|
)
|
||||||
return await updater(lnurldevicepayment.deviceid)
|
return await updater(lnurldevicepayment.deviceid)
|
||||||
return
|
return
|
|
@ -57,6 +57,7 @@ async def displaypin(request: Request, paymentid: str = Query(None)):
|
||||||
{"request": request, "pin": "filler", "not_paid": True},
|
{"request": request, "pin": "filler", "not_paid": True},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@lnurldevice_ext.get("/img/{lnurldevice_id}", response_class=StreamingResponse)
|
@lnurldevice_ext.get("/img/{lnurldevice_id}", response_class=StreamingResponse)
|
||||||
async def img(request: Request, lnurldevice_id):
|
async def img(request: Request, lnurldevice_id):
|
||||||
lnurldevice = await get_lnurldevice(lnurldevice_id)
|
lnurldevice = await get_lnurldevice(lnurldevice_id)
|
||||||
|
@ -110,4 +111,3 @@ async def updater(lnurldevice_id):
|
||||||
if not lnurldevice:
|
if not lnurldevice:
|
||||||
return
|
return
|
||||||
await manager.send_personal_message(f"{lnurldevice.amount}", lnurldevice_id)
|
await manager.send_personal_message(f"{lnurldevice.amount}", lnurldevice_id)
|
||||||
|
|
||||||
|
|
|
@ -46,18 +46,20 @@ async def api_lnurldevice_create_or_update(
|
||||||
|
|
||||||
|
|
||||||
@lnurldevice_ext.get("/api/v1/lnurlpos")
|
@lnurldevice_ext.get("/api/v1/lnurlpos")
|
||||||
async def api_lnurldevices_retrieve(req: Request, wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_lnurldevices_retrieve(
|
||||||
|
req: Request, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
|
):
|
||||||
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
|
||||||
try:
|
try:
|
||||||
return [
|
return [
|
||||||
{**lnurldevice.dict(), **{"lnurl": lnurldevice.lnurl(req)}}
|
{**lnurldevice.dict(), **{"lnurl": lnurldevice.lnurl(req)}}
|
||||||
for lnurldevice in await get_lnurldevices(wallet_ids)
|
for lnurldevice in await get_lnurldevices(wallet_ids)
|
||||||
]
|
]
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
return [
|
return [
|
||||||
{**lnurldevice.dict()}
|
{**lnurldevice.dict()}
|
||||||
for lnurldevice in await get_lnurldevices(wallet_ids)
|
for lnurldevice in await get_lnurldevices(wallet_ids)
|
||||||
]
|
]
|
||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user