From 505ca5d14f733672a2f7f58f34b8d029ebf12dab Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 9 Jul 2015 08:23:04 -0400 Subject: [PATCH] wait & set contract addresses on deployment --- lib/deploy.js | 22 +++++++++++----------- test/deploy.js | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index a90eb30b5..a4b300443 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -65,13 +65,20 @@ Deploy.prototype.deploy_contracts = function(env) { }); var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash; - this.deployedContracts[className] = transactionHash; // TODO: get this with sync until a different mechanism is implemented //this.deployedContracts[className] = contractAddress; //console.log("address is " + contractAddress); - console.log("deployed " + className + " with transaction hash " + transactionHash); - //console.log("deployed " + className + " at " + contractAddress); + console.log('trying to obtain ' + className + ' address...'); + var receipt = null; + while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null) { + sleep.sleep(1); + } + var contractAddress = receipt.contractAddress; + this.deployedContracts[className] = contractAddress; + console.log('address is ' + contractAddress); + + console.log("deployed " + className + " at " + contractAddress); } } @@ -88,15 +95,8 @@ Deploy.prototype.generate_abi_file = function() { var contract = this.contractDB[className]; var abi = JSON.stringify(contract.compiled.info.abiDefinition); - var transactionHash = deployedContract; - //var contractAddress = deployedContract; + var contractAddress = deployedContract; - console.log('trying to obtain ' + className + ' address...'); - var receipt = null; - while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null) { - sleep.sleep(1); - } - var contractAddress = receipt.contractAddress; console.log('address is ' + contractAddress); result += className + "Abi = " + abi + ";"; diff --git a/test/deploy.js b/test/deploy.js index 6070d22cf..de02529bc 100644 --- a/test/deploy.js +++ b/test/deploy.js @@ -61,7 +61,7 @@ describe('embark.deploy', function() { it("should deploy contracts", function() { var result = deploy.generate_abi_file(); - assert.strictEqual(result, "web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));web3.eth.defaultAccount = web3.eth.accounts[0];var SimpleStorageAbi = 123;var SimpleStorageContract = web3.eth.contract(SimpleStorageAbi);var SimpleStorage = SimpleStorageContract.at('0x123');var AnotherStorageAbi = 234;var AnotherStorageContract = web3.eth.contract(AnotherStorageAbi);var AnotherStorage = AnotherStorageContract.at('0x234');"); + assert.strictEqual(result, "web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));web3.eth.defaultAccount = web3.eth.accounts[0];SimpleStorageAbi = 123;SimpleStorageContract = web3.eth.contract(SimpleStorageAbi);SimpleStorage = SimpleStorageContract.at('0x123');AnotherStorageAbi = 234;AnotherStorageContract = web3.eth.contract(AnotherStorageAbi);AnotherStorage = AnotherStorageContract.at('0x234');"); }); }); });