-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
134 lines (111 loc) · 3.36 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
124
125
126
127
128
129
130
131
132
133
134
import json
from datetime import datetime, timezone
from typing import Optional
from fastapi import Query, Request
from lnurl import Lnurl
from lnurl import encode as lnurl_encode
from lnurl.types import LnurlPayMetadata
from pydantic import BaseModel
class SatsdiceLink(BaseModel):
id: str
wallet: str
title: str
min_bet: int
max_bet: int
multiplier: float
haircut: float
chance: float
base_url: str
amount: int = 0
served_meta: int = 0
served_pr: int = 0
# TODO: Change to datetime
open_time: int = int(datetime.now(timezone.utc).timestamp())
def lnurl(self, req: Request) -> str:
return lnurl_encode(
str(req.url_for("satsdice.lnurlp_response", link_id=self.id))
)
@property
def lnurlpay_metadata(self) -> LnurlPayMetadata:
return LnurlPayMetadata(
json.dumps(
[
[
"text/plain",
(
f"{self.title} (Chance: {self.chance}%, "
f"Multiplier: {self.multiplier})"
),
]
]
)
)
def success_action(self, payment_hash: str, req: Request) -> Optional[dict]:
url = str(
req.url_for(
"satsdice.displaywin", link_id=self.id, payment_hash=payment_hash
)
)
return {"tag": "url", "description": "Check the attached link", "url": url}
class SatsdicePayment(BaseModel):
payment_hash: str
satsdice_pay: str
value: int
paid: bool = False
lost: bool = False
class SatsdiceWithdraw(BaseModel):
id: str
satsdice_pay: str
value: int
unique_hash: str
k1: str
open_time: int
used: int
def lnurl(self, req: Request) -> Lnurl:
return lnurl_encode(
str(req.url_for("satsdice.lnurlw_response", unique_hash=self.unique_hash))
)
@property
def is_spent(self) -> bool:
return self.used >= 1
def lnurl_response(self, req: Request):
url = str(
req.url_for("satsdice.api_lnurlw_callback", unique_hash=self.unique_hash)
)
withdraw_response = {
"tag": "withdrawRequest",
"callback": url,
"k1": self.k1,
"minWithdrawable": self.value * 1000,
"maxWithdrawable": self.value * 1000,
"defaultDescription": "Satsdice winnings!",
}
return withdraw_response
class HashCheck(BaseModel):
id: str
lnurl_id: str
class CreateSatsDiceLink(BaseModel):
wallet: str = Query(None)
title: str = Query(None)
base_url: str = Query(None)
min_bet: int = Query(None)
max_bet: int = Query(None)
multiplier: float = Query(0)
chance: float = Query(0)
haircut: float = Query(0)
class CreateSatsDicePayment(BaseModel):
satsdice_pay: str = Query(None)
value: int = Query(0)
payment_hash: str = Query(None)
class CreateSatsDiceWithdraw(BaseModel):
payment_hash: str = Query(None)
satsdice_pay: str = Query(None)
value: int = Query(0)
used: int = Query(0)
class CreateSatsDiceWithdraws(BaseModel):
title: str = Query(None)
min_satsdiceable: int = Query(0)
max_satsdiceable: int = Query(0)
uses: int = Query(0)
wait_time: str = Query(None)
is_unique: bool = Query(False)