@@ -6,28 +6,6 @@ This class stores and interacts with blocks.
6
6
7
7
_ ** remarks** _ : This class performs write operations. Making a backup of your data before trying this module is recommended. Otherwise, you can end up with a compromised DB state.
8
8
9
- _ ** example** _ : The following is an example to iterate through an existing Geth DB (needs ` level ` to be installed separately).
10
-
11
- ``` javascript
12
- const level = require (' level' )
13
- const Blockchain = require (' ethereumjs-blockchain' )
14
- const utils = require (' ethereumjs-util' )
15
-
16
- const gethDbPath = ' ./chaindata' // Add your own path here. It will get modified, see remarks.
17
- const db = level (gethDbPath)
18
-
19
- new Blockchain ({ db: db }).iterator (
20
- ' i' ,
21
- (block , reorg , cb ) => {
22
- const blockNumber = utils .bufferToInt (block .header .number )
23
- const blockHash = block .hash ().toString (' hex' )
24
- console .log (` BLOCK ${ blockNumber} : ${ blockHash} ` )
25
- cb ()
26
- },
27
- err => console .log (err \| \| ' Done.' ),
28
- )
29
- ```
30
-
31
9
## Hierarchy
32
10
33
11
** Blockchain**
@@ -76,7 +54,7 @@ new Blockchain({ db: db }).iterator(
76
54
77
55
⊕ ** new Blockchain** (opts?: _ [ BlockchainOptions] ( ../interfaces/blockchainoptions.md ) _ ): [ Blockchain] ( blockchain.md )
78
56
79
- _ Defined in [ index.ts:155 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L155 ) _
57
+ _ Defined in [ index.ts:131 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L131 ) _
80
58
81
59
Creates new Blockchain object
82
60
@@ -102,7 +80,7 @@ The old separated DB constructor parameters `opts.blockDB` and `opts.detailsDb`
102
80
103
81
** ● db** : _ ` any ` _
104
82
105
- _ Defined in [ index.ts:148 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L148 ) _
83
+ _ Defined in [ index.ts:124 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L124 ) _
106
84
107
85
---
108
86
@@ -112,7 +90,7 @@ _Defined in [index.ts:148](https://github.com/ethereumjs/ethereumjs-blockchain/b
112
90
113
91
** ● dbManager** : _ ` DBManager ` _
114
92
115
- _ Defined in [ index.ts:149 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L149 ) _
93
+ _ Defined in [ index.ts:125 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L125 ) _
116
94
117
95
---
118
96
@@ -122,7 +100,7 @@ _Defined in [index.ts:149](https://github.com/ethereumjs/ethereumjs-blockchain/b
122
100
123
101
** ● ethash** : _ ` any ` _
124
102
125
- _ Defined in [ index.ts:150 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L150 ) _
103
+ _ Defined in [ index.ts:126 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L126 ) _
126
104
127
105
---
128
106
@@ -132,7 +110,7 @@ _Defined in [index.ts:150](https://github.com/ethereumjs/ethereumjs-blockchain/b
132
110
133
111
** ● validate** : _ ` boolean ` _
134
112
135
- _ Defined in [ index.ts:155 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L155 ) _
113
+ _ Defined in [ index.ts:131 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L131 ) _
136
114
137
115
A flag indicating if this Blockchain validates blocks or not.
138
116
@@ -146,7 +124,7 @@ A flag indicating if this Blockchain validates blocks or not.
146
124
147
125
** get meta** (): ` object `
148
126
149
- _ Defined in [ index.ts:210 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L210 ) _
127
+ _ Defined in [ index.ts:186 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L186 ) _
150
128
151
129
Returns an object with metadata about the Blockchain. It's defined for backwards compatibility.
152
130
@@ -162,7 +140,7 @@ Returns an object with metadata about the Blockchain. It's defined for backwards
162
140
163
141
▸ ** delBlock** (blockHash: _ ` Buffer ` _ , cb: _ ` any ` _ ): ` void `
164
142
165
- _ Defined in [ index.ts:858 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L858 ) _
143
+ _ Defined in [ index.ts:834 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L834 ) _
166
144
167
145
Deletes a block from the blockchain. All child blocks in the chain are deleted and any encountered heads are set to the parent block.
168
146
@@ -183,7 +161,7 @@ Deletes a block from the blockchain. All child blocks in the chain are deleted a
183
161
184
162
▸ ** getBlock** (blockTag: _ ` Buffer ` \| ` number ` \| ` BN ` _ , cb: _ ` any ` _ ): ` void `
185
163
186
- _ Defined in [ index.ts:595 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L595 ) _
164
+ _ Defined in [ index.ts:571 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L571 ) _
187
165
188
166
Gets a block by its hash.
189
167
@@ -204,7 +182,7 @@ Gets a block by its hash.
204
182
205
183
▸ ** getBlocks** (blockId: _ ` Buffer ` \| ` number ` _ , maxBlocks: _ ` number ` _ , skip: _ ` number ` _ , reverse: _ ` boolean ` _ , cb: _ ` any ` _ ): ` void `
206
184
207
- _ Defined in [ index.ts:618 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L618 ) _
185
+ _ Defined in [ index.ts:594 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L594 ) _
208
186
209
187
Looks up many blocks relative to blockId
210
188
@@ -228,7 +206,7 @@ Looks up many blocks relative to blockId
228
206
229
207
▸ ** getDetails** (\_ : _ ` string ` _ , cb: _ ` any ` _ ): ` void `
230
208
231
- _ Defined in [ index.ts:659 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L659 ) _
209
+ _ Defined in [ index.ts:635 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L635 ) _
232
210
233
211
This method used to return block details by its hash. It's only here for backwards compatibility.
234
212
@@ -251,7 +229,7 @@ _**deprecated**_:
251
229
252
230
▸ ** getHead** (name: _ ` any ` _ , cb?: _ ` any ` _ ): ` void `
253
231
254
- _ Defined in [ index.ts:306 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L306 ) _
232
+ _ Defined in [ index.ts:282 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L282 ) _
255
233
256
234
Returns the specified iterator head.
257
235
@@ -272,7 +250,7 @@ Returns the specified iterator head.
272
250
273
251
▸ ** getLatestBlock** (cb: _ ` any ` _ ): ` void `
274
252
275
- _ Defined in [ index.ts:346 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L346 ) _
253
+ _ Defined in [ index.ts:322 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L322 ) _
276
254
277
255
Returns the latest full block in the canonical chain.
278
256
@@ -292,7 +270,7 @@ Returns the latest full block in the canonical chain.
292
270
293
271
▸ ** getLatestHeader** (cb: _ ` any ` _ ): ` void `
294
272
295
- _ Defined in [ index.ts:329 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L329 ) _
273
+ _ Defined in [ index.ts:305 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L305 ) _
296
274
297
275
Returns the latest header in the canonical chain.
298
276
@@ -312,7 +290,7 @@ Returns the latest header in the canonical chain.
312
290
313
291
▸ ** iterator** (name: _ ` string ` _ , onBlock: _ ` any ` _ , cb: _ ` any ` _ ): ` void `
314
292
315
- _ Defined in [ index.ts:992 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L992 ) _
293
+ _ Defined in [ index.ts:968 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L968 ) _
316
294
317
295
Iterates through blocks starting at the specified iterator head and calls the onBlock function on each block. The current location of an iterator head can be retrieved using the ` getHead() ` method.
318
296
@@ -334,7 +312,7 @@ Iterates through blocks starting at the specified iterator head and calls the on
334
312
335
313
▸ ** putBlock** (block: _ ` object ` _ , cb: _ ` any ` _ , isGenesis?: _ ` undefined ` \| ` false ` \| ` true ` _ ): ` void `
336
314
337
- _ Defined in [ index.ts:375 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L375 ) _
315
+ _ Defined in [ index.ts:351 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L351 ) _
338
316
339
317
Adds a block to the blockchain.
340
318
@@ -356,7 +334,7 @@ Adds a block to the blockchain.
356
334
357
335
▸ ** putBlocks** (blocks: _ ` Array ` <` any ` >_ , cb: _ ` any ` _ ): ` void `
358
336
359
- _ Defined in [ index.ts:359 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L359 ) _
337
+ _ Defined in [ index.ts:335 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L335 ) _
360
338
361
339
Adds many blocks to the blockchain.
362
340
@@ -377,7 +355,7 @@ Adds many blocks to the blockchain.
377
355
378
356
▸ ** putGenesis** (genesis: _ ` any ` _ , cb: _ ` any ` _ ): ` void `
379
357
380
- _ Defined in [ index.ts:296 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L296 ) _
358
+ _ Defined in [ index.ts:272 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L272 ) _
381
359
382
360
Puts the genesis block in the database
383
361
@@ -398,7 +376,7 @@ Puts the genesis block in the database
398
376
399
377
▸ ** putHeader** (header: _ ` object ` _ , cb: _ ` any ` _ ): ` void `
400
378
401
- _ Defined in [ index.ts:407 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L407 ) _
379
+ _ Defined in [ index.ts:383 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L383 ) _
402
380
403
381
Adds a header to the blockchain.
404
382
@@ -419,7 +397,7 @@ Adds a header to the blockchain.
419
397
420
398
▸ ** putHeaders** (headers: _ ` Array ` <` any ` >_ , cb: _ ` any ` _ ): ` void `
421
399
422
- _ Defined in [ index.ts:391 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L391 ) _
400
+ _ Defined in [ index.ts:367 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L367 ) _
423
401
424
402
Adds many headers to the blockchain.
425
403
@@ -440,7 +418,7 @@ Adds many headers to the blockchain.
440
418
441
419
▸ ** selectNeededHashes** (hashes: _ ` Array ` <` any ` >_ , cb: _ ` any ` _ ): ` void `
442
420
443
- _ Defined in [ index.ts:669 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a /src/index.ts#L669 ) _
421
+ _ Defined in [ index.ts:645 ] ( https://github.com/ethereumjs/ethereumjs-blockchain/blob/f54802f /src/index.ts#L645 ) _
444
422
445
423
Given an ordered array, returns to the callback an array of hashes that are not in the blockchain yet.
446
424
0 commit comments