@@ -25,7 +25,7 @@ export interface ChainOptions {
2525 /**
2626 * Specify a blockchain which implements the Chain interface
2727 */
28- blockchain ?: Chain
28+ blockchain ?: Blockchain
2929
3030 /**
3131 * Logging provider
@@ -80,14 +80,6 @@ export interface GenesisBlockParams {
8080 [ key : string ] : Buffer
8181}
8282
83- /**
84- * Default blockchain constructor options
85- */
86- const defaultOptions = {
87- logger : defaultLogger ,
88- common : new Common ( { chain : 'mainnet' , hardfork : 'chainstart' } ) ,
89- }
90-
9183/**
9284 * Blockchain
9385 * @memberof module:blockchain
@@ -97,7 +89,7 @@ export class Chain extends EventEmitter {
9789 public common : Common
9890 public db : any
9991 public blockchain : Blockchain
100- public opened = false
92+ public opened : boolean
10193
10294 private _headers : ChainHeaders = {
10395 latest : null ,
@@ -115,35 +107,21 @@ export class Chain extends EventEmitter {
115107 * Create new chain
116108 * @param {ChainOptions } options
117109 */
118- constructor ( options ? : ChainOptions ) {
110+ constructor ( options : ChainOptions = { } ) {
119111 super ( )
120- options = { ...defaultOptions , ...options }
121- this . logger = options . logger !
122- this . common = options . common !
123- this . db = options . db
124-
125- //@ts -ignore Blockchain will be set in init
126- this . blockchain = options . blockchain
127- this . init ( )
128- }
112+ this . logger = options . logger || defaultLogger
113+ this . common = options . common || new Common ( { chain : 'mainnet' , hardfork : 'chainstart' } )
129114
130- /**
131- * Initializes blockchain
132- */
133- private init ( ) {
134- if ( ! this . blockchain ) {
135- this . blockchain = new Blockchain ( {
136- db : this . db ,
115+ this . blockchain =
116+ options . blockchain ||
117+ new Blockchain ( {
118+ db : options . db ,
137119 validateBlocks : false ,
138120 validatePow : false ,
139121 common : this . common ,
140122 } )
141- if ( ! this . db ) {
142- this . db = this . blockchain . db
143- }
144- }
145123
146- this . reset ( )
124+ this . db = this . blockchain . db
147125 this . opened = false
148126 }
149127
0 commit comments