-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
102 lines (76 loc) · 1.85 KB
/
schemas.py
File metadata and controls
102 lines (76 loc) · 1.85 KB
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
from typing import Annotated, TypeVar, Generic
from pydantic import BaseModel, ConfigDict
from datetime import datetime, timedelta
from pydantic import PlainSerializer
from app import utils
# Custom Pydantic serializers
datetime_pd = Annotated[
datetime,
PlainSerializer(
lambda x: utils.to_timestamp(x),
return_type=int,
),
]
timedelta_pd = Annotated[
timedelta,
PlainSerializer(
lambda x: int(x.total_seconds()),
return_type=int,
),
]
Satoshi = Annotated[
float,
PlainSerializer(
utils.to_satoshi,
return_type=int,
),
]
class CustomModel(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
use_enum_values=True,
from_attributes=True,
)
class PaginationDataResponse(CustomModel):
total: int
pages: int
page: int
T = TypeVar("T", bound=CustomModel)
class PaginatedResponse(CustomModel, Generic[T]):
pagination: PaginationDataResponse
list: list[T]
class OutputResponse(CustomModel):
address: str
txid: str
currency: str
amount: Satoshi
timelock: int
type: str
spent: bool
script: str
asm: str
index: int
OutputPaginatedResponse = PaginatedResponse[OutputResponse]
class OutputFullResponse(OutputResponse):
units: int
class InputFullResponse(CustomModel):
amount: Satoshi
units: int
currency: str
address: str
class TransactionResponse(CustomModel):
height: int | None
blockhash: str | None
timestamp: int | None
txid: str
amount: dict[str, Satoshi]
outputs: list[OutputFullResponse]
inputs: list[InputFullResponse]
coinbase: bool
confirmations: int
fee: Satoshi
TransactionPaginatedResponse = PaginatedResponse[TransactionResponse]
class BalanceResponse(CustomModel):
currency: str
units: int
balance: Satoshi