From 1cffb468088853600884fff51a19c7b6edab2b6c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 26 May 2015 22:11:35 -0400 Subject: [PATCH] support for geth versions that return multiple contracts in compiled object; maintain compatibility with older geth versions --- tasks/deploy.coffee | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tasks/deploy.coffee b/tasks/deploy.coffee index 72b6a2aea..59b6359cf 100644 --- a/tasks/deploy.coffee +++ b/tasks/deploy.coffee @@ -25,16 +25,31 @@ module.exports = (grunt) -> source = grunt.file.read(contractFile) grunt.log.writeln("deploying #{contractFile}") - contract = web3.eth.compile.solidity(source) - contractAddress = web3.eth.sendTransaction({from: primaryAddress, data: contract.code}) - grunt.log.writeln("deployed at #{contractAddress}") + compiled_contracts = web3.eth.compile.solidity(source) - abi = JSON.stringify(contract.info.abiDefinition) - className = source.match(/contract (\w+)(?=\s[is|{])/g)[0].replace("contract ","") + #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}") - result += "var #{className}Abi = #{abi};" - result += "var #{className}Contract = web3.eth.contract(#{className}Abi);" - result += "var #{className} = new #{className}Contract('#{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}") + + 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}Contract = web3.eth.contract(#{className}Abi);" + result += "var #{className} = new #{className}Contract('#{contractAddress}');"; destFile = grunt.config.get("deploy.dest") grunt.file.write(destFile, result)