Skip to content

Commit 7d0273e

Browse files
committed
Prepare base ConstantinopleVM structure
Closes #1107
1 parent 4c6cd4b commit 7d0273e

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed

eth/vm/forks/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
from .byzantium import ( # noqa: F401
1414
ByzantiumVM,
1515
)
16+
from .constantinople import ( # noqa: F401
17+
ConstantinopleVM
18+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import ( # noqa: F401
2+
Type,
3+
)
4+
5+
from eth.rlp.blocks import BaseBlock # noqa: F401
6+
from eth.vm.forks.byzantium import ByzantiumVM
7+
from eth.vm.state import BaseState # noqa: F401
8+
9+
from .blocks import ConstantinopleBlock
10+
from .state import ConstantinopleState
11+
12+
13+
class ConstantinopleVM(ByzantiumVM):
14+
# fork name
15+
fork = 'constantinople'
16+
17+
# classes
18+
block_class = ConstantinopleBlock # type: Type[BaseBlock]
19+
_state_class = ConstantinopleState # type: Type[BaseState]

eth/vm/forks/constantinople/blocks.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from rlp.sedes import (
2+
CountableList,
3+
)
4+
from eth.rlp.headers import (
5+
BlockHeader,
6+
)
7+
from eth.vm.forks.byzantium.blocks import (
8+
ByzantiumBlock,
9+
)
10+
11+
from .transactions import (
12+
ConstantinopleTransaction,
13+
)
14+
15+
16+
class ConstantinopleBlock(ByzantiumBlock):
17+
transaction_class = ConstantinopleTransaction
18+
fields = [
19+
('header', BlockHeader),
20+
('transactions', CountableList(transaction_class)),
21+
('uncles', CountableList(BlockHeader))
22+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from cytoolz import (
2+
merge,
3+
)
4+
5+
from eth.vm.forks.byzantium.computation import (
6+
BYZANTIUM_PRECOMPILES
7+
)
8+
from eth.vm.forks.byzantium.computation import (
9+
ByzantiumComputation
10+
)
11+
12+
from .opcodes import CONSTANTINOPLE_OPCODES
13+
14+
CONSTANTINOPLE_PRECOMPILES = merge(
15+
BYZANTIUM_PRECOMPILES,
16+
{
17+
# TODO: add new precompiles
18+
},
19+
)
20+
21+
22+
class ConstantinopleComputation(ByzantiumComputation):
23+
"""
24+
A class for all execution computations in the ``Constantinople`` fork.
25+
Inherits from :class:`~eth.vm.forks.byzantium.computation.ByzantiumComputation`
26+
"""
27+
# Override
28+
opcodes = CONSTANTINOPLE_OPCODES
29+
_precompiles = CONSTANTINOPLE_PRECOMPILES
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import copy
2+
3+
from eth.vm.forks.byzantium.opcodes import (
4+
BYZANTIUM_OPCODES
5+
)
6+
7+
8+
CONSTANTINOPLE_OPCODES = copy.deepcopy(BYZANTIUM_OPCODES)

eth/vm/forks/constantinople/state.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from eth.vm.forks.byzantium.state import (
2+
ByzantiumState
3+
)
4+
5+
from .computation import ConstantinopleComputation
6+
7+
8+
class ConstantinopleState(ByzantiumState):
9+
computation_class = ConstantinopleComputation
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from eth.vm.forks.byzantium.transactions import (
2+
ByzantiumTransaction,
3+
ByzantiumUnsignedTransaction,
4+
)
5+
6+
from eth.utils.transactions import (
7+
create_transaction_signature,
8+
)
9+
10+
11+
class ConstantinopleTransaction(ByzantiumTransaction):
12+
@classmethod
13+
def create_unsigned_transaction(cls, nonce, gas_price, gas, to, value, data):
14+
return ConstantinopleUnsignedTransaction(nonce, gas_price, gas, to, value, data)
15+
16+
17+
class ConstantinopleUnsignedTransaction(ByzantiumUnsignedTransaction):
18+
def as_signed_transaction(self, private_key, chain_id=None):
19+
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id)
20+
return ConstantinopleTransaction(
21+
nonce=self.nonce,
22+
gas_price=self.gas_price,
23+
gas=self.gas,
24+
to=self.to,
25+
value=self.value,
26+
data=self.data,
27+
v=v,
28+
r=r,
29+
s=s,
30+
)

0 commit comments

Comments
 (0)