From 527dbcca8b4bcdcb196ff7d6dbfcbc3cb40420ba Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 25 Sep 2018 14:58:19 +0100 Subject: [PATCH] Delay contract deploiement if share bytecode --- lib/modules/blockchain_connector/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index 8d81e48c..e59090f7 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) {