-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathabc.py
177 lines (141 loc) · 3.47 KB
/
abc.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from abc import (
ABC,
abstractmethod,
)
from typing import (
Any,
Generic,
Iterable,
Iterator,
Optional,
TypeVar,
Union,
)
from eth_typing import (
Hash32,
)
from pyrsistent.typing import (
PVector,
)
from ssz.hash_tree import (
HashTree,
)
from ssz.sedes.base import (
BaseProperCompositeSedes,
)
TStructure = TypeVar("TStructure")
TElement = TypeVar("TElement")
class HashableStructureAPI(ABC, Generic[TElement]):
@classmethod
@abstractmethod
def from_iterable_and_sedes(
cls,
iterable: Iterable[TElement],
sedes: BaseProperCompositeSedes,
max_length: Optional[int],
):
...
#
# Element and hash tree access
#
@property
@abstractmethod
def elements(self) -> PVector[TElement]:
...
@property
@abstractmethod
def chunks(self) -> PVector[Hash32]:
...
@property
@abstractmethod
def hash_tree(self) -> HashTree:
...
@property
@abstractmethod
def raw_root(self) -> Hash32:
...
@property
@abstractmethod
def hash_tree_root(self) -> Hash32:
...
#
# Partial PVector interface
#
@abstractmethod
def __len__(self) -> int:
...
@abstractmethod
def __getitem__(self, index: int) -> TElement:
...
@abstractmethod
def __iter__(self) -> Iterator[TElement]:
...
@abstractmethod
def __hash__(self) -> int:
...
@abstractmethod
def __eq__(self, other: Any) -> bool:
...
@abstractmethod
def transform(self, *transformations):
...
@abstractmethod
def mset(self: TStructure, *args: Union[int, TElement]) -> TStructure:
...
@abstractmethod
def set(self: TStructure, index: int, value: TElement) -> TStructure:
...
@abstractmethod
def evolver(
self: TStructure,
) -> "HashableStructureEvolverAPI[TStructure, TElement]":
...
class ResizableHashableStructureAPI(HashableStructureAPI[TElement]):
@abstractmethod
def append(self: TStructure, value: TElement) -> TStructure:
...
@abstractmethod
def extend(self: TStructure, values: Iterable[TElement]) -> TStructure:
...
@abstractmethod
def __add__(self: TStructure, values: Iterable[TElement]) -> TStructure:
...
@abstractmethod
def __mul__(self: TStructure, times: int) -> TStructure:
...
@abstractmethod
def evolver(
self: TStructure,
) -> "ResizableHashableStructureEvolverAPI[TStructure, TElement]":
...
class HashableStructureEvolverAPI(ABC, Generic[TStructure, TElement]):
@abstractmethod
def __init__(self, hashable_structure: TStructure) -> None:
...
@abstractmethod
def __getitem__(self, index: int) -> TElement:
...
@abstractmethod
def set(self, index: int, element: TElement) -> None:
...
@abstractmethod
def __setitem__(self, index: int, element: TElement) -> None:
...
@abstractmethod
def __len__(self) -> int:
...
@abstractmethod
def is_dirty(self) -> bool:
...
@abstractmethod
def persistent(self) -> TStructure:
...
class ResizableHashableStructureEvolverAPI(
HashableStructureEvolverAPI[TStructure, TElement]
):
@abstractmethod
def append(self, element: TElement) -> None:
...
@abstractmethod
def extend(self, iterable: Iterable[TElement]) -> None:
...