def get_chain(data_dir=default_data_dir): """ returns an ethereum.chain.Chain instance """ dbfile = os.path.join(data_dir, 'leveldb') db = LevelDB(dbfile) return Chain(Env(db))
DB_DIR = '/tmp/%d' % random.randrange(int(time.time() * 1000000)) if '--db' in sys.argv: DB_DIR = int(sys.argv[sys.argv.index('--db') + 1]) _path, _file = os.path.split(STATE_LOAD_FN) if _file in os.listdir(os.path.join(os.getcwd(), _path)): print('loading state from %s ...' % STATE_LOAD_FN) c = chain.Chain(json.load(open(STATE_LOAD_FN)), Env()) print('loaded.') elif 'genesis_frontier.json' not in os.listdir(os.getcwd()): print('Please download genesis_frontier.json from ' + 'http://vitalik.ca/files/genesis_frontier.json') sys.exit() else: c = chain.Chain(json.load(open('genesis_frontier.json')), Env(LevelDB(DB_DIR))) assert c.state.trie.root_hash.encode('hex') == \ 'd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544' assert c.state.prev_headers[0].hash.encode('hex') == \ 'd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3' print('state generated from genesis') print('Attempting to open %s' % RLP_BLOCKS_FILE) _path, _file = os.path.split(RLP_BLOCKS_FILE) if not _path or _file not in os.listdir(_path): print( 'Please download 200kblocks.rlp from http://vitalik.ca/files/200kblocks.rlp ' + 'and put it in this directory to continue the test') sys.exit() f = open(RLP_BLOCKS_FILE)