Skip to content

Commit fa74b13

Browse files
committed
Deprecate validate fields from Blockchain and BlockchainOptions
1 parent 90b81e3 commit fa74b13

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/index.ts

+23-10
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,21 @@ export interface BlockchainOptions {
9494

9595
/**
9696
* This the flag indicates if blocks and Proof-of-Work should be validated. Defaults to true.
97-
* See
97+
* This option can't be used in conjunction with `validatePow` nor `validateBlocks`.
98+
*
99+
* @deprecated
98100
*/
99101
validate?: boolean
100102

101103
/**
102-
* This flags indicates if Proof-of-work should be validated. Defaults to the value of `validate`.
104+
* This flags indicates if Proof-of-work should be validated. If `validate` is provided, this
105+
* option takes its value.
103106
*/
104107
validatePow?: boolean
105108

106109
/**
107-
* This flags indicates if blocks should be validated. See Block#validate for details. Defaults to
108-
* the value of `validate`.
110+
* This flags indicates if blocks should be validated. See Block#validate for details. If
111+
* `validate` is provided, this option takes its value.
109112
*/
110113
validateBlocks?: boolean
111114
}
@@ -169,9 +172,12 @@ export default class Blockchain implements BlockchainInterface {
169172
ethash: any
170173

171174
/**
172-
* A flag indicating if this Blockchain validates blocks or not.
175+
* This field is always `true`. It's here only for backwards compatibility.
176+
*
177+
* @deprecated
173178
*/
174-
public readonly validate: boolean
179+
public readonly validate: boolean = true
180+
175181
private readonly _validatePow: boolean
176182
private readonly _validateBlocks: boolean
177183

@@ -192,13 +198,20 @@ export default class Blockchain implements BlockchainInterface {
192198
this._common = new Common(chain, hardfork)
193199
}
194200

201+
if (opts.validate !== undefined) {
202+
if (opts.validatePow !== undefined || opts.validateBlocks !== undefined) {
203+
throw new Error(
204+
"opts.validate can't be used at the same time than opts.validatePow nor opts.validateBlocks",
205+
)
206+
}
207+
}
208+
195209
// defaults
196210
this.db = opts.db ? opts.db : level()
197211
this.dbManager = new DBManager(this.db, this._common)
198-
this.validate = opts.validate === undefined ? true : opts.validate
199-
this._validatePow = opts.validatePow !== undefined ? opts.validatePow : this.validate
200-
this._validateBlocks = opts.validateBlocks !== undefined ? opts.validateBlocks : this.validate
201-
this.ethash = this.validate ? new Ethash(this.db) : null
212+
this._validatePow = opts.validatePow !== undefined ? opts.validatePow : !!opts.validate
213+
this._validateBlocks = opts.validateBlocks !== undefined ? opts.validateBlocks : !!opts.validate
214+
this.ethash = this._validatePow ? new Ethash(this.db) : null
202215
this._heads = {}
203216
this._genesis = null
204217
this._headHeader = null

0 commit comments

Comments
 (0)