diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index 8d81e48c4..e59090f7e 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -20,6 +20,7 @@ class BlockchainConnector { this.isDev = options.isDev; this.web3Endpoint = ''; this.isWeb3Ready = false; + this.deployers = {}; self.events.setCommandHandler("blockchain:web3:isReady", (cb) => { cb(self.isWeb3Ready); @@ -232,9 +233,29 @@ class BlockchainConnector { } deployContractFromObject(deployContractObject, params, cb) { + let deployer = this.deployers[deployContractObject._deployData]; + + if (!deployer) { + deployer = {running: false, requested: []}; + this.deployers[deployContractObject._deployData] = deployer; + } + + if (deployer.running) { + deployer.requested.push({deployContractObject, params, cb}); + return; + } + + deployer.running = true; embarkJsUtils.secureSend(this.web3, deployContractObject, { from: params.from, gas: params.gas, gasPrice: params.gasPrice - }, true, cb); + }, true, (error, receipt) => { + deployer.running = false; + if (deployer.requested.length > 0) { + let request = deployer.requested.shift(); + this.deployContractFromObject(request.deployContractObject, request.params, request.cb); + } + cb(error, receipt); + }); } determineDefaultAccount(cb) {