-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
63 lines (52 loc) · 1.63 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
import json
from datetime import datetime, timezone
from typing import Optional
from lnurl import encode as lnurl_encode
from lnurl.types import LnurlPayMetadata
from pydantic import BaseModel, Field
class Switch(BaseModel):
amount: float = 0.0
duration: int = 0
pin: int = 0
comment: bool = False
variable: bool = False
lnurl: Optional[str] = None
def set_lnurl(self, url: str) -> str:
self.lnurl = str(
lnurl_encode(
url
+ f"?pin={self.pin}"
+ f"&amount={self.amount}"
+ f"&duration={self.duration}"
+ f"&variable={self.variable}"
+ f"&comment={self.comment}"
+ "&disabletime=0"
)
)
return self.lnurl
class CreateBitcoinswitch(BaseModel):
title: str
wallet: str
currency: str
switches: list[Switch]
class Bitcoinswitch(BaseModel):
id: str
title: str
wallet: str
currency: str
key: str
switches: list[Switch]
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
@property
def lnurlpay_metadata(self) -> LnurlPayMetadata:
return LnurlPayMetadata(json.dumps([["text/plain", self.title]]))
class BitcoinswitchPayment(BaseModel):
id: str
payment_hash: str
bitcoinswitch_id: str
payload: str
pin: int
sats: int
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))