@@ -227,10 +227,13 @@ class VMExt():
227
227
def __init__ (self , block , tx ):
228
228
self ._block = block
229
229
self .get_code = block .get_code
230
+ self .set_code = block .set_code
230
231
self .get_balance = block .get_balance
231
232
self .set_balance = block .set_balance
233
+ self .delta_balance = block .delta_balance
232
234
self .get_nonce = block .get_nonce
233
235
self .set_nonce = block .set_nonce
236
+ self .increment_nonce = block .increment_nonce
234
237
self .set_storage_data = block .set_storage_data
235
238
self .get_storage_data = block .get_storage_data
236
239
self .get_storage_bytes = block .get_storage_bytes
@@ -254,6 +257,10 @@ def __init__(self, block, tx):
254
257
self .account_exists = block .account_exists
255
258
self .post_homestead_hardfork = lambda : block .number >= block .config ['HOMESTEAD_FORK_BLKNUM' ]
256
259
self .post_metropolis_hardfork = lambda : block .number >= block .config ['METROPOLIS_FORK_BLKNUM' ]
260
+ self .snapshot = block .snapshot
261
+ self .revert = block .revert
262
+ self .transfer_value = block .transfer_value
263
+ self .reset_storage = block .reset_storage
257
264
258
265
259
266
def apply_msg (ext , msg ):
@@ -275,9 +282,9 @@ def _apply_msg(ext, msg, code):
275
282
state = ext .log_storage (msg .to ))
276
283
# log_state.trace('CODE', code=code)
277
284
# Transfer value, instaquit if not enough
278
- snapshot = ext ._block . snapshot ()
285
+ snapshot = ext .snapshot ()
279
286
if msg .transfers_value :
280
- if not ext ._block . transfer_value (msg .sender , msg .to , msg .value ):
287
+ if not ext .transfer_value (msg .sender , msg .to , msg .value ):
281
288
log_msg .debug ('MSG TRANSFER FAILED' , have = ext .get_balance (msg .to ),
282
289
want = msg .value )
283
290
return 1 , msg .gas , []
@@ -301,7 +308,7 @@ def _apply_msg(ext, msg, code):
301
308
302
309
if res == 0 :
303
310
log_msg .debug ('REVERTING' )
304
- ext ._block . revert (snapshot )
311
+ ext .revert (snapshot )
305
312
306
313
return res , gas , dat
307
314
@@ -311,7 +318,7 @@ def create_contract(ext, msg):
311
318
#print('CREATING WITH GAS', msg.gas)
312
319
sender = decode_hex (msg .sender ) if len (msg .sender ) == 40 else msg .sender
313
320
code = msg .data .extract_all ()
314
- if ext ._block . number >= ext . _block . config [ "METROPOLIS_FORK_BLKNUM" ] :
321
+ if ext .post_metropolis_hardfork () :
315
322
msg .to = mk_metropolis_contract_address (msg .sender , code )
316
323
if ext .get_code (msg .to ):
317
324
if ext .get_nonce (msg .to ) >= 2 ** 40 :
@@ -322,19 +329,19 @@ def create_contract(ext, msg):
322
329
msg .to = normalize_address ((ext .get_nonce (msg .to ) - 1 ) % 2 ** 160 )
323
330
else :
324
331
if ext .tx_origin != msg .sender :
325
- ext ._block . increment_nonce (msg .sender )
326
- nonce = utils .encode_int (ext ._block . get_nonce (msg .sender ) - 1 )
332
+ ext .increment_nonce (msg .sender )
333
+ nonce = utils .encode_int (ext .get_nonce (msg .sender ) - 1 )
327
334
msg .to = mk_contract_address (sender , nonce )
328
335
b = ext .get_balance (msg .to )
329
336
if b > 0 :
330
337
ext .set_balance (msg .to , b )
331
- ext ._block . set_nonce (msg .to , 0 )
332
- ext ._block . set_code (msg .to , b'' )
333
- ext ._block . reset_storage (msg .to )
338
+ ext .set_nonce (msg .to , 0 )
339
+ ext .set_code (msg .to , b'' )
340
+ ext .reset_storage (msg .to )
334
341
msg .is_create = True
335
342
# assert not ext.get_code(msg.to)
336
343
msg .data = vm .CallData ([], 0 , 0 )
337
- snapshot = ext ._block . snapshot ()
344
+ snapshot = ext .snapshot ()
338
345
res , gas , dat = _apply_msg (ext , msg , code )
339
346
assert utils .is_numeric (gas )
340
347
@@ -346,11 +353,11 @@ def create_contract(ext, msg):
346
353
gas -= gcost
347
354
else :
348
355
dat = []
349
- log_msg .debug ('CONTRACT CREATION OOG' , have = gas , want = gcost , block_number = ext ._block . number )
350
- if ext ._block . number >= ext . _block . config [ 'HOMESTEAD_FORK_BLKNUM' ] :
351
- ext ._block . revert (snapshot )
356
+ log_msg .debug ('CONTRACT CREATION OOG' , have = gas , want = gcost , block_number = ext .block_number )
357
+ if ext .post_homestead_hardfork () :
358
+ ext .revert (snapshot )
352
359
return 0 , 0 , b''
353
- ext ._block . set_code (msg .to , b'' .join (map (ascii_chr , dat )))
360
+ ext .set_code (msg .to , b'' .join (map (ascii_chr , dat )))
354
361
return 1 , gas , msg .to
355
362
else :
356
363
return 0 , gas , b''
0 commit comments