load contracts config when deploying

This commit is contained in:
Iuri Matias 2015-06-19 10:27:53 -04:00
parent 79db42544a
commit 6a60d0110a
2 changed files with 20 additions and 15 deletions

View File

@ -0,0 +1,2 @@
development:
staging:

View File

@ -4,6 +4,7 @@ module.exports = (grunt) ->
grunt.registerTask "deploy_contracts", "deploy code", (env) => grunt.registerTask "deploy_contracts", "deploy code", (env) =>
blockchainConfig = readYaml.sync("config/blockchain.yml") blockchainConfig = readYaml.sync("config/blockchain.yml")
contractsConfig = readYaml.sync("config/contracts.yml")[env || "development"]
rpcHost = blockchainConfig[env || "development"].rpc_host rpcHost = blockchainConfig[env || "development"].rpc_host
rpcPort = blockchainConfig[env || "development"].rpc_port rpcPort = blockchainConfig[env || "development"].rpc_port
gasLimit = blockchainConfig[env || "development"].gas_limit || 100000 gasLimit = blockchainConfig[env || "development"].gas_limit || 100000
@ -29,25 +30,27 @@ module.exports = (grunt) ->
grunt.log.writeln("deploying #{contractFile}") grunt.log.writeln("deploying #{contractFile}")
compiled_contracts = web3.eth.compile.solidity(source) compiled_contracts = web3.eth.compile.solidity(source)
#TODO: refactor this into a common method for className, contract of compiled_contracts
if compiled_contracts.info is undefined contractGasLimit = contractsConfig[className].gasLimit || gasLimit
for className, contract of compiled_contracts contractGasPrice = contractsConfig[className].gasPrice || gasPrice
contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code, gas: gasLimit, gasPrice: gasPrice})
grunt.log.writeln("deployed #{className} at #{contractAddress}")
abi = JSON.stringify(contract.info.abiDefinition) args = contractsConfig[className].args
result += "var #{className}Abi = #{abi};" contractObject = web3.eth.contract(contract.info.abiDefinition)
result += "var #{className}Contract = web3.eth.contract(#{className}Abi);" #contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code, gas: contractGasLimit, gasPrice: contractGasPrice})
result += "var #{className} = #{className}Contract.at('#{contractAddress}');"; #contractAddress = contractObject.new(150, {from: primaryAddress, data: contract.code, gas: contractGasLimit, gasPrice: contractGasPrice}).address
else contractAddress = contractObject.new.apply(contractObject, [args, {from: primaryAddress, data: contract.code, gas: contractGasLimit, gasPrice: contractGasPrice}]).address
#for geth < 0.9.23
contract = compiled_contracts if (web3.eth.getCode(contractAddress) is "0x") {
contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code, gas: gasLimit}) console.log "contract #{className} was not deployed, try adjusting the gas costs"
grunt.log.writeln("deployed at #{contractAddress}") exit
}
console.log "address is #{contractAddress}"
grunt.log.writeln("deployed #{className} at #{contractAddress}")
abi = JSON.stringify(contract.info.abiDefinition) abi = JSON.stringify(contract.info.abiDefinition)
className = source.match(/contract (\w+)(?=\s[is|{])/g)[0].replace("contract ","")
result += "var #{className}Abi = #{abi};" result += "var #{className}Abi = #{abi};"
result += "var #{className}Contract = web3.eth.contract(#{className}Abi);" result += "var #{className}Contract = web3.eth.contract(#{className}Abi);"