Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit d9caa62

Browse files
author
Jan Xie
committed
add new head hook to chain
1 parent 8577d94 commit d9caa62

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ethereum/chain.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Chain(object):
2323

2424
def __init__(self, genesis=None, env=None, coinbase=b'\x00' * 20, \
25-
post_state_initialize=None, **kwargs):
25+
new_head_cb=None, post_state_initialize=None, **kwargs):
2626
self.env = env or Env()
2727
# Initialize the state
2828
if 'head_hash' in self.db:
@@ -55,6 +55,7 @@ def __init__(self, genesis=None, env=None, coinbase=b'\x00' * 20, \
5555
}, self.env)
5656

5757
initialize(self.state)
58+
self.new_head_cb = new_head_cb
5859
if post_state_initialize:
5960
post_state_initialize(self.state)
6061

@@ -299,6 +300,8 @@ def add_block(self, block):
299300
log.info('Added block %d (%s) with %d txs and %d gas' % \
300301
(block.header.number, encode_hex(block.header.hash)[:8],
301302
len(block.transactions), block.header.gas_used))
303+
if self.new_head_cb and block.header.number != 0:
304+
self.new_head_cb(block)
302305
return True
303306

304307
def __contains__(self, blk):

0 commit comments

Comments
 (0)