mirror of https://github.com/embarklabs/embark.git
add single deploy support
This commit is contained in:
parent
60d860f27a
commit
0faa649c2f
|
@ -68,8 +68,9 @@ Embark = {
|
||||||
|
|
||||||
deployContract: function(contractFiles, className, args, cb) {
|
deployContract: function(contractFiles, className, args, cb) {
|
||||||
var compiledContracts = this.compiler.compile_solidity(contractFiles);
|
var compiledContracts = this.compiler.compile_solidity(contractFiles);
|
||||||
|
var config = this.blockchainConfig.config('development');
|
||||||
|
|
||||||
var deploy = new SingleDeploy(compiledContracts, this.web3);
|
var deploy = new SingleDeploy(compiledContracts, config.gasLimit, config.gasPrice, this.web3);
|
||||||
deploy.deploy_a_contract(className, args, function() {
|
deploy.deploy_a_contract(className, args, function() {
|
||||||
var result = "";
|
var result = "";
|
||||||
result += deploy.generate_abi_file();
|
result += deploy.generate_abi_file();
|
||||||
|
|
|
@ -8,11 +8,15 @@ var BigNumber = require('bignumber.js');
|
||||||
|
|
||||||
// this is a temporary module to deploy a single contract, will be refactored
|
// this is a temporary module to deploy a single contract, will be refactored
|
||||||
|
|
||||||
SingleDeploy = function(compiledContracts, _web3) {
|
SingleDeploy = function(compiledContracts, gasLimit, gasPrice, _web3) {
|
||||||
if (_web3 !== undefined) {
|
if (_web3 !== undefined) {
|
||||||
web3 = _web3;
|
web3 = _web3;
|
||||||
}
|
}
|
||||||
this.compiledContracts = compiledContracts;
|
this.compiledContracts = compiledContracts;
|
||||||
|
this.gasLimit = gasLimit;
|
||||||
|
this.gasPrice = gasPrice;
|
||||||
|
this.deployedContracts = {};
|
||||||
|
web3.eth.defaultAccount = web3.eth.coinbase;
|
||||||
};
|
};
|
||||||
|
|
||||||
SingleDeploy.waitForContract = function(transactionHash, cb) {
|
SingleDeploy.waitForContract = function(transactionHash, cb) {
|
||||||
|
@ -21,7 +25,7 @@ SingleDeploy.waitForContract = function(transactionHash, cb) {
|
||||||
cb(receipt.contractAddress);
|
cb(receipt.contractAddress);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Deploy.waitForContract(transactionHash, cb);
|
SingleDeploy.waitForContract(transactionHash, cb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -32,7 +36,7 @@ SingleDeploy.prototype.deploy_contract = function(contractObject, contractParams
|
||||||
cb(contract.address);
|
cb(contract.address);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Deploy.waitForContract(contract.transactionHash, cb);
|
SingleDeploy.waitForContract(contract.transactionHash, cb);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,16 +44,17 @@ SingleDeploy.prototype.deploy_contract = function(contractObject, contractParams
|
||||||
contractObject["new"].apply(contractObject, contractParams);
|
contractObject["new"].apply(contractObject, contractParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
Deploy.prototype.deploy_a_contract = function(className, args, cb) {
|
SingleDeploy.prototype.deploy_a_contract = function(className, args, cb) {
|
||||||
|
var self = this;
|
||||||
var contract = this.compiledContracts[className];
|
var contract = this.compiledContracts[className];
|
||||||
var contractObject = web3.eth.contract(contract.compiled.info.abiDefinition);
|
var contractObject = web3.eth.contract(contract.info.abiDefinition);
|
||||||
|
|
||||||
contractParams = args.slice();
|
contractParams = args.slice();
|
||||||
contractParams.push({
|
contractParams.push({
|
||||||
from: primaryAddress,
|
from: web3.eth.coinbase,
|
||||||
data: contract.compiled.code,
|
data: contract.code,
|
||||||
gas: contract.gasLimit,
|
gas: this.gasLimit,
|
||||||
gasPrice: contract.gasPrice
|
gasPrice: this.gasPrice
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('trying to obtain ' + className + ' address...');
|
console.log('trying to obtain ' + className + ' address...');
|
||||||
|
@ -62,6 +67,7 @@ Deploy.prototype.deploy_a_contract = function(className, args, cb) {
|
||||||
console.log("=========");
|
console.log("=========");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.deployedContracts[className] = contractAddress;
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -82,14 +88,13 @@ SingleDeploy.prototype.generate_provider_file = function() {
|
||||||
|
|
||||||
SingleDeploy.prototype.generate_abi_file = function() {
|
SingleDeploy.prototype.generate_abi_file = function() {
|
||||||
var result = "";
|
var result = "";
|
||||||
|
|
||||||
result += 'blockchain = '+JSON.stringify(this.blockchainConfig)+';';
|
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.compiledContracts[className];
|
||||||
|
|
||||||
var abi = JSON.stringify(contract.compiled.info.abiDefinition);
|
var abi = JSON.stringify(contract.info.abiDefinition);
|
||||||
var contractAddress = deployedContract;
|
var contractAddress = deployedContract;
|
||||||
|
|
||||||
console.log('address is ' + contractAddress);
|
console.log('address is ' + contractAddress);
|
||||||
|
|
Loading…
Reference in New Issue