You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 6, 2020. It is now read-only.
@@ -35,8 +66,32 @@ export default class Blockchain {
35
66
db: any
36
67
dbManager: DBManager
37
68
ethash: any
69
+
70
+
/**
71
+
* A flag indicating if this Blockchain validates blocks or not.
72
+
*/
38
73
validate: boolean
39
74
75
+
/**
76
+
* Creates new Blockchain object
77
+
*
78
+
* This constructor receives an object with different options, all of them are optional:
79
+
*
80
+
* * `opts.chain` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))** The chain for the block [default: 'mainnet']
81
+
* * `opts.hardfork` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Hardfork for the block [default: null, block number-based behavior]
82
+
* * `opts.common` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Alternatively pass a Common instance (ethereumjs-common) instead of setting chain/hardfork directly
83
+
* * `opts.db` - Database to store blocks and metadata. Should be a [levelup](https://github.com/rvagg/node-levelup) instance.
84
+
* * `opts.validate` - this the flag to validate blocks (e.g. Proof-of-Work), latest HF rules supported: `Constantinople`.
85
+
*
86
+
* **Deprecation note**:
87
+
*
88
+
* The old separated DB constructor parameters `opts.blockDB` and `opts.detailsDB` from before the Geth DB-compatible
89
+
* `v3.0.0` release are deprecated and continued usage is discouraged. When provided `opts.blockDB` will be used as
90
+
* `opts.db` and `opts.detailsDB` is ignored. On the storage level the DB formats are not compatible and it is not
91
+
* possible to load an old-format DB state into a post-`v3.0.0` `Blockchain` object.
92
+
*
93
+
* @param opts See above documentation.
94
+
*/
40
95
constructor(opts: any={}){
41
96
if(opts.common){
42
97
if(opts.chain){
@@ -76,7 +131,7 @@ export default class Blockchain {
76
131
}
77
132
78
133
/**
79
-
* Define meta getter for backwards compatibility
134
+
* Returns an object with metadata about the Blockchain. It's defined for backwards compatibility.
80
135
*/
81
136
getmeta(){
82
137
return{
@@ -156,13 +211,19 @@ export default class Blockchain {
156
211
157
212
/**
158
213
* Puts the genesis block in the database
214
+
*
215
+
* @param genesis - The genesis block to be added
216
+
* @param cb - The callback. It is given two parameters `err` and the saved `block`
159
217
*/
160
218
putGenesis(genesis: any,cb: any): void{
161
219
this.putBlock(genesis,cb,true)
162
220
}
163
221
164
222
/**
165
223
* Returns the specified iterator head.
224
+
*
225
+
* @param name - Optional name of the state root head (default: 'vm')
226
+
* @param cb - The callback. It is given two parameters `err` and the returned `block`
166
227
*/
167
228
getHead(name: any,cb?: any): void{
168
229
// handle optional args
@@ -184,6 +245,8 @@ export default class Blockchain {
184
245
185
246
/**
186
247
* Returns the latest header in the canonical chain.
248
+
*
249
+
* @param cb - The callback. It is given two parameters `err` and the returned `header`
187
250
*/
188
251
getLatestHeader(cb: any): void{
189
252
// ensure init completed
@@ -199,6 +262,8 @@ export default class Blockchain {
199
262
200
263
/**
201
264
* Returns the latest full block in the canonical chain.
265
+
*
266
+
* @param cb - The callback. It is given two parameters `err` and the returned `block`
202
267
*/
203
268
getLatestBlock(cb: any){
204
269
// ensure init completed
@@ -208,7 +273,10 @@ export default class Blockchain {
208
273
}
209
274
210
275
/**
211
-
* Adds many blocks to the blockchain
276
+
* Adds many blocks to the blockchain.
277
+
*
278
+
* @param blocks - The blocks to be added to the blockchain
279
+
* @param cb - The callback. It is given two parameters `err` and the last of the saved `blocks`
212
280
*/
213
281
putBlocks(blocks: Array<any>,cb: any){
214
282
async.eachSeries(
@@ -221,7 +289,10 @@ export default class Blockchain {
221
289
}
222
290
223
291
/**
224
-
* Adds a block to the blockchain
292
+
* Adds a block to the blockchain.
293
+
*
294
+
* @param block - The block to be added to the blockchain
295
+
* @param cb - The callback. It is given two parameters `err` and the saved `block`
@@ -234,7 +305,10 @@ export default class Blockchain {
234
305
}
235
306
236
307
/**
237
-
* Adds many headers to the blockchain
308
+
* Adds many headers to the blockchain.
309
+
*
310
+
* @param headers - The headers to be added to the blockchain
311
+
* @param cb - The callback. It is given two parameters `err` and the last of the saved `headers`
238
312
*/
239
313
putHeaders(headers: Array<any>,cb: any){
240
314
async.eachSeries(
@@ -247,7 +321,10 @@ export default class Blockchain {
247
321
}
248
322
249
323
/**
250
-
* Adds a header to the blockchain
324
+
* Adds a header to the blockchain.
325
+
*
326
+
* @param header - The header to be added to the blockchain
327
+
* @param cb - The callback. It is given two parameters `err` and the saved `header`
251
328
*/
252
329
putHeader(header: object,cb: any){
253
330
// make sure init has completed
@@ -429,7 +506,10 @@ export default class Blockchain {
429
506
}
430
507
431
508
/**
432
-
*Gets a block by its hash
509
+
* Gets a block by its hash.
510
+
*
511
+
* @param blockTag - The block's hash or number
512
+
* @param cb - The callback. It is given two parameters `err` and the found `block` (an instance of https://github.com/ethereumjs/ethereumjs-block) if any.
433
513
*/
434
514
getBlock(blockTag: Buffer|number|BN,cb: any){
435
515
// ensure init completed
@@ -438,12 +518,18 @@ export default class Blockchain {
0 commit comments