-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
73 lines (60 loc) · 1.44 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
from dataclasses import dataclass
from typing import Literal, Optional, Any
Location = Literal['L1', 'L2']
Currency = Literal['BAX', 'RED', 'GBP']
@dataclass
class Account:
location: Location
address: str
@dataclass
class Amount:
currency: Currency
value: int
@dataclass
class Event:
block_number: int
idx: int
pallet: str
name: str
data: Any
link: str
@dataclass
class Events:
sender: list[Event]
receiver: Optional[list[Event]]
TransactionStatus = Literal['InProgress', 'Done', 'Error']
@dataclass
class Block:
number: int
link: str
@classmethod
def from_polkascan(cls, number: int, polkascan: str):
from urllib.parse import urlparse, urljoin, urlunparse
polkadot_url = urlparse(polkascan)
polkadot_path = urljoin(f'{polkadot_url.path}/', f'block/{number}')
link = urlunparse(polkadot_url._replace(path=polkadot_path))
return cls(number, link)
@dataclass
class Transaction:
tx_hash: str
link_to_scanner: str
xcm_id: str
sender: Account
receiver: Account
amount: Amount
sent_in_block: Block
received_in_block: Optional[Block]
events: Events
status: TransactionStatus
error: Optional[str]
@dataclass
class ExtrinsicIdx:
block_number: int
idx: int
@dataclass
class EthTransaction:
tx_hash: str
extrinsic_idx: ExtrinsicIdx
sender: Account
receiver: Account
amount: Amount