Skip to content

Commit 42752f0

Browse files
committed
Implement eth.abc module with abstract base classes for public APIs
1 parent 814fb0e commit 42752f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2993
-1882
lines changed

docs/api/api.abc.rst

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
ABC
2+
===
3+
4+
Abstract base classes for documented interfaces
5+
6+
MiningHeaderAPI
7+
---------------
8+
9+
.. autoclass:: eth.abc.MiningHeaderAPI
10+
:members:
11+
12+
13+
BlockHeaderAPI
14+
--------------
15+
16+
.. autoclass:: eth.abc.BlockHeaderAPI
17+
:members:
18+
19+
20+
LogAPI
21+
------
22+
23+
.. autoclass:: eth.abc.LogAPI
24+
:members:
25+
26+
27+
ReceiptAPI
28+
----------
29+
30+
.. autoclass:: eth.abc.ReceiptAPI
31+
:members:
32+
33+
34+
BaseTransactionAPI
35+
------------------
36+
37+
.. autoclass:: eth.abc.BaseTransactionAPI
38+
:members:
39+
40+
41+
TransactionFieldsAPI
42+
--------------------
43+
44+
.. autoclass:: eth.abc.TransactionFieldsAPI
45+
:members:
46+
47+
48+
UnsignedTransactionAPI
49+
----------------------
50+
51+
.. autoclass:: eth.abc.UnsignedTransactionAPI
52+
:members:
53+
54+
55+
SignedTransactionAPI
56+
--------------------
57+
58+
.. autoclass:: eth.abc.SignedTransactionAPI
59+
:members:
60+
61+
62+
BlockAPI
63+
--------
64+
65+
.. autoclass:: eth.abc.BlockAPI
66+
:members:
67+
68+
69+
DatabaseAPI
70+
-----------
71+
72+
.. autoclass:: eth.abc.DatabaseAPI
73+
:members:
74+
75+
76+
AtomicDatabaseAPI
77+
-----------------
78+
79+
.. autoclass:: eth.abc.AtomicDatabaseAPI
80+
:members:
81+
82+
83+
HeaderDatabaseAPI
84+
-----------------
85+
86+
.. autoclass:: eth.abc.HeaderDatabaseAPI
87+
:members:
88+
89+
90+
ChainDatabaseAPI
91+
----------------
92+
93+
.. autoclass:: eth.abc.ChainDatabaseAPI
94+
:members:
95+
96+
97+
GasMeterAPI
98+
-----------
99+
100+
.. autoclass:: eth.abc.GasMeterAPI
101+
:members:
102+
103+
104+
MessageAPI
105+
----------
106+
107+
.. autoclass:: eth.abc.MessageAPI
108+
:members:
109+
110+
111+
OpcodeAPI
112+
---------
113+
114+
.. autoclass:: eth.abc.OpcodeAPI
115+
:members:
116+
117+
118+
TransactionContextAPI
119+
---------------------
120+
121+
.. autoclass:: eth.abc.TransactionContextAPI
122+
:members:
123+
124+
125+
MemoryAPI
126+
---------
127+
128+
.. autoclass:: eth.abc.MemoryAPI
129+
:members:
130+
131+
132+
StackAPI
133+
--------
134+
135+
.. autoclass:: eth.abc.StackAPI
136+
:members:
137+
138+
139+
CodeStreamAPI
140+
-------------
141+
142+
.. autoclass:: eth.abc.CodeStreamAPI
143+
:members:
144+
145+
146+
StackManipulationAPI
147+
--------------------
148+
149+
.. autoclass:: eth.abc.StackManipulationAPI
150+
:members:
151+
152+
153+
ExecutionContextAPI
154+
-------------------
155+
156+
.. autoclass:: eth.abc.ExecutionContextAPI
157+
:members:
158+
159+
160+
ComputationAPI
161+
--------------
162+
163+
.. autoclass:: eth.abc.ComputationAPI
164+
:members:
165+
166+
167+
AccountStorageDatabaseAPI
168+
-------------------------
169+
170+
.. autoclass:: eth.abc.AccountStorageDatabaseAPI
171+
:members:
172+
173+
174+
AccountDatabaseAPI
175+
------------------
176+
177+
.. autoclass:: eth.abc.AccountDatabaseAPI
178+
:members:
179+
180+
181+
TransactionExecutorAPI
182+
----------------------
183+
184+
.. autoclass:: eth.abc.TransactionExecutorAPI
185+
:members:
186+
187+
188+
ConfigurableAPI
189+
---------------
190+
191+
.. autoclass:: eth.abc.ConfigurableAPI
192+
:members:
193+
194+
195+
StateAPI
196+
--------
197+
198+
.. autoclass:: eth.abc.StateAPI
199+
:members:
200+
201+
202+
VirtualMachineAPI
203+
-----------------
204+
205+
.. autoclass:: eth.abc.VirtualMachineAPI
206+
:members:
207+
208+
209+
HeaderChainAPI
210+
--------------
211+
212+
.. autoclass:: eth.abc.HeaderChainAPI
213+
:members:
214+
215+
216+
ChainAPI
217+
--------
218+
219+
.. autoclass:: eth.abc.ChainAPI
220+
:members:
221+
222+
223+
MiningChainAPI
224+
--------------
225+
226+
.. autoclass:: eth.abc.MiningChainAPI
227+
:members:

docs/api/db/api.db.account.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
Account
22
========
33

4-
BaseAccountDB
5-
-------------
6-
7-
.. autoclass:: eth.db.account.BaseAccountDB
8-
:members:
9-
104
AccountDB
115
-------------
126

docs/api/db/api.db.chain.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
Chain
22
=====
33

4-
BaseChainDB
5-
~~~~~~~~~~~
6-
7-
.. autoclass:: eth.db.chain.BaseChainDB
8-
:members:
9-
104
ChainDB
115
~~~~~~~
126

docs/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This section aims to provide a detailed description of all APIs. If you are look
1212
:name: toc-api-eth
1313

1414

15+
api.abc
1516
api.chain
1617
api.db
1718
api.exceptions

docs/api/vm/api.vm.vm.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
VM
22
==
33

4-
BaseVM
5-
------
6-
7-
.. autoclass:: eth.vm.base.BaseVM
8-
:members:
9-
10-
114
VM
125
--
136

docs/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ All parameters as well as the return type of defs are expected to be typed with
6565

6666
.. code:: python
6767
68-
def __init__(self, wrapped_db: BaseDB) -> None:
68+
def __init__(self, wrapped_db: DatabaseAPI) -> None:
6969
self.wrapped_db = wrapped_db
7070
self.reset()
7171

eth/_utils/datatypes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from typing import Any, Dict, Tuple, Type, TypeVar, Iterator, List
1313

14+
from eth.abc import ConfigurableAPI
15+
1416

1517
def _is_local_prop(prop: str) -> bool:
1618
return len(prop.split('.')) == 1
@@ -64,7 +66,7 @@ def _get_top_level_keys(overrides: Dict[str, Any]) -> Iterator[str]:
6466
T = TypeVar('T')
6567

6668

67-
class Configurable(object):
69+
class Configurable(ConfigurableAPI):
6870
"""
6971
Base class for simple inline subclassing
7072
"""

eth/_utils/db.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
1-
from typing import (
2-
TYPE_CHECKING,
3-
)
4-
51
from eth_typing import (
62
Hash32,
73
)
84

9-
from eth.rlp.headers import (
10-
BlockHeader,
5+
from eth.abc import (
6+
BlockHeaderAPI,
7+
ChainDatabaseAPI,
8+
StateAPI,
119
)
1210
from eth.typing import (
1311
AccountState,
1412
)
15-
from eth.vm.state import (
16-
BaseState,
17-
)
18-
19-
if TYPE_CHECKING:
20-
from eth.db.chain import BaseChainDB # noqa: F401
2113

2214

23-
def get_parent_header(block_header: BlockHeader, db: 'BaseChainDB') -> BlockHeader:
15+
def get_parent_header(block_header: BlockHeaderAPI, db: ChainDatabaseAPI) -> BlockHeaderAPI:
2416
"""
2517
Returns the header for the parent block.
2618
"""
2719
return db.get_block_header_by_hash(block_header.parent_hash)
2820

2921

30-
def get_block_header_by_hash(block_hash: Hash32, db: 'BaseChainDB') -> BlockHeader:
22+
def get_block_header_by_hash(block_hash: Hash32, db: ChainDatabaseAPI) -> BlockHeaderAPI:
3123
"""
3224
Returns the header for the parent block.
3325
"""
3426
return db.get_block_header_by_hash(block_hash)
3527

3628

37-
def apply_state_dict(state: BaseState, state_dict: AccountState) -> None:
29+
def apply_state_dict(state: StateAPI, state_dict: AccountState) -> None:
3830
for account, account_data in state_dict.items():
3931
state.set_balance(account, account_data["balance"])
4032
state.set_nonce(account, account_data["nonce"])

eth/_utils/spoof.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
DEFAULT_SPOOF_S,
1515
)
1616

17-
from eth.rlp.transactions import (
18-
BaseTransaction,
19-
BaseUnsignedTransaction,
17+
from eth.abc import (
18+
SignedTransactionAPI,
19+
UnsignedTransactionAPI,
2020
)
2121

2222
SPOOF_ATTRIBUTES_DEFAULTS = {
@@ -31,7 +31,7 @@
3131
class SpoofAttributes:
3232
def __init__(
3333
self,
34-
spoof_target: Union[BaseTransaction, BaseUnsignedTransaction],
34+
spoof_target: Union[SignedTransactionAPI, UnsignedTransactionAPI],
3535
**overrides: Any) -> None:
3636
self.spoof_target = spoof_target
3737
self.overrides = overrides

0 commit comments

Comments
 (0)