Merge pull request #144 from SafeMarket/deploy_synchronously

Deploy synchronously
This commit is contained in:
Iuri Matias 2016-02-28 12:57:05 -05:00
commit 30fd0a9489
4 changed files with 34 additions and 3 deletions

View File

@ -36,6 +36,7 @@ Compiler.prototype.compile_solidity = function(contractFiles) {
compiled_object[className] = {}; compiled_object[className] = {};
compiled_object[className].code = contract.bytecode; compiled_object[className].code = contract.bytecode;
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
compiled_object[className].info = {}; compiled_object[className].info = {};
compiled_object[className].info.abiDefinition = JSON.parse(contract.interface); compiled_object[className].info.abiDefinition = JSON.parse(contract.interface);
} }

View File

@ -33,6 +33,7 @@ BlockchainConfig.prototype.config = function(env) {
config = { config = {
env:env,
rpcHost: config.rpc_host, rpcHost: config.rpc_host,
rpcPort: config.rpc_port, rpcPort: config.rpc_port,
gasLimit: config.gas_limit || 500000, gasLimit: config.gas_limit || 500000,
@ -54,7 +55,9 @@ BlockchainConfig.prototype.config = function(env) {
whisper: config.whisper || false, whisper: config.whisper || false,
account: config.account, account: config.account,
geth_extra_opts: config.geth_extra_opts || [], geth_extra_opts: config.geth_extra_opts || [],
testnet: config.testnet || false testnet: config.testnet || false,
geth_extra_opts: config.geth_extra_opts,
deploy_synchronously: config.deploy_synchronously || false
} }
return config; return config;

View File

@ -3,6 +3,7 @@ var fs = require('fs');
var grunt = require('grunt'); var grunt = require('grunt');
var readYaml = require('read-yaml'); var readYaml = require('read-yaml');
var Config = require('./config/config.js'); var Config = require('./config/config.js');
var BigNumber = require('bignumber.js');
Deploy = function(env, contractFiles, blockchainConfig, contractsConfig, chainManager, withProvider, withChain, _web3) { Deploy = function(env, contractFiles, blockchainConfig, contractsConfig, chainManager, withProvider, withChain, _web3) {
if (_web3 !== undefined) { if (_web3 !== undefined) {
@ -53,7 +54,10 @@ Deploy.prototype.deploy_contracts = function(env, cb) {
this.contractDB = this.contractsManager.contractDB; this.contractDB = this.contractsManager.contractDB;
this.deployedContracts = {}; this.deployedContracts = {};
this.deploy_contract_list(all_contracts.length, env, all_contracts, cb); if(this.blockchainConfig.deploy_synchronously)
this.deploy_contract_list_synchronously(env, all_contracts, cb);
else
this.deploy_contract_list(all_contracts.length, env, all_contracts, cb);
} }
Deploy.prototype.deploy_contract_list = function(index, env, all_contracts, cb) { Deploy.prototype.deploy_contract_list = function(index, env, all_contracts, cb) {
@ -69,6 +73,25 @@ Deploy.prototype.deploy_contract_list = function(index, env, all_contracts, cb)
} }
} }
Deploy.prototype.deploy_contract_list_synchronously = function(env, all_contracts, cb) {
var _this = this
,deployed_contracts_count = 0
all_contracts.forEach(function(className){
_this.deploy_a_contract(env, className, function(){
mark_contract_as_deployed()
});
})
function mark_contract_as_deployed(){
deployed_contracts_count ++;
if(deployed_contracts_count === all_contracts.length)
cb()
}
}
Deploy.prototype.deploy_a_contract = function(env, className, cb) { Deploy.prototype.deploy_a_contract = function(env, className, cb) {
var contractDependencies = this.contractsManager.contractDependencies; var contractDependencies = this.contractsManager.contractDependencies;
var contract = this.contractDB[className]; var contract = this.contractDB[className];
@ -175,6 +198,8 @@ Deploy.prototype.generate_provider_file = function() {
Deploy.prototype.generate_abi_file = function() { Deploy.prototype.generate_abi_file = function() {
var result = ""; var result = "";
result += 'blockchain = '+JSON.stringify(this.blockchainConfig)+';';
for(className in this.deployedContracts) { for(className in this.deployedContracts) {
var deployedContract = this.deployedContracts[className]; var deployedContract = this.deployedContracts[className];
var contract = this.contractDB[className]; var contract = this.contractDB[className];
@ -188,6 +213,7 @@ Deploy.prototype.generate_abi_file = function() {
result += className + "Contract = web3.eth.contract(" + className + "Abi);"; result += className + "Contract = web3.eth.contract(" + className + "Abi);";
result += className + " = " + className + "Contract.at('" + contractAddress + "');"; result += className + " = " + className + "Contract.at('" + contractAddress + "');";
} }
result += 'contractDB = '+JSON.stringify(this.contractDB)+';'
return result; return result;
}; };

View File

@ -22,7 +22,8 @@
"shelljs": "^0.5.0", "shelljs": "^0.5.0",
"solc": "^0.1.6", "solc": "^0.1.6",
"toposort": "^0.2.10", "toposort": "^0.2.10",
"web3": "^0.15.0", "web3": "^0.8.1",
"bignumber.js": "debris/bignumber.js#master",
"wrench": "^1.5.8", "wrench": "^1.5.8",
"ethersim": "^0.1.1" "ethersim": "^0.1.1"
}, },