@@ -94,18 +94,21 @@ export interface BlockchainOptions {
94
94
95
95
/**
96
96
* 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
98
100
*/
99
101
validate ?: boolean
100
102
101
103
/**
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.
103
106
*/
104
107
validatePow ?: boolean
105
108
106
109
/**
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 .
109
112
*/
110
113
validateBlocks ?: boolean
111
114
}
@@ -169,9 +172,12 @@ export default class Blockchain implements BlockchainInterface {
169
172
ethash : any
170
173
171
174
/**
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
173
178
*/
174
- public readonly validate : boolean
179
+ public readonly validate : boolean = true
180
+
175
181
private readonly _validatePow : boolean
176
182
private readonly _validateBlocks : boolean
177
183
@@ -192,13 +198,20 @@ export default class Blockchain implements BlockchainInterface {
192
198
this . _common = new Common ( chain , hardfork )
193
199
}
194
200
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
+
195
209
// defaults
196
210
this . db = opts . db ? opts . db : level ( )
197
211
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
202
215
this . _heads = { }
203
216
this . _genesis = null
204
217
this . _headHeader = null
0 commit comments