Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit f54802f

Browse files
committed
Add BlockchainOptions and document it
1 parent ca7662a commit f54802f

File tree

4 files changed

+184
-44
lines changed

4 files changed

+184
-44
lines changed

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66

77
- [Blockchain](classes/blockchain.md)
88

9+
### Interfaces
10+
11+
- [BlockchainOptions](interfaces/blockchainoptions.md)
12+
913
---

docs/classes/blockchain.md

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,21 @@ new Blockchain({ db: db }).iterator(
7474

7575
### constructor
7676

77-
**new Blockchain**(opts?: _`any`_): [Blockchain](blockchain.md)
77+
**new Blockchain**(opts?: _[BlockchainOptions](../interfaces/blockchainoptions.md)_): [Blockchain](blockchain.md)
7878

79-
_Defined in [index.ts:112](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L112)_
79+
_Defined in [index.ts:155](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L155)_
8080

8181
Creates new Blockchain object
8282

83-
This constructor receives an object with different options, all of them are optional:
84-
85-
- `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'\]
86-
- `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\]
87-
- `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
88-
- `opts.db` - Database to store blocks and metadata. Should be a [levelup](https://github.com/rvagg/node-levelup) instance.
89-
- `opts.validate` - this the flag to validate blocks (e.g. Proof-of-Work), latest HF rules supported: `Constantinople`.
90-
9183
**Deprecation note**:
9284

93-
The old separated DB constructor parameters `opts.blockDB` and `opts.detailsDB` from before the Geth DB-compatible `v3.0.0` release are deprecated and continued usage is discouraged. When provided `opts.blockDB` will be used as `opts.db` and `opts.detailsDB` is ignored. On the storage level the DB formats are not compatible and it is not possible to load an old-format DB state into a post-`v3.0.0` `Blockchain` object.
85+
The old separated DB constructor parameters `opts.blockDB` and `opts.detailsDb` from before the Geth DB-compatible `v3.0.0` release are deprecated and continued usage is discouraged. When provided `opts.blockDB` will be used as `opts.db` and `opts.detailsDB` is ignored. On the storage level the DB formats are not compatible and it is not possible to load an old-format DB state into a post-`v3.0.0` `Blockchain` object.
9486

9587
**Parameters:**
9688

97-
| Name | Type | Default value | Description |
98-
| -------------------- | ----- | ------------- | ------------------------ |
99-
| `Default value` opts | `any` | {} | See above documentation. |
89+
| Name | Type | Default value | Description |
90+
| -------------------- | ------------------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------- |
91+
| `Default value` opts | [BlockchainOptions](../interfaces/blockchainoptions.md) | {} | An object with the options that this constructor takes. See [BlockchainOptions](../interfaces/blockchainoptions.md). |
10092

10193
**Returns:** [Blockchain](blockchain.md)
10294

@@ -110,7 +102,7 @@ The old separated DB constructor parameters `opts.blockDB` and `opts.detailsDB`
110102

111103
**● db**: _`any`_
112104

113-
_Defined in [index.ts:105](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L105)_
105+
_Defined in [index.ts:148](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L148)_
114106

115107
---
116108

@@ -120,7 +112,7 @@ _Defined in [index.ts:105](https://github.com/ethereumjs/ethereumjs-blockchain/b
120112

121113
**● dbManager**: _`DBManager`_
122114

123-
_Defined in [index.ts:106](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L106)_
115+
_Defined in [index.ts:149](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L149)_
124116

125117
---
126118

@@ -130,7 +122,7 @@ _Defined in [index.ts:106](https://github.com/ethereumjs/ethereumjs-blockchain/b
130122

131123
**● ethash**: _`any`_
132124

133-
_Defined in [index.ts:107](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L107)_
125+
_Defined in [index.ts:150](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L150)_
134126

135127
---
136128

@@ -140,7 +132,7 @@ _Defined in [index.ts:107](https://github.com/ethereumjs/ethereumjs-blockchain/b
140132

141133
**● validate**: _`boolean`_
142134

143-
_Defined in [index.ts:112](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L112)_
135+
_Defined in [index.ts:155](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L155)_
144136

145137
A flag indicating if this Blockchain validates blocks or not.
146138

@@ -154,7 +146,7 @@ A flag indicating if this Blockchain validates blocks or not.
154146

155147
**get meta**(): `object`
156148

157-
_Defined in [index.ts:175](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L175)_
149+
_Defined in [index.ts:210](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L210)_
158150

159151
Returns an object with metadata about the Blockchain. It's defined for backwards compatibility.
160152

@@ -170,7 +162,7 @@ Returns an object with metadata about the Blockchain. It's defined for backwards
170162

171163
**delBlock**(blockHash: _`Buffer`_, cb: _`any`_): `void`
172164

173-
_Defined in [index.ts:823](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L823)_
165+
_Defined in [index.ts:858](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L858)_
174166

175167
Deletes a block from the blockchain. All child blocks in the chain are deleted and any encountered heads are set to the parent block.
176168

@@ -191,7 +183,7 @@ Deletes a block from the blockchain. All child blocks in the chain are deleted a
191183

192184
**getBlock**(blockTag: _`Buffer` \| `number` \| `BN`_, cb: _`any`_): `void`
193185

194-
_Defined in [index.ts:560](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L560)_
186+
_Defined in [index.ts:595](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L595)_
195187

196188
Gets a block by its hash.
197189

@@ -212,7 +204,7 @@ Gets a block by its hash.
212204

213205
**getBlocks**(blockId: _`Buffer` \| `number`_, maxBlocks: _`number`_, skip: _`number`_, reverse: _`boolean`_, cb: _`any`_): `void`
214206

215-
_Defined in [index.ts:583](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L583)_
207+
_Defined in [index.ts:618](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L618)_
216208

217209
Looks up many blocks relative to blockId
218210

@@ -236,7 +228,7 @@ Looks up many blocks relative to blockId
236228

237229
**getDetails**(\_: _`string`_, cb: _`any`_): `void`
238230

239-
_Defined in [index.ts:624](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L624)_
231+
_Defined in [index.ts:659](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L659)_
240232

241233
This method used to return block details by its hash. It's only here for backwards compatibility.
242234

@@ -259,7 +251,7 @@ _**deprecated**_:
259251

260252
**getHead**(name: _`any`_, cb?: _`any`_): `void`
261253

262-
_Defined in [index.ts:271](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L271)_
254+
_Defined in [index.ts:306](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L306)_
263255

264256
Returns the specified iterator head.
265257

@@ -280,7 +272,7 @@ Returns the specified iterator head.
280272

281273
**getLatestBlock**(cb: _`any`_): `void`
282274

283-
_Defined in [index.ts:311](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L311)_
275+
_Defined in [index.ts:346](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L346)_
284276

285277
Returns the latest full block in the canonical chain.
286278

@@ -300,7 +292,7 @@ Returns the latest full block in the canonical chain.
300292

301293
**getLatestHeader**(cb: _`any`_): `void`
302294

303-
_Defined in [index.ts:294](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L294)_
295+
_Defined in [index.ts:329](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L329)_
304296

305297
Returns the latest header in the canonical chain.
306298

@@ -320,7 +312,7 @@ Returns the latest header in the canonical chain.
320312

321313
**iterator**(name: _`string`_, onBlock: _`any`_, cb: _`any`_): `void`
322314

323-
_Defined in [index.ts:957](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L957)_
315+
_Defined in [index.ts:992](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L992)_
324316

325317
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.
326318

@@ -342,7 +334,7 @@ Iterates through blocks starting at the specified iterator head and calls the on
342334

343335
**putBlock**(block: _`object`_, cb: _`any`_, isGenesis?: _`undefined` \| `false` \| `true`_): `void`
344336

345-
_Defined in [index.ts:340](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L340)_
337+
_Defined in [index.ts:375](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L375)_
346338

347339
Adds a block to the blockchain.
348340

@@ -364,7 +356,7 @@ Adds a block to the blockchain.
364356

365357
**putBlocks**(blocks: _`Array`<`any`>_, cb: _`any`_): `void`
366358

367-
_Defined in [index.ts:324](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L324)_
359+
_Defined in [index.ts:359](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L359)_
368360

369361
Adds many blocks to the blockchain.
370362

@@ -385,7 +377,7 @@ Adds many blocks to the blockchain.
385377

386378
**putGenesis**(genesis: _`any`_, cb: _`any`_): `void`
387379

388-
_Defined in [index.ts:261](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L261)_
380+
_Defined in [index.ts:296](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L296)_
389381

390382
Puts the genesis block in the database
391383

@@ -406,7 +398,7 @@ Puts the genesis block in the database
406398

407399
**putHeader**(header: _`object`_, cb: _`any`_): `void`
408400

409-
_Defined in [index.ts:372](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L372)_
401+
_Defined in [index.ts:407](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L407)_
410402

411403
Adds a header to the blockchain.
412404

@@ -427,7 +419,7 @@ Adds a header to the blockchain.
427419

428420
**putHeaders**(headers: _`Array`<`any`>_, cb: _`any`_): `void`
429421

430-
_Defined in [index.ts:356](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L356)_
422+
_Defined in [index.ts:391](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L391)_
431423

432424
Adds many headers to the blockchain.
433425

@@ -448,7 +440,7 @@ Adds many headers to the blockchain.
448440

449441
**selectNeededHashes**(hashes: _`Array`<`any`>_, cb: _`any`_): `void`
450442

451-
_Defined in [index.ts:634](https://github.com/ethereumjs/ethereumjs-blockchain/blob/c93b4dd/src/index.ts#L634)_
443+
_Defined in [index.ts:669](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L669)_
452444

453445
Given an ordered array, returns to the callback an array of hashes that are not in the blockchain yet.
454446

docs/interfaces/blockchainoptions.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
[ethereumjs-blockchain](../README.md) > [BlockchainOptions](../interfaces/blockchainoptions.md)
2+
3+
# Interface: BlockchainOptions
4+
5+
This are the options that the Blockchain constructor can receive.
6+
7+
## Hierarchy
8+
9+
**BlockchainOptions**
10+
11+
## Index
12+
13+
### Properties
14+
15+
- [blockDb](blockchainoptions.md#blockdb)
16+
- [chain](blockchainoptions.md#chain)
17+
- [common](blockchainoptions.md#common)
18+
- [db](blockchainoptions.md#db)
19+
- [detailsDb](blockchainoptions.md#detailsdb)
20+
- [hardfork](blockchainoptions.md#hardfork)
21+
- [validate](blockchainoptions.md#validate)
22+
23+
---
24+
25+
## Properties
26+
27+
<a id="blockdb"></a>
28+
29+
### `<Optional>` blockDb
30+
31+
**● blockDb**: _`any`_
32+
33+
_Defined in [index.ts:58](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L58)_
34+
35+
_**deprecated**_:
36+
37+
---
38+
39+
<a id="chain"></a>
40+
41+
### `<Optional>` chain
42+
43+
**● chain**: _`string` \| `number`_
44+
45+
_Defined in [index.ts:30](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L30)_
46+
47+
The chain id or name. Default: `"mainnet"`.
48+
49+
---
50+
51+
<a id="common"></a>
52+
53+
### `<Optional>` common
54+
55+
**● common**: _`Common`_
56+
57+
_Defined in [index.ts:41](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L41)_
58+
59+
An alternative way to specify the chain and hardfork is by passing a Common instance.
60+
61+
---
62+
63+
<a id="db"></a>
64+
65+
### `<Optional>` db
66+
67+
**● db**: _`any`_
68+
69+
_Defined in [index.ts:47](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L47)_
70+
71+
Database to store blocks and metadata. Should be a [levelup](https://github.com/rvagg/node-levelup) instance.
72+
73+
---
74+
75+
<a id="detailsdb"></a>
76+
77+
### `<Optional>` detailsDb
78+
79+
**● detailsDb**: _`any`_
80+
81+
_Defined in [index.ts:63](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L63)_
82+
83+
_**deprecated**_:
84+
85+
---
86+
87+
<a id="hardfork"></a>
88+
89+
### `<Optional>` hardfork
90+
91+
**● hardfork**: _`string` \| `null`_
92+
93+
_Defined in [index.ts:36](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L36)_
94+
95+
Hardfork for the blocks. If `undefined` or `null` is passed, it gets computed based on block numbers.
96+
97+
---
98+
99+
<a id="validate"></a>
100+
101+
### `<Optional>` validate
102+
103+
**● validate**: _`undefined` \| `false` \| `true`_
104+
105+
_Defined in [index.ts:53](https://github.com/ethereumjs/ethereumjs-blockchain/blob/ca7662a/src/index.ts#L53)_
106+
107+
This the flag indicates if blocks should be validated (e.g. Proof-of-Work), latest HF rules supported: `Petersburg`.
108+
109+
---

0 commit comments

Comments
 (0)