Skip to content

Commit 72dec76

Browse files
committed
Merge branch 'develop'
2 parents ddc134a + 834b259 commit 72dec76

File tree

18 files changed

+210
-37
lines changed

18 files changed

+210
-37
lines changed

bin/embark

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

2727
program
28-
.version('0.7.2')
28+
.version('0.7.3')
2929

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

boilerplate/Gruntfile.coffee

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = (grunt) ->
6464
tasks: ["concat"]
6565

6666
css:
67-
files: ["<%= concat.css.src %>"]
67+
files: ["<%= files.css.src %>"]
6868
tasks: ["concat"]
6969

7070
coffee:
@@ -75,6 +75,10 @@ module.exports = (grunt) ->
7575
files: ["<%= files.contracts.src %>"]
7676
tasks: ["deploy", "concat", "copy"]
7777

78+
config:
79+
files: ["config/blockchain.yml", "config/contracts.yml"]
80+
tasks: ["deploy", "concat", "copy"]
81+
7882
copy:
7983
html:
8084
files:

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.7.2",
13+
"embark-framework": "^0.7.3",
1414
"grunt-embark": "^0.2.0",
1515
"grunt-contrib-clean": "^0.6.0",
1616
"grunt-contrib-coffee": "^0.13.0",

demo/spec/contracts/simple_storage_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Embark.contractsConfig.loadConfigFile('config/contracts.yml');
55

66
var files = ["app/contracts/simple_storage.sol"];
77

8-
Embark.contractsConfig.init(files);
8+
Embark.contractsConfig.init(files, 'development');
99
var EmbarkSpec = Embark.tests(files);
1010

1111
describe("SimpleStorage", function() {

js/mine.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
var miner_var;
12

2-
setInterval(function() {
3-
var miner_var;
3+
if (admin.miner === undefined) {
4+
miner_var = miner;
5+
}
6+
else {
7+
miner_var = admin.miner;
8+
}
49

5-
if (admin.miner === undefined) {
6-
miner_var = miner;
7-
}
8-
else {
9-
miner_var = admin.miner;
10-
}
10+
miner_var.setEtherbase(web3.eth.accounts[0]);
1111

12+
setInterval(function() {
1213
var minimalAmount = (web3.eth.getBalance(web3.eth.coinbase) >= 15000000000000000000);
1314
var pendingTransactions = function() {
1415
if (web3.eth.pendingTransactions === undefined || web3.eth.pendingTransactions === null) {

lib/blockchain.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Blockchain.prototype.generate_basic_command = function() {
1818
cmd += "--port " + config.port + " ";
1919
cmd += "--rpc ";
2020
cmd += "--rpcport " + config.rpcPort + " ";
21+
cmd += "--rpcaddr " + config.rpcHost + " ";
2122
cmd += "--networkid " + config.networkId + " ";
2223
cmd += "--rpccorsdomain \"" + config.rpcWhitelist + "\" ";
2324

lib/config/contracts.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ ContractsConfig = function(blockchainConfig, compiler) {
88
this.contractFiles = [];
99
}
1010

11-
ContractsConfig.prototype.init = function(files) {
11+
ContractsConfig.prototype.init = function(files, env) {
1212
this.all_contracts = [];
1313
this.contractDB = {};
1414
this.contractFiles = files;
1515
this.contractDependencies = {};
16+
this.contractStubs = {};
1617

1718
//TODO: have to specify environment otherwise wouldn't work with staging
1819
if (this.blockchainConfig.config != undefined) {
19-
this.blockchainConfig = this.blockchainConfig.config('development');
20+
//this.blockchainConfig = this.blockchainConfig.config('development');
21+
this.blockchainConfig = this.blockchainConfig.config(env);
2022
}
2123
};
2224

@@ -38,6 +40,15 @@ ContractsConfig.prototype.config = function(env) {
3840
return this.contractConfig[env];
3941
};
4042

43+
ContractsConfig.prototype.is_a_token = function(target, compiled_contracts) {
44+
for (var className in compiled_contracts) {
45+
if (this.contractStubs[className] && this.contractStubs[className].indexOf(target) >= 0) {
46+
return true;
47+
}
48+
}
49+
return false;
50+
};
51+
4152
ContractsConfig.prototype.compileContracts = function(env) {
4253
var contractFile, source, j;
4354
var contractsConfig = this.config(env);
@@ -59,6 +70,8 @@ ContractsConfig.prototype.compileContracts = function(env) {
5970
this.contractDependencies[className].push(arg.substr(1));
6071
}
6172
}
73+
74+
this.contractStubs[className] = options.stubs;
6275
}
6376
}
6477

@@ -68,10 +81,14 @@ ContractsConfig.prototype.compileContracts = function(env) {
6881
contractFile = this.contractFiles[j];
6982
source = fs.readFileSync(contractFile).toString()
7083

71-
console.log("compiling " + contractFile);
7284
compiled_contracts = this.compiler.compile(source);
73-
for (className in compiled_contracts) {
85+
for (var className in compiled_contracts) {
7486
var contract = compiled_contracts[className];
87+
88+
if (this.is_a_token(className, compiled_contracts)) {
89+
continue;
90+
}
91+
7592
all_compiled_contracts[className] = contract;
7693
this.all_contracts.push(className);
7794
this.contractDB[className] = {

lib/deploy.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ var fs = require('fs');
33
var grunt = require('grunt');
44
var readYaml = require('read-yaml');
55
var Config = require('./config/config.js');
6-
var sleep = require('sleep');
6+
7+
// Ugly, but sleep lib has issues on osx
8+
sleep = function sleep(ms) {
9+
var start = new Date().getTime();
10+
while (new Date().getTime() < start + ms);
11+
}
712

813
Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
914
//this.blockchainConfig = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
@@ -22,9 +27,23 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
2227
throw new Error("==== can't connect to " + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + " check if an ethereum node is running");
2328
}
2429

25-
console.log("address is : " + primaryAddress);
30+
console.log("primary account address is : " + primaryAddress);
2631
};
2732

33+
Deploy.prototype.deploy_contract = function(contractObject, contractParams) {
34+
var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash;
35+
var receipt = null;
36+
var time = 0;
37+
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null || receipt.contractAddress === null) {
38+
sleep(1000);
39+
time += 1;
40+
if (time >= 20) {
41+
return false;
42+
}
43+
}
44+
return receipt;
45+
}
46+
2847
Deploy.prototype.deploy_contracts = function(env) {
2948
this.contractsManager.compileContracts(env);
3049
all_contracts = this.contractsManager.all_contracts;
@@ -64,19 +83,25 @@ Deploy.prototype.deploy_contracts = function(env) {
6483
gasPrice: contract.gasPrice
6584
});
6685

67-
var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash;
68-
// TODO: get this with sync until a different mechanism is implemented
69-
//this.deployedContracts[className] = contractAddress;
70-
//console.log("address is " + contractAddress);
71-
7286
console.log('trying to obtain ' + className + ' address...');
73-
var receipt = null;
74-
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null || receipt.contractAddress === null) {
75-
sleep.sleep(1);
87+
88+
while((receipt = this.deploy_contract(contractObject, contractParams)) === false) {
89+
console.log("timeout... failed to deploy contract.. retrying...");
7690
}
91+
7792
var contractAddress = receipt.contractAddress;
93+
94+
if (web3.eth.getCode(contractAddress) === "0x") {
95+
console.log("=========");
96+
console.log("contract was deployed at " + contractAddress + " but doesn't seem to be working");
97+
console.log("try adjusting your gas values");
98+
console.log("=========");
99+
}
100+
else {
101+
console.log("deployed " + className + " at " + contractAddress);
102+
}
103+
78104
this.deployedContracts[className] = contractAddress;
79-
console.log('address is ' + contractAddress);
80105

81106
console.log("deployed " + className + " at " + contractAddress);
82107
}

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Embark = {
3434
},
3535

3636
deployContracts: function(env, contractFiles, destFile) {
37-
this.contractsConfig.init(contractFiles);
37+
this.contractsConfig.init(contractFiles, env);
3838
var deploy = new Deploy(env, contractFiles, this.blockchainConfig.config(env), this.contractsConfig);
3939
deploy.deploy_contracts(env);
4040
return deploy.generate_abi_file(destFile);

lib/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TestContract = function(contract, className, args) {
5757
}
5858

5959
test = function(contractsConfig, contractFiles) {
60-
contractsConfig.init(contractFiles);
60+
contractsConfig.init(contractFiles, 'development');
6161

6262
contractsConfig.compileContracts();
6363
this.contractDB = contractsConfig.contractDB;

0 commit comments

Comments
 (0)