From 4b4b15f405831c98865bc4c1c44e0e9ad292f5d3 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 27 Sep 2016 21:13:54 -0400 Subject: [PATCH] add support for static addresses in contracts config --- demo/chains.json | 19 +++++++++++++++++++ demo/config/contracts.json | 1 + lib/contracts.js | 1 + lib/deploy.js | 25 +++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 demo/chains.json diff --git a/demo/chains.json b/demo/chains.json new file mode 100644 index 00000000..07338e7c --- /dev/null +++ b/demo/chains.json @@ -0,0 +1,19 @@ +{ + "0xb6cfeab83614da04c03db0fb8a6787a45d0be8d576fcc6f8f457a5a816d22ab3": { + "name": "development", + "contracts": { + "2ac097aa929aece4724cc229cc7bd26c7dfa153f3274b5623936cb4a4dc12fa1": { + "address": "0x123", + "name": "token" + }, + "e0d35d6564373021d9749a7a8815cf58cc5ca7b7edaf4740c1913898561531c3": { + "address": "0x9e3b27a53318d4dc0b6716afc5ad146480b86b64", + "name": "SimpleStorage2" + }, + "f3765f8b702ccb44eb19f1adecbf5a216175713fbd41d9fae100d8e3dfc5e74f": { + "address": "0x6ecb595483da2c264ea5e039743340ebce8af0da", + "name": "SimpleStorage" + } + } + } +} \ No newline at end of file diff --git a/demo/config/contracts.json b/demo/config/contracts.json index 4d7f2f72..d5b177d0 100644 --- a/demo/config/contracts.json +++ b/demo/config/contracts.json @@ -3,6 +3,7 @@ "gas": "auto", "contracts": { "token": { + "address": "0x123", "args": [ 100 ] diff --git a/lib/contracts.js b/lib/contracts.js index cf9666cb..c93b25f8 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -52,6 +52,7 @@ ContractsManager.prototype.build = function() { contract.type = 'file'; contract.className = className; + contract.address = contractConfig.address; this.contracts[className] = contract; } diff --git a/lib/deploy.js b/lib/deploy.js index 9613872b..c7d78457 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -15,6 +15,31 @@ var Deploy = function(options) { Deploy.prototype.checkAndDeployContract = function(contract, params, callback) { var self = this; + + if (contract.address !== undefined) { + + // determine arguments + var suppliedArgs = (params || contract.args); + var realArgs = []; + + for (var l = 0; l < suppliedArgs.length; l++) { + var arg = suppliedArgs[l]; + if (arg[0] === "$") { + var contractName = arg.substr(1); + var referedContract = this.contractsManager.getContract(contractName); + realArgs.push(referedContract.deployedAddress); + } else { + realArgs.push(arg); + } + } + + contract.deployedAddress = contract.address; + self.deployTracker.trackContract(contract.className, contract.code, realArgs, contract.address); + self.deployTracker.save(); + self.logger.contractsState(self.contractsManager.contractsState()); + return callback(); + } + var trackedContract = self.deployTracker.getContract(contract.className, contract.code, contract.args); if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") {