1
1
import sys
2
2
import rlp
3
3
from rlp .sedes import CountableList , binary
4
- from rlp .utils import decode_hex , encode_hex , ascii_chr , str_to_bytes
4
+ from rlp .utils import decode_hex , encode_hex , ascii_chr
5
5
from ethereum import opcodes
6
6
from ethereum import utils
7
7
from ethereum import specials
8
8
from ethereum import bloom
9
9
from ethereum import vm as vm
10
- from ethereum .exceptions import *
11
- from ethereum .utils import safe_ord , normalize_address , mk_contract_address
10
+ from ethereum .exceptions import InvalidNonce , InsufficientStartGas , UnsignedTransaction , \
11
+ BlockGasLimitReached , InsufficientBalance
12
+ from ethereum .utils import safe_ord , mk_contract_address
12
13
from ethereum import transactions
14
+ import ethereum .config as config
13
15
14
16
sys .setrecursionlimit (100000 )
15
17
@@ -80,6 +82,8 @@ def rp(what, actual, target):
80
82
# (1) The transaction signature is valid;
81
83
if not tx .sender : # sender is set and validated on Transaction initialization
82
84
raise UnsignedTransaction (tx )
85
+ if block .number >= config .default_config ["HOMESTEAD_FORK_BLKNUM" ]:
86
+ tx .check_low_s ()
83
87
84
88
# (2) the transaction nonce is valid (equivalent to the
85
89
# sender account's current nonce);
@@ -105,6 +109,30 @@ def rp(what, actual, target):
105
109
return True
106
110
107
111
112
+ class lazy_safe_encode (object ):
113
+ """Creates a lazy and logging safe representation of transaction data.
114
+ Use this in logging of transactions; instead of
115
+
116
+ >>> log.debug(data=data)
117
+
118
+ do this:
119
+
120
+ >>> log.debug(data=lazy_safe_encode(data))
121
+ """
122
+
123
+ def __init__ (self , data ):
124
+ self .data = data
125
+
126
+ def __str__ (self ):
127
+ if not isinstance (self .data , (str , unicode )):
128
+ return repr (self .data )
129
+ else :
130
+ return encode_hex (self .data )
131
+
132
+ def __repr__ (self ):
133
+ return str (self )
134
+
135
+
108
136
def apply_transaction (block , tx ):
109
137
validate_transaction (block , tx )
110
138
@@ -124,7 +152,7 @@ def rp(what, actual, target):
124
152
log_tx .debug ('TX NEW' , tx_dict = tx .log_dict ())
125
153
# start transacting #################
126
154
block .increment_nonce (tx .sender )
127
-
155
+
128
156
# buy startgas
129
157
assert block .get_balance (tx .sender ) >= tx .startgas * tx .gasprice
130
158
block .delta_balance (tx .sender , - tx .startgas * tx .gasprice )
@@ -136,16 +164,16 @@ def rp(what, actual, target):
136
164
ext = VMExt (block , tx )
137
165
if tx .to and tx .to != CREATE_CONTRACT_ADDRESS :
138
166
result , gas_remained , data = apply_msg (ext , message )
139
- log_tx .debug ('_res_' , result = result , gas_remained = gas_remained , data = data )
167
+ log_tx .debug ('_res_' , result = result , gas_remained = gas_remained , data = lazy_safe_encode ( data ) )
140
168
else : # CREATE
141
169
result , gas_remained , data = create_contract (ext , message )
142
170
assert utils .is_numeric (gas_remained )
143
- log_tx .debug ('_create_' , result = result , gas_remained = gas_remained , data = data )
171
+ log_tx .debug ('_create_' , result = result , gas_remained = gas_remained , data = lazy_safe_encode ( data ) )
144
172
145
173
assert gas_remained >= 0
146
174
147
175
log_tx .debug ("TX APPLIED" , result = result , gas_remained = gas_remained ,
148
- data = data )
176
+ data = lazy_safe_encode ( data ) )
149
177
150
178
if not result : # 0 = OOG failure in both cases
151
179
log_tx .debug ('TX FAILED' , reason = 'out of gas' ,
@@ -155,7 +183,7 @@ def rp(what, actual, target):
155
183
output = b''
156
184
success = 0
157
185
else :
158
- log_tx .debug ('TX SUCCESS' , data = data )
186
+ log_tx .debug ('TX SUCCESS' , data = lazy_safe_encode ( data ) )
159
187
gas_used = tx .startgas - gas_remained
160
188
block .refunds += len (set (block .suicides )) * opcodes .GSUICIDEREFUND
161
189
if block .refunds > 0 :
@@ -251,7 +279,7 @@ def _apply_msg(ext, msg, code):
251
279
# assert utils.is_numeric(gas)
252
280
if trace_msg :
253
281
log_msg .debug ('MSG APPLIED' , gas_remained = gas ,
254
- sender = msg .sender , to = msg .to , data = dat )
282
+ sender = encode_hex ( msg .sender ) , to = encode_hex ( msg .to ) , data = dat )
255
283
if log_state .is_active ('trace' ):
256
284
log_state .trace ('MSG POST STATE SENDER' , account = msg .sender .encode ('hex' ),
257
285
bal = ext .get_balance (msg .sender ),
0 commit comments