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

57 lines
1.3 KiB
Python
Raw Normal View History

2021-10-20 06:49:59 +01:00
import json
from sqlite3 import Row
from typing import Optional
from fastapi import Request
from lnurl import Lnurl
from lnurl import encode as lnurl_encode # type: ignore
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
from lnurl.types import LnurlPayMetadata # type: ignore
from pydantic import BaseModel
from pydantic.main import BaseModel
2021-10-20 06:49:59 +01:00
2022-01-21 21:23:32 +00:00
class createLnurldevice(BaseModel):
2021-10-20 06:49:59 +01:00
title: str
wallet: str
currency: str
2022-01-21 21:23:32 +00:00
device: str
profit: float
2022-10-06 17:10:15 +01:00
amount: int
2021-10-20 06:49:59 +01:00
2022-01-21 21:23:32 +00:00
class lnurldevices(BaseModel):
2021-10-20 06:49:59 +01:00
id: str
key: str
title: str
wallet: str
currency: str
2022-01-21 21:23:32 +00:00
device: str
profit: float
2022-10-06 17:10:15 +01:00
amount: int
2021-10-20 06:49:59 +01:00
timestamp: str
2022-01-21 21:23:32 +00:00
def from_row(cls, row: Row) -> "lnurldevices":
2021-10-20 06:49:59 +01:00
return cls(**dict(row))
2021-11-03 14:41:36 +00:00
def lnurl(self, req: Request) -> Lnurl:
2022-10-07 23:18:57 +01:00
url = req.url_for("lnurldevice.lnurl_v1_params", device_id=self.id)
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]]))
2022-01-30 19:43:30 +00:00
2022-01-21 21:23:32 +00:00
class lnurldevicepayment(BaseModel):
2021-10-20 06:49:59 +01:00
id: str
2022-01-21 21:23:32 +00:00
deviceid: str
2021-10-20 06:49:59 +01:00
payhash: str
payload: str
pin: int
sats: int
timestamp: str
@classmethod
2022-01-21 21:23:32 +00:00
def from_row(cls, row: Row) -> "lnurldevicepayment":
2021-10-20 06:49:59 +01:00
return cls(**dict(row))