@@ -18,6 +18,8 @@ export default class Blockchain {
1818 this . startedClient = null ;
1919 this . plugins = options . plugins ;
2020 this . blockchainClients = { } ;
21+ this . warnIfPackageNotDefinedLocally = options . warnIfPackageNotDefinedLocally ?? warnIfPackageNotDefinedLocally ;
22+ this . Web3 = options . Web3 ?? Web3 ;
2123
2224 this . registerConsoleCommands ( ) ;
2325
@@ -30,17 +32,17 @@ export default class Blockchain {
3032 }
3133
3234 this . blockchainNodes = { } ;
33- this . events . setCommandHandler ( "blockchain:node:register" , ( clientName , clientFunctions ) => {
35+ this . events . setCommandHandler ( "blockchain:node:register" , ( clientName , clientFunctions , cb = ( ) => { } ) => {
3436 const { isStartedFn, launchFn, stopFn, provider} = clientFunctions ;
3537
3638 if ( ! isStartedFn ) {
37- throw new Error ( `Blockchain client '${ clientName } ' must be registered with an 'isStarted' function, client not registered.` ) ;
39+ return cb ( `Blockchain client '${ clientName } ' must be registered with an 'isStarted' function, client not registered.` ) ;
3840 }
3941 if ( ! launchFn ) {
40- throw new Error ( `Blockchain client '${ clientName } ' must be registered with a 'launchFn' function, client not registered.` ) ;
42+ return cb ( `Blockchain client '${ clientName } ' must be registered with a 'launchFn' function, client not registered.` ) ;
4143 }
4244 if ( ! stopFn ) {
43- throw new Error ( `Blockchain client '${ clientName } ' must be registered with a 'stopFn' function, client not registered.` ) ;
45+ return cb ( `Blockchain client '${ clientName } ' must be registered with a 'stopFn' function, client not registered.` ) ;
4446 }
4547 if ( ! provider ) {
4648 // Set default provider function
@@ -50,6 +52,7 @@ export default class Blockchain {
5052 }
5153
5254 this . blockchainNodes [ clientName ] = clientFunctions ;
55+ cb ( ) ;
5356 } ) ;
5457
5558 this . events . setCommandHandler ( "blockchain:node:start" , ( blockchainConfig , cb ) => {
@@ -135,8 +138,9 @@ export default class Blockchain {
135138 cb ( null , this . getProviderFromTemplate ( this . blockchainConfig . endpoint ) ) ;
136139 } ) ;
137140
138- this . events . setCommandHandler ( "blockchain:client:register" , ( clientName , getProviderFunction ) => {
141+ this . events . setCommandHandler ( "blockchain:client:register" , ( clientName , getProviderFunction , cb = ( ) => { } ) => {
139142 this . blockchainClients [ clientName ] = getProviderFunction ;
143+ cb ( ) ;
140144 } ) ;
141145
142146 this . events . setCommandHandler ( "blockchain:client:provider" , async ( clientName , cb ) => {
@@ -161,26 +165,26 @@ export default class Blockchain {
161165 this . blockchainApi . registerRequests ( "ethereum" ) ;
162166
163167 if ( this . blockchainConfig . enabled && this . blockchainConfig . client === "geth" ) {
164- warnIfPackageNotDefinedLocally ( "embark-geth" , this . embark . logger . warn . bind ( this . embark . logger ) , this . embark . config . embarkConfig ) ;
168+ this . warnIfPackageNotDefinedLocally ( "embark-geth" , this . embark . logger . warn . bind ( this . embark . logger ) , this . embark . config . embarkConfig ) ;
165169 }
166170 if ( this . blockchainConfig . enabled && this . blockchainConfig . client === "parity" ) {
167- warnIfPackageNotDefinedLocally ( "embark-parity" , this . embark . logger . warn . bind ( this . embark . logger ) , this . embark . config . embarkConfig ) ;
171+ this . warnIfPackageNotDefinedLocally ( "embark-parity" , this . embark . logger . warn . bind ( this . embark . logger ) , this . embark . config . embarkConfig ) ;
168172 }
169173 }
170174
171175 getProviderFromTemplate ( endpoint ) {
172176 if ( endpoint . startsWith ( 'ws' ) ) {
173- return new Web3 . providers . WebsocketProvider ( endpoint , {
177+ return new this . Web3 . providers . WebsocketProvider ( endpoint , {
174178 headers : { Origin : constants . embarkResourceOrigin }
175179 } ) ;
176180 }
177- const web3 = new Web3 ( endpoint ) ;
181+ const web3 = new this . Web3 ( endpoint ) ;
178182 return web3 . currentProvider ;
179183 }
180184
181185 async addArtifactFile ( _params , cb ) {
182186 if ( ! this . blockchainConfig . enabled ) {
183- cb ( ) ;
187+ return cb ( ) ;
184188 }
185189
186190 try {
0 commit comments