@@ -19,53 +19,59 @@ npm install @ethereumjs/era
1919
2020## Usage
2121
22-
2322All helpers are re-exported from the root level and deep imports are not necessary. So an import can be done like this:
2423
2524``` ts
26- import { formatEntry } from ' @ethereumjs/era'
25+ import { formatEntry } from " @ethereumjs/era" ;
2726```
2827
2928#### Export History as Era1
29+
3030Export history in epochs of 8192 blocks as Era1 files
3131
3232``` ts
33- import { exportEpochAsEra1 } from ' @ethereumjs/era'
33+ import { exportEpochAsEra1 } from " @ethereumjs/era" ;
3434
35- const dataDir = PATH_TO_ETHEREUMJS_CLIENT_DB
36- const epoch = 0
35+ const dataDir = PATH_TO_ETHEREUMJS_CLIENT_DB ;
36+ const epoch = 0 ;
3737
3838// generates ${dataDir}/era1/epoch-0.era1
39- await exportEpochAsEra1 (epoch , dataDir )
39+ await exportEpochAsEra1 (epoch , dataDir );
4040```
4141
4242#### Read Era1 file
4343
4444` readERA1 ` returns an async iterator of block tuples (header + body + receipts + totalDifficulty)
4545
46-
4746``` ts
48- import { readBinaryFile , validateERA1 , readERA1 , EpochAccumulator } from ' @ethereumjs/era'
49-
50- const era1File = readBinaryFile (PATH_TO_ERA1_FILE )
47+ import {
48+ readBinaryFile ,
49+ validateERA1 ,
50+ readERA1 ,
51+ parseBlockTuple ,
52+ blockFromTuple ,
53+ getHeaderRecords ,
54+ EpochAccumulator ,
55+ } from " @ethereumjs/era" ;
56+
57+ const era1File = readBinaryFile (PATH_TO_ERA1_FILE );
5158
5259// validate era1 file
53- const isValid = validateERA1 (era1File )
60+ const isValid = validateERA1 (era1File );
5461
5562// read blocks from era1 file
56- const blocks = readERA1 (era1File )
63+ const blocks = readERA1 (era1File );
5764
5865for await (const blockTuple of blocks ) {
59- const { header, body, receipts } = await parseBlockTuple (blockTuple )
60- const block = blockFromTuple ({ header , body })
61- console .log (block .header .number )
66+ const { header, body, receipts } = await parseBlockTuple (blockTuple );
67+ const block = blockFromTuple ({ header , body });
68+ console .log (block .header .number );
6269}
6370
6471// reconstruct epoch accumulator
65- const headerRecords = await getHeaderRecords (era1File )
66- const epochAccumulator = EpochAccumulator .encode (headerRecords )
67- const epochAccumulatorRoot = EpochAccumulator .merkleRoot (headerRecords )
68-
72+ const headerRecords = await getHeaderRecords (era1File );
73+ const epochAccumulator = EpochAccumulator .encode (headerRecords );
74+ const epochAccumulatorRoot = EpochAccumulator .merkleRoot (headerRecords );
6975```
7076
7177## EthereumJS
0 commit comments