forked from lnbits/tpos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
123 lines (99 loc) · 3.03 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from sqlite3 import Row
from typing import Optional, Any, List
from fastapi import Request
from lnurl import Lnurl, LnurlWithdrawResponse
from lnurl import encode as lnurl_encode
from lnurl.models import ClearnetUrl, MilliSatoshi
from pydantic import BaseModel, Field
class CreateTposData(BaseModel):
wallet: Optional[str]
name: Optional[str]
currency: Optional[str]
tip_options: str = Field(None)
tip_wallet: str = Field(None)
withdrawlimit: int = Field(None, ge=1)
withdrawpin: int = Field(None, ge=1)
withdrawamt: int = Field(None, ge=0)
withdrawtime: int = Field(0)
withdrawbtwn: int = Field(10, ge=1)
withdrawpremium: float = Field(None)
class TPoS(BaseModel):
id: str
wallet: str
name: str
currency: str
tip_options: Optional[str]
tip_wallet: Optional[str]
withdrawlimit: Optional[int]
withdrawpin: Optional[int]
withdrawamt: int
withdrawtime: int
withdrawbtwn: int
withdrawpremium: Optional[float]
items: Optional[str]
@classmethod
def from_row(cls, row: Row) -> "TPoS":
return cls(**dict(row))
@property
def withdrawamtposs(self) -> int:
return self.withdrawlimit - self.withdrawamt if self.withdrawlimit else 0
class TPoSClean(BaseModel):
id: str
name: str
currency: str
tip_options: Optional[str]
withdrawlimit: Optional[int]
withdrawamt: int
withdrawtime: int
withdrawbtwn: int
withdrawpremium: Optional[float]
items: Optional[str]
@classmethod
def from_row(cls, row: Row) -> "TPoSClean":
return cls(**dict(row))
@property
def withdrawamtposs(self) -> int:
return self.withdrawlimit - self.withdrawamt if self.withdrawlimit else 0
class LNURLCharge(BaseModel):
id: str
tpos_id: str
amount: int = Field(None)
claimed: bool = Field(False)
@classmethod
def from_row(cls, row: Row) -> "LNURLCharge":
return cls(**dict(row))
def lnurl(self, req: Request) -> Lnurl:
url = str(
req.url_for(
"tpos.tposlnurlcharge",
lnurlcharge_id=self.id,
amount=self.amount,
)
)
return lnurl_encode(url)
def lnurl_response(self, req: Request) -> LnurlWithdrawResponse:
url = str(req.url_for("tpos.tposlnurlcharge.callback"))
assert self.amount
amount = int(self.amount)
return LnurlWithdrawResponse(
callback=ClearnetUrl(url, scheme="https"),
k1=self.k1,
minWithdrawable=MilliSatoshi(amount * 1000),
maxWithdrawable=MilliSatoshi(amount * 1000),
defaultDescription=self.title,
)
class HashCheck(BaseModel):
hash: bool
lnurl: bool
class PayLnurlWData(BaseModel):
lnurl: str
class Item(BaseModel):
image: Optional[str]
price: float
title: str
description: Optional[str]
tax: Optional[float] = 0.0
disabled: bool = False
categories: Optional[List[str]] = []
class CreateUpdateItemData(BaseModel):
items: List[Item]