diff --git a/lib/index.js b/lib/index.js index 5e699a29b..2bf3fb065 100644 --- a/lib/index.js +++ b/lib/index.js @@ -68,8 +68,9 @@ Embark = { deployContract: function(contractFiles, className, args, cb) { 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() { var result = ""; result += deploy.generate_abi_file(); diff --git a/lib/single_deploy.js b/lib/single_deploy.js index dc84263c3..eab6e038a 100644 --- a/lib/single_deploy.js +++ b/lib/single_deploy.js @@ -8,11 +8,15 @@ var BigNumber = require('bignumber.js'); // 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) { web3 = _web3; } this.compiledContracts = compiledContracts; + this.gasLimit = gasLimit; + this.gasPrice = gasPrice; + this.deployedContracts = {}; + web3.eth.defaultAccount = web3.eth.coinbase; }; SingleDeploy.waitForContract = function(transactionHash, cb) { @@ -21,7 +25,7 @@ SingleDeploy.waitForContract = function(transactionHash, cb) { cb(receipt.contractAddress); } else { - Deploy.waitForContract(transactionHash, cb); + SingleDeploy.waitForContract(transactionHash, cb); } }); }; @@ -32,7 +36,7 @@ SingleDeploy.prototype.deploy_contract = function(contractObject, contractParams cb(contract.address); } 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); }; -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 contractObject = web3.eth.contract(contract.compiled.info.abiDefinition); + var contractObject = web3.eth.contract(contract.info.abiDefinition); contractParams = args.slice(); contractParams.push({ - from: primaryAddress, - data: contract.compiled.code, - gas: contract.gasLimit, - gasPrice: contract.gasPrice + from: web3.eth.coinbase, + data: contract.code, + gas: this.gasLimit, + gasPrice: this.gasPrice }); console.log('trying to obtain ' + className + ' address...'); @@ -62,6 +67,7 @@ Deploy.prototype.deploy_a_contract = function(className, args, cb) { console.log("========="); } + self.deployedContracts[className] = contractAddress; cb(); }); @@ -82,14 +88,13 @@ SingleDeploy.prototype.generate_provider_file = function() { SingleDeploy.prototype.generate_abi_file = function() { var result = ""; - result += 'blockchain = '+JSON.stringify(this.blockchainConfig)+';'; for(className in this.deployedContracts) { 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; console.log('address is ' + contractAddress);