From 01260b889dc1e219e5f3ce82849fe2085717c37e Mon Sep 17 00:00:00 2001 From: Joris Bontje Date: Wed, 5 Aug 2015 14:35:39 +0200 Subject: [PATCH 1/7] default to empty set when chains.json is missing --- lib/chain_manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/chain_manager.js b/lib/chain_manager.js index 157d6423a..9dc8e5c32 100644 --- a/lib/chain_manager.js +++ b/lib/chain_manager.js @@ -3,17 +3,18 @@ var web3 = require('web3'); var sha3_256 = require('js-sha3').sha3_256; ChainManager = function() { + this.chainManagerConfig = {}; this.currentChain = {}; this.file = ""; } ChainManager.prototype.loadConfigFile = function(filename) { + this.file = filename; try { var obj = JSON.parse(fs.readFileSync(filename)); - this.file = filename; this.chainManagerConfig = obj; } catch (e) { - throw new Error("error reading " + filename); + console.warn("error reading " + filename + "; defaulting to empty set"); } return this; }; @@ -51,4 +52,3 @@ ChainManager.prototype.save = function() { } module.exports = ChainManager; - From efdf24c49bf3868966441dc008c78b7a3c463f19 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Aug 2015 10:01:44 -0400 Subject: [PATCH 2/7] if contract already deployed record it and generate api; also re-run ondeploy --- lib/deploy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/deploy.js b/lib/deploy.js index 81fcf08a4..d0be3c064 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -70,6 +70,8 @@ Deploy.prototype.deploy_contracts = function(env) { if (chainContract != undefined) { console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address); + this.deployedContracts[className] = contractAddress; + this.execute_cmds(contract.onDeploy); } else { From 5e15cc7e3f24de624e06b432a037c265305448ee Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Aug 2015 10:02:18 -0400 Subject: [PATCH 3/7] update to 0.8.2 --- bin/embark | 2 +- boilerplate/package.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/embark b/bin/embark index 1d9846809..d72547e0e 100644 --- a/bin/embark +++ b/bin/embark @@ -32,7 +32,7 @@ var deploy = function(env, embarkConfig) { } program - .version('0.8.1') + .version('0.8.2') program.command('new [name]').description('New application').action(function(name) { if (name === undefined) { diff --git a/boilerplate/package.json b/boilerplate/package.json index 09bde0130..7e77698fe 100644 --- a/boilerplate/package.json +++ b/boilerplate/package.json @@ -10,7 +10,7 @@ "license": "ISC", "homepage": "", "devDependencies": { - "embark-framework": "^0.8.1", + "embark-framework": "^0.8.2", "grunt-embark": "^0.3.0", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-coffee": "^0.13.0", diff --git a/package.json b/package.json index 09a01ebc0..015f83b8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "embark-framework", - "version": "0.8.1", + "version": "0.8.2", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" From c667d8ad668ac4f10ffe4213bb00cb7421b14583 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Aug 2015 10:11:32 -0400 Subject: [PATCH 4/7] fix contact address --- lib/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/deploy.js b/lib/deploy.js index d0be3c064..2c6b85613 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -70,7 +70,7 @@ Deploy.prototype.deploy_contracts = function(env) { if (chainContract != undefined) { console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address); - this.deployedContracts[className] = contractAddress; + this.deployedContracts[className] = chainContract.address; this.execute_cmds(contract.onDeploy); } else { From 11076ab00cd8c8fadcb7f868310bdeefdaf1b88d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Aug 2015 10:12:03 -0400 Subject: [PATCH 5/7] update to 0.8.3 --- bin/embark | 2 +- boilerplate/package.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/embark b/bin/embark index d72547e0e..bec002c4a 100644 --- a/bin/embark +++ b/bin/embark @@ -32,7 +32,7 @@ var deploy = function(env, embarkConfig) { } program - .version('0.8.2') + .version('0.8.3') program.command('new [name]').description('New application').action(function(name) { if (name === undefined) { diff --git a/boilerplate/package.json b/boilerplate/package.json index 7e77698fe..f49c97659 100644 --- a/boilerplate/package.json +++ b/boilerplate/package.json @@ -10,7 +10,7 @@ "license": "ISC", "homepage": "", "devDependencies": { - "embark-framework": "^0.8.2", + "embark-framework": "^0.8.3", "grunt-embark": "^0.3.0", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-coffee": "^0.13.0", diff --git a/package.json b/package.json index 015f83b8c..712f2bcdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "embark-framework", - "version": "0.8.2", + "version": "0.8.3", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" From 39840bbd7a28eae34c9db97de4cd288c0f38af9c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Aug 2015 22:19:21 -0400 Subject: [PATCH 6/7] take into account contract args and classname when recording contract --- lib/chain_manager.js | 8 ++++---- lib/deploy.js | 25 ++++++++++++------------- test/chain_manager.js | 13 +++++++------ test/deploy.js | 1 + test/support/chain_manager.json | 2 +- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/chain_manager.js b/lib/chain_manager.js index 9dc8e5c32..d63c8b850 100644 --- a/lib/chain_manager.js +++ b/lib/chain_manager.js @@ -36,15 +36,15 @@ ChainManager.prototype.init = function(env, config) { this.currentChain = this.chainManagerConfig[chainId]; } -ChainManager.prototype.addContract = function(contractName, code, address) { - this.currentChain.contracts[sha3_256(code)] = { +ChainManager.prototype.addContract = function(contractName, code, args, address) { + this.currentChain.contracts[sha3_256(code + contractName + args.join(','))] = { name: contractName, address: address } } -ChainManager.prototype.getContract = function(code) { - return this.currentChain.contracts[sha3_256(code)]; +ChainManager.prototype.getContract = function(contractName, code, args) { + return this.currentChain.contracts[sha3_256(code + contractName + args.join(','))]; } ChainManager.prototype.save = function() { diff --git a/lib/deploy.js b/lib/deploy.js index 2c6b85613..899a88229 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -58,6 +58,15 @@ Deploy.prototype.deploy_contracts = function(env) { className = all_contracts[k]; contract = this.contractDB[className]; + var realArgs = []; + for (var l = 0; l < contract.args.length; l++) { + arg = contract.args[l]; + if (arg[0] === "$") { + realArgs.push(this.deployedContracts[arg.substr(1)]); + } else { + realArgs.push(arg); + } + } if (contract.address !== undefined) { this.deployedContracts[className] = contract.address; @@ -66,7 +75,7 @@ Deploy.prototype.deploy_contracts = function(env) { console.log("contract " + className + " at " + contract.address); } else { - var chainContract = this.chainManager.getContract(contract.compiled.code); + var chainContract = this.chainManager.getContract(className, contract.compiled.code, realArgs); if (chainContract != undefined) { console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address); @@ -77,17 +86,7 @@ Deploy.prototype.deploy_contracts = function(env) { contractObject = web3.eth.contract(contract.compiled.info.abiDefinition); - realArgs = []; - for (var l = 0; l < contract.args.length; l++) { - arg = contract.args[l]; - if (arg[0] === "$") { - realArgs.push(this.deployedContracts[arg.substr(1)]); - } else { - realArgs.push(arg); - } - } - - contractParams = realArgs; + contractParams = realArgs.slice(); contractParams.push({ from: primaryAddress, data: contract.compiled.code, @@ -114,7 +113,7 @@ Deploy.prototype.deploy_contracts = function(env) { } this.deployedContracts[className] = contractAddress; - this.chainManager.addContract(className, contract.compiled.code, contractAddress); + this.chainManager.addContract(className, contract.compiled.code, realArgs, contractAddress); this.chainManager.save(); console.log("deployed " + className + " at " + contractAddress); diff --git a/test/chain_manager.js b/test/chain_manager.js index 26dcd13dd..e2add352a 100644 --- a/test/chain_manager.js +++ b/test/chain_manager.js @@ -15,7 +15,7 @@ describe('embark.chain_manager', function() { chainManager.init('development', blockchainConfig); it('should initialize chain', function() { - var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f'] + var chain = chainManager.chainManagerConfig['0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5'] assert.equal(chain != undefined, true); }); }); @@ -23,10 +23,11 @@ describe('embark.chain_manager', function() { describe('#addContract', function() { it('should register a contract in the chain', function() { - chainManager.addContract("Foo", "123456", "0x123"); + chainManager.addContract("Foo", "123456", [], "0x123"); - var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f'] - var contract = chain.contracts["d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e"] + console.log(chainManager.chainManagerConfig); + var chain = chainManager.chainManagerConfig['0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5'] + var contract = chain.contracts["d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b"] assert.equal(contract.name, "Foo"); assert.equal(contract.address, "0x123"); @@ -37,7 +38,7 @@ describe('embark.chain_manager', function() { describe('#getContract', function() { it('should a contract in the chain', function() { - var contract = chainManager.getContract("123456"); + var contract = chainManager.getContract("Foo", "123456", []); assert.equal(contract.name, "Foo"); assert.equal(contract.address, "0x123"); @@ -52,7 +53,7 @@ describe('embark.chain_manager', function() { var chainFile = './test/support/chain_manager.json'; var content = fs.readFileSync(chainFile).toString(); - assert.equal(content, '{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}}'); + assert.equal(content, '{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b\":{"name":"Foo","address":"0x123"}}}}'); }); }); diff --git a/test/deploy.js b/test/deploy.js index c5df8511e..7e7fd6b22 100644 --- a/test/deploy.js +++ b/test/deploy.js @@ -1,6 +1,7 @@ var Config = require('../lib/config/config.js'); var Deploy = require('../lib/deploy.js'); var Compiler = require('../lib/compiler.js'); +var ChainManager = require('../lib/chain_manager.js'); var assert = require('assert'); var web3 = require('web3'); diff --git a/test/support/chain_manager.json b/test/support/chain_manager.json index ccb1943fb..0b027530b 100644 --- a/test/support/chain_manager.json +++ b/test/support/chain_manager.json @@ -1 +1 @@ -{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}} \ No newline at end of file +{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b":{"name":"Foo","address":"0x123"}}}} \ No newline at end of file From 76203e43e3af49abc0f37c8cb83417416e636448 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 5 Aug 2015 22:32:14 -0400 Subject: [PATCH 7/7] update to 0.8.4 --- bin/embark | 2 +- boilerplate/package.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/embark b/bin/embark index bec002c4a..98fd67e3b 100644 --- a/bin/embark +++ b/bin/embark @@ -32,7 +32,7 @@ var deploy = function(env, embarkConfig) { } program - .version('0.8.3') + .version('0.8.4') program.command('new [name]').description('New application').action(function(name) { if (name === undefined) { diff --git a/boilerplate/package.json b/boilerplate/package.json index f49c97659..770769863 100644 --- a/boilerplate/package.json +++ b/boilerplate/package.json @@ -10,7 +10,7 @@ "license": "ISC", "homepage": "", "devDependencies": { - "embark-framework": "^0.8.3", + "embark-framework": "^0.8.4", "grunt-embark": "^0.3.0", "grunt-contrib-clean": "^0.6.0", "grunt-contrib-coffee": "^0.13.0", diff --git a/package.json b/package.json index 712f2bcdf..cf0d25141 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "embark-framework", - "version": "0.8.3", + "version": "0.8.4", "description": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1"