15
15
)
16
16
from eth .abc import (
17
17
ComputationAPI ,
18
+ MessageAPI ,
19
+ StateAPI ,
20
+ TransactionContextAPI ,
18
21
)
19
22
from eth .exceptions import (
20
23
OutOfGas ,
@@ -45,47 +48,59 @@ class FrontierComputation(BaseComputation):
45
48
opcodes = FRONTIER_OPCODES
46
49
_precompiles = FRONTIER_PRECOMPILES # type: ignore # https://github.com/python/mypy/issues/708 # noqa: E501
47
50
48
- def apply_message (self ) -> ComputationAPI :
49
- snapshot = self .state .snapshot ()
51
+ @classmethod
52
+ def apply_message (
53
+ cls ,
54
+ state : StateAPI ,
55
+ message : MessageAPI ,
56
+ transaction_context : TransactionContextAPI ) -> ComputationAPI :
50
57
51
- if self .msg .depth > STACK_DEPTH_LIMIT :
58
+ snapshot = state .snapshot ()
59
+
60
+ if message .depth > STACK_DEPTH_LIMIT :
52
61
raise StackDepthLimit ("Stack depth limit reached" )
53
62
54
- if self . msg . should_transfer_value and self . msg .value :
55
- sender_balance = self . state .get_balance (self . msg .sender )
63
+ if message . should_transfer_value and message .value :
64
+ sender_balance = state .get_balance (message .sender )
56
65
57
- if sender_balance < self . msg .value :
66
+ if sender_balance < message .value :
58
67
raise InsufficientFunds (
59
- f"Insufficient funds: { sender_balance } < { self . msg .value } "
68
+ f"Insufficient funds: { sender_balance } < { message .value } "
60
69
)
61
70
62
- self . state .delta_balance (self . msg . sender , - 1 * self . msg .value )
63
- self . state .delta_balance (self . msg . storage_address , self . msg .value )
71
+ state .delta_balance (message . sender , - 1 * message .value )
72
+ state .delta_balance (message . storage_address , message .value )
64
73
65
- self .logger .debug2 (
74
+ cls .logger .debug2 (
66
75
"TRANSFERRED: %s from %s -> %s" ,
67
- self . msg .value ,
68
- encode_hex (self . msg .sender ),
69
- encode_hex (self . msg .storage_address ),
76
+ message .value ,
77
+ encode_hex (message .sender ),
78
+ encode_hex (message .storage_address ),
70
79
)
71
80
72
- self . state .touch_account (self . msg .storage_address )
81
+ state .touch_account (message .storage_address )
73
82
74
- computation = self .apply_computation (
75
- self . state ,
76
- self . msg ,
77
- self . transaction_context ,
83
+ computation = cls .apply_computation (
84
+ state ,
85
+ message ,
86
+ transaction_context ,
78
87
)
79
88
80
89
if computation .is_error :
81
- self . state .revert (snapshot )
90
+ state .revert (snapshot )
82
91
else :
83
- self . state .commit (snapshot )
92
+ state .commit (snapshot )
84
93
85
94
return computation
86
95
87
- def apply_create_message (self ) -> ComputationAPI :
88
- computation = self .apply_message ()
96
+ @classmethod
97
+ def apply_create_message (
98
+ cls ,
99
+ state : StateAPI ,
100
+ message : MessageAPI ,
101
+ transaction_context : TransactionContextAPI ) -> ComputationAPI :
102
+
103
+ computation = cls .apply_message (state , message , transaction_context )
89
104
90
105
if computation .is_error :
91
106
return computation
@@ -102,11 +117,11 @@ def apply_create_message(self) -> ComputationAPI:
102
117
except OutOfGas :
103
118
computation .output = b''
104
119
else :
105
- self .logger .debug2 (
120
+ cls .logger .debug2 (
106
121
"SETTING CODE: %s -> length: %s | hash: %s" ,
107
- encode_hex (self . msg .storage_address ),
122
+ encode_hex (message .storage_address ),
108
123
len (contract_code ),
109
124
encode_hex (keccak (contract_code ))
110
125
)
111
- self . state .set_code (self . msg .storage_address , contract_code )
126
+ state .set_code (message .storage_address , contract_code )
112
127
return computation
0 commit comments