Merge branch 'develop'

This commit is contained in:
Iuri Matias 2015-08-05 22:34:51 -04:00
commit e5a18ebd0b
8 changed files with 33 additions and 30 deletions

View File

@ -32,7 +32,7 @@ var deploy = function(env, embarkConfig) {
}
program
.version('0.8.1')
.version('0.8.4')
program.command('new [name]').description('New application').action(function(name) {
if (name === undefined) {

View File

@ -10,7 +10,7 @@
"license": "ISC",
"homepage": "",
"devDependencies": {
"embark-framework": "^0.8.1",
"embark-framework": "^0.8.4",
"grunt-embark": "^0.3.0",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-coffee": "^0.13.0",

View File

@ -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;
};
@ -35,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() {
@ -51,4 +52,3 @@ ChainManager.prototype.save = function() {
}
module.exports = ChainManager;

View File

@ -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,26 +75,18 @@ 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);
this.deployedContracts[className] = chainContract.address;
this.execute_cmds(contract.onDeploy);
}
else {
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,
@ -112,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);

View File

@ -1,6 +1,6 @@
{
"name": "embark-framework",
"version": "0.8.1",
"version": "0.8.4",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"

View File

@ -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"}}}}');
});
});

View File

@ -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');

View File

@ -1 +1 @@
{"0x629e768beb87dc8c54a475d310a7196e86c97d0006e5a6d34a8217726c90223f":{"contracts":{"d7190eb194ff9494625514b6d178c87f99c5973e28c398969d2233f2960a573e":{"name":"Foo","address":"0x123"}}}}
{"0xcd9c11da1e46f86ce40a38b6ef84cfdfa6ea92598a27538f0e87da6d7a5c73d5":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b":{"name":"Foo","address":"0x123"}}}}