-
Notifications
You must be signed in to change notification settings - Fork 7
/
models.py
46 lines (34 loc) · 984 Bytes
/
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
from typing import Optional
from pydantic import BaseModel
class BuyOrder(BaseModel):
action: str
relay_id: str
pubkey: str
units_to_buy: int = 0
def is_valid_action(self) -> bool:
return self.action in ["join", "storage"]
class NostrPartialAccount(BaseModel):
relay_id: str
pubkey: str
allowed: Optional[bool] = None
blocked: Optional[bool] = None
class NostrAccount(BaseModel):
pubkey: str
relay_id: str
sats: int = 0
storage: int = 0
paid_to_join: bool = False
allowed: bool = False
blocked: bool = False
@property
def can_join(self):
"""If an account is explicitly allowed then it does not need to pay"""
return self.paid_to_join or self.allowed
@classmethod
def null_account(cls) -> "NostrAccount":
return NostrAccount(pubkey="", relay_id="")
class NostrEventTags(BaseModel):
event_id: str
name: str
value: str
extra: Optional[str] = None