mirror of https://github.com/embarklabs/embark.git
load contracts config when deploying
This commit is contained in:
parent
79db42544a
commit
6a60d0110a
|
@ -0,0 +1,2 @@
|
||||||
|
development:
|
||||||
|
staging:
|
|
@ -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,26 +30,28 @@ 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
|
|
||||||
if compiled_contracts.info is undefined
|
|
||||||
for className, contract of compiled_contracts
|
for className, contract of compiled_contracts
|
||||||
contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code, gas: gasLimit, gasPrice: gasPrice})
|
contractGasLimit = contractsConfig[className].gasLimit || gasLimit
|
||||||
|
contractGasPrice = contractsConfig[className].gasPrice || gasPrice
|
||||||
|
|
||||||
|
args = contractsConfig[className].args
|
||||||
|
|
||||||
|
contractObject = web3.eth.contract(contract.info.abiDefinition)
|
||||||
|
#contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code, gas: contractGasLimit, gasPrice: contractGasPrice})
|
||||||
|
#contractAddress = contractObject.new(150, {from: primaryAddress, data: contract.code, gas: contractGasLimit, gasPrice: contractGasPrice}).address
|
||||||
|
contractAddress = contractObject.new.apply(contractObject, [args, {from: primaryAddress, data: contract.code, gas: contractGasLimit, gasPrice: contractGasPrice}]).address
|
||||||
|
|
||||||
|
if (web3.eth.getCode(contractAddress) is "0x") {
|
||||||
|
console.log "contract #{className} was not deployed, try adjusting the gas costs"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log "address is #{contractAddress}"
|
||||||
|
|
||||||
grunt.log.writeln("deployed #{className} at #{contractAddress}")
|
grunt.log.writeln("deployed #{className} at #{contractAddress}")
|
||||||
|
|
||||||
abi = JSON.stringify(contract.info.abiDefinition)
|
abi = JSON.stringify(contract.info.abiDefinition)
|
||||||
|
|
||||||
result += "var #{className}Abi = #{abi};"
|
|
||||||
result += "var #{className}Contract = web3.eth.contract(#{className}Abi);"
|
|
||||||
result += "var #{className} = #{className}Contract.at('#{contractAddress}');";
|
|
||||||
else
|
|
||||||
#for geth < 0.9.23
|
|
||||||
contract = compiled_contracts
|
|
||||||
contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code, gas: gasLimit})
|
|
||||||
grunt.log.writeln("deployed at #{contractAddress}")
|
|
||||||
|
|
||||||
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);"
|
||||||
result += "var #{className} = #{className}Contract.at('#{contractAddress}');";
|
result += "var #{className} = #{className}Contract.at('#{contractAddress}');";
|
||||||
|
|
Loading…
Reference in New Issue