Skip to content

Commit

Permalink
Merge pull request #14 from bugout-dev/fix-empy-constructor
Browse files Browse the repository at this point in the history
fix no constructor
  • Loading branch information
Yhtiyar authored Nov 9, 2021
2 parents c4758f2 + 2b751e3 commit aa733ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion moonworm/cli.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 16 additions & 2 deletions moonworm/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion moonworm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MOONWORM_VERSION = "0.0.2"
MOONWORM_VERSION = "0.0.3"

0 comments on commit aa733ce

Please sign in to comment.