manage chain when deploying contracts
This commit is contained in:
parent
f8db3c2920
commit
8544756684
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -58,6 +58,7 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
className = all_contracts[k];
|
||||
contract = this.contractDB[className];
|
||||
|
||||
|
||||
if (contract.address !== undefined) {
|
||||
this.deployedContracts[className] = contract.address;
|
||||
|
||||
|
@ -65,48 +66,58 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||
console.log("contract " + className + " at " + contract.address);
|
||||
}
|
||||
else {
|
||||
contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
||||
var chainContract = this.chainManager.getContract(contract.compiled.code);
|
||||
|
||||
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.push({
|
||||
from: primaryAddress,
|
||||
data: contract.compiled.code,
|
||||
gas: contract.gasLimit,
|
||||
gasPrice: contract.gasPrice
|
||||
});
|
||||
|
||||
console.log('trying to obtain ' + className + ' address...');
|
||||
|
||||
while((receipt = this.deploy_contract(contractObject, contractParams)) === false) {
|
||||
console.log("timeout... failed to deploy contract.. retrying...");
|
||||
}
|
||||
|
||||
var contractAddress = receipt.contractAddress;
|
||||
|
||||
if (web3.eth.getCode(contractAddress) === "0x") {
|
||||
console.log("=========");
|
||||
console.log("contract was deployed at " + contractAddress + " but doesn't seem to be working");
|
||||
console.log("try adjusting your gas values");
|
||||
console.log("=========");
|
||||
if (chainContract != undefined) {
|
||||
console.log("contract " + className + " is unchanged and already deployed at " + chainContract.address);
|
||||
}
|
||||
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.push({
|
||||
from: primaryAddress,
|
||||
data: contract.compiled.code,
|
||||
gas: contract.gasLimit,
|
||||
gasPrice: contract.gasPrice
|
||||
});
|
||||
|
||||
console.log('trying to obtain ' + className + ' address...');
|
||||
|
||||
while((receipt = this.deploy_contract(contractObject, contractParams)) === false) {
|
||||
console.log("timeout... failed to deploy contract.. retrying...");
|
||||
}
|
||||
|
||||
var contractAddress = receipt.contractAddress;
|
||||
|
||||
if (web3.eth.getCode(contractAddress) === "0x") {
|
||||
console.log("=========");
|
||||
console.log("contract was deployed at " + contractAddress + " but doesn't seem to be working");
|
||||
console.log("try adjusting your gas values");
|
||||
console.log("=========");
|
||||
}
|
||||
else {
|
||||
console.log("deployed " + className + " at " + contractAddress);
|
||||
}
|
||||
|
||||
this.deployedContracts[className] = contractAddress;
|
||||
this.chainManager.addContract(className, contract.compiled.code, contractAddress);
|
||||
this.chainManager.save();
|
||||
|
||||
console.log("deployed " + className + " at " + contractAddress);
|
||||
this.execute_cmds(contract.onDeploy);
|
||||
}
|
||||
|
||||
this.deployedContracts[className] = contractAddress;
|
||||
|
||||
console.log("deployed " + className + " at " + contractAddress);
|
||||
this.execute_cmds(contract.onDeploy);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ var Deploy = require('./deploy.js');
|
|||
var Release = require('./ipfs.js');
|
||||
var Config = require('./config/config.js');
|
||||
var Compiler = require('./compiler.js');
|
||||
var ChainManager = require('./chain_manager.js');
|
||||
|
||||
Embark = {
|
||||
init: function() {
|
||||
|
|
Loading…
Reference in New Issue