Skip to content

Commit e5a18eb

Browse files
committed
Merge branch 'develop'
2 parents 2f19b4c + 76203e4 commit e5a18eb

File tree

8 files changed

+33
-30
lines changed

8 files changed

+33
-30
lines changed

bin/embark

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var deploy = function(env, embarkConfig) {
3232
}
3333

3434
program
35-
.version('0.8.1')
35+
.version('0.8.4')
3636

3737
program.command('new [name]').description('New application').action(function(name) {
3838
if (name === undefined) {

boilerplate/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"homepage": "",
1212
"devDependencies": {
13-
"embark-framework": "^0.8.1",
13+
"embark-framework": "^0.8.4",
1414
"grunt-embark": "^0.3.0",
1515
"grunt-contrib-clean": "^0.6.0",
1616
"grunt-contrib-coffee": "^0.13.0",

lib/chain_manager.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ var web3 = require('web3');
33
var sha3_256 = require('js-sha3').sha3_256;
44

55
ChainManager = function() {
6+
this.chainManagerConfig = {};
67
this.currentChain = {};
78
this.file = "";
89
}
910

1011
ChainManager.prototype.loadConfigFile = function(filename) {
12+
this.file = filename;
1113
try {
1214
var obj = JSON.parse(fs.readFileSync(filename));
13-
this.file = filename;
1415
this.chainManagerConfig = obj;
1516
} catch (e) {
16-
throw new Error("error reading " + filename);
17+
console.warn("error reading " + filename + "; defaulting to empty set");
1718
}
1819
return this;
1920
};
@@ -35,20 +36,19 @@ ChainManager.prototype.init = function(env, config) {
3536
this.currentChain = this.chainManagerConfig[chainId];
3637
}
3738

38-
ChainManager.prototype.addContract = function(contractName, code, address) {
39-
this.currentChain.contracts[sha3_256(code)] = {
39+
ChainManager.prototype.addContract = function(contractName, code, args, address) {
40+
this.currentChain.contracts[sha3_256(code + contractName + args.join(','))] = {
4041
name: contractName,
4142
address: address
4243
}
4344
}
4445

45-
ChainManager.prototype.getContract = function(code) {
46-
return this.currentChain.contracts[sha3_256(code)];
46+
ChainManager.prototype.getContract = function(contractName, code, args) {
47+
return this.currentChain.contracts[sha3_256(code + contractName + args.join(','))];
4748
}
4849

4950
ChainManager.prototype.save = function() {
5051
fs.writeFileSync(this.file, JSON.stringify(this.chainManagerConfig));
5152
}
5253

5354
module.exports = ChainManager;
54-

lib/deploy.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ Deploy.prototype.deploy_contracts = function(env) {
5858
className = all_contracts[k];
5959
contract = this.contractDB[className];
6060

61+
var realArgs = [];
62+
for (var l = 0; l < contract.args.length; l++) {
63+
arg = contract.args[l];
64+
if (arg[0] === "$") {
65+
realArgs.push(this.deployedContracts[arg.substr(1)]);
66+
} else {
67+
realArgs.push(arg);
68+
}
69+
}
6170

6271
if (contract.address !== undefined) {
6372
this.deployedContracts[className] = contract.address;
@@ -66,26 +75,18 @@ Deploy.prototype.deploy_contracts = function(env) {
6675
console.log("contract " + className + " at " + contract.address);
6776
}
6877
else {
69-
var chainContract = this.chainManager.getContract(contract.compiled.code);
78+
var chainContract = this.chainManager.getContract(className, contract.compiled.code, realArgs);
7079

7180
if (chainContract != undefined) {
7281
console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address);
82+
this.deployedContracts[className] = chainContract.address;
83+
this.execute_cmds(contract.onDeploy);
7384
}
7485
else {
7586

7687
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
7788

78-
realArgs = [];
79-
for (var l = 0; l < contract.args.length; l++) {
80-
arg = contract.args[l];
81-
if (arg[0] === "$") {
82-
realArgs.push(this.deployedContracts[arg.substr(1)]);
83-
} else {
84-
realArgs.push(arg);
85-
}
86-
}
87-
88-
contractParams = realArgs;
89+
contractParams = realArgs.slice();
8990
contractParams.push({
9091
from: primaryAddress,
9192
data: contract.compiled.code,
@@ -112,7 +113,7 @@ Deploy.prototype.deploy_contracts = function(env) {
112113
}
113114

114115
this.deployedContracts[className] = contractAddress;
115-
this.chainManager.addContract(className, contract.compiled.code, contractAddress);
116+
this.chainManager.addContract(className, contract.compiled.code, realArgs, contractAddress);
116117
this.chainManager.save();
117118

118119
console.log("deployed " + className + " at " + contractAddress);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "embark-framework",
3-
"version": "0.8.1",
3+
"version": "0.8.4",
44
"description": "",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1"

test/chain_manager.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ describe('embark.chain_manager', function() {
1515
chainManager.init('development', blockchainConfig);
1616

1717
it('should initialize chain', function() {
18-
var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f']
18+
var chain = chainManager.chainManagerConfig['0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5']
1919
assert.equal(chain != undefined, true);
2020
});
2121
});
2222

2323
describe('#addContract', function() {
2424

2525
it('should register a contract in the chain', function() {
26-
chainManager.addContract("Foo", "123456", "0x123");
26+
chainManager.addContract("Foo", "123456", [], "0x123");
2727

28-
var chain = chainManager.chainManagerConfig['0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f']
29-
var contract = chain.contracts["d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e"]
28+
console.log(chainManager.chainManagerConfig);
29+
var chain = chainManager.chainManagerConfig['0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5']
30+
var contract = chain.contracts["d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b"]
3031

3132
assert.equal(contract.name, "Foo");
3233
assert.equal(contract.address, "0x123");
@@ -37,7 +38,7 @@ describe('embark.chain_manager', function() {
3738
describe('#getContract', function() {
3839

3940
it('should a contract in the chain', function() {
40-
var contract = chainManager.getContract("123456");
41+
var contract = chainManager.getContract("Foo", "123456", []);
4142

4243
assert.equal(contract.name, "Foo");
4344
assert.equal(contract.address, "0x123");
@@ -52,7 +53,7 @@ describe('embark.chain_manager', function() {
5253

5354
var chainFile = './test/support/chain_manager.json';
5455
var content = fs.readFileSync(chainFile).toString();
55-
assert.equal(content, '{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}}');
56+
assert.equal(content, '{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b\":{"name":"Foo","address":"0x123"}}}}');
5657
});
5758

5859
});

test/deploy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Config = require('../lib/config/config.js');
22
var Deploy = require('../lib/deploy.js');
33
var Compiler = require('../lib/compiler.js');
4+
var ChainManager = require('../lib/chain_manager.js');
45
var assert = require('assert');
56
var web3 = require('web3');
67

test/support/chain_manager.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}}
1+
{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b":{"name":"Foo","address":"0x123"}}}}

0 commit comments

Comments
 (0)