diff --git a/moonworm/cli.py.template b/moonworm/cli.py.template index 1912bc8..c13a50a 100644 --- a/moonworm/cli.py.template +++ b/moonworm/cli.py.template @@ -23,7 +23,8 @@ for abi_item in CONTRACT_ABI: CONTRACT_FUNCTIONS[abi_item["name"]] = abi_item if abi_item["type"] == "constructor": CONTRACT_FUNCTIONS["constructor"] = abi_item - +if CONTRACT_FUNCTIONS["constructor"] is None: + CONTRACT_FUNCTIONS["constructor"] = {{"inputs" : []}} def init_web3(ipc_path: str) -> Web3: return Web3(web3.HTTPProvider(ipc_path)) diff --git a/moonworm/generator.py b/moonworm/generator.py index b28b0af..081db2e 100644 --- a/moonworm/generator.py +++ b/moonworm/generator.py @@ -96,7 +96,14 @@ def generate_contract_class( ] ), ) - contract_constructor = [c for c in abi if c["type"] == "constructor"][0] + contract_constructors = [c for c in abi if c["type"] == "constructor"] + if len(contract_constructors) == 1: + contract_constructor = contract_constructors[0] + elif len(contract_constructors) == 0: + contract_constructor = {"inputs": []} + else: + raise ValueError("Multiple constructors found in ABI") + contract_constructor["name"] = "constructor" class_functions = ( [class_constructor] @@ -261,7 +268,14 @@ def generate_function_subparser( subparsers.extend(generate_function_subparser(function_abi, "description")) # Deploy argparser: - contract_constructor = [item for item in abi if item["type"] == "constructor"][0] + contract_constructors = [item for item in abi if item["type"] == "constructor"] + if len(contract_constructors) == 1: + contract_constructor = contract_constructors[0] + elif len(contract_constructors) == 0: + contract_constructor = {"inputs": []} + else: + raise Exception("Multiple constructors found") + deploy_argument_parsers = [] default_arg_counter = 1 for arg in contract_constructor["inputs"]: diff --git a/moonworm/version.py b/moonworm/version.py index 8c99d04..b07ac57 100644 --- a/moonworm/version.py +++ b/moonworm/version.py @@ -1 +1 @@ -MOONWORM_VERSION = "0.0.2" +MOONWORM_VERSION = "0.0.3"