lnbits-legend/lnbits/extensions/lnurlpos/models.py

62 lines
1.7 KiB
Python
Raw Normal View History

2021-10-20 06:49:59 +01:00
import json
from lnurl import Lnurl, LnurlWithdrawResponse, encode as lnurl_encode # type: ignore
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
from lnurl.types import LnurlPayMetadata # type: ignore
2021-11-03 14:41:36 +00:00
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
2021-10-20 06:49:59 +01:00
from sqlite3 import Row
from typing import NamedTuple, Optional, Dict
import shortuuid # type: ignore
from fastapi.param_functions import Query
from pydantic.main import BaseModel
from pydantic import BaseModel
from typing import Optional
from fastapi import FastAPI, Request
class createLnurlpos(BaseModel):
title: str
wallet: str
currency: str
class lnurlposs(BaseModel):
id: str
key: str
title: str
wallet: str
currency: str
timestamp: str
def from_row(cls, row: Row) -> "lnurlposs":
return cls(**dict(row))
2021-11-03 14:41:36 +00:00
def lnurl(self, req: Request) -> Lnurl:
url = req.url_for("lnurlpos.lnurl_response", pos_id=self.id, _external=True)
2021-10-20 06:49:59 +01:00
return lnurl_encode(url)
2021-11-03 14:41:36 +00:00
async def lnurlpay_metadata(self) -> LnurlPayMetadata:
2021-10-20 06:49:59 +01:00
return LnurlPayMetadata(json.dumps([["text/plain", self.title]]))
2021-11-03 14:41:36 +00:00
def success_action(
self, paymentid: str, req: Request
) -> Optional[LnurlPaySuccessAction]:
return UrlAction(
url=req.url_for("lnurlpos.displaypin", paymentid=paymentid),
description="Check the attached link",
2021-10-20 06:49:59 +01:00
)
class lnurlpospayment(BaseModel):
id: str
posid: str
payhash: str
payload: str
pin: int
sats: int
timestamp: str
@classmethod
def from_row(cls, row: Row) -> "lnurlpospayment":
return cls(**dict(row))