support for geth versions that return multiple contracts in compiled object; maintain compatibility with older geth versions

This commit is contained in:
Iuri Matias 2015-05-26 22:11:35 -04:00
parent bea68f8263
commit 1cffb46808

View File

@ -25,7 +25,22 @@ module.exports = (grunt) ->
source = grunt.file.read(contractFile)
grunt.log.writeln("deploying #{contractFile}")
contract = 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
contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code})
grunt.log.writeln("deployed #{className} at #{contractAddress}")
abi = JSON.stringify(contract.info.abiDefinition)
result += "var #{className}Abi = #{abi};"
result += "var #{className}Contract = web3.eth.contract(#{className}Abi);"
result += "var #{className} = new #{className}Contract('#{contractAddress}');";
else
#for geth < 0.9.23
contract = compiled_contracts
contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code})
grunt.log.writeln("deployed at #{contractAddress}")