Skip to content

Commit

Permalink
Minimal support for raw abi inputs (#154)
Browse files Browse the repository at this point in the history
#153

## Minor fixes
- Bug fix for missing whitespace when there is no raw bytecode.
- Adding support for uint224.
  • Loading branch information
slundqui authored Dec 9, 2024
1 parent cc87e61 commit 730e236
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pypechain/templates/contract.py/contract.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class {{contract_name}}Contract(Contract):
_raw_bytecode : HexStr | None = HexStr("{{bytecode}}")
{% else %}
_raw_bytecode : HexStr | None = None
{%- endif -%}
{% endif %}

def __init__(self, address: ChecksumAddress | None = None) -> None:
# Initialize parent Contract class
Expand Down
17 changes: 16 additions & 1 deletion pypechain/utilities/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,21 @@ def load_abi_infos_from_file(file_path: Path) -> list[AbiInfo]:
)
]

if is_abi(json_file):
abi = get_abi_from_json(json_file)
# TODO bytecode should be none
bytecode = ""
bytecode_link_references = []
contract_name = file_path.name.removesuffix(".json")
return [
AbiInfo(
abi=abi,
bytecode=bytecode,
contract_name=contract_name,
bytecode_link_references=bytecode_link_references,
)
]

raise ValueError("Unknown ABI Json format")


Expand Down Expand Up @@ -975,7 +990,7 @@ def get_abi_from_json(json_abi: FoundryJson | HardhatJson | ABI) -> ABI:

def is_abi(maybe_abi: object) -> TypeGuard[ABI]:
"""Typeguard for ABI's"""
if not isinstance(json, list):
if not isinstance(maybe_abi, list):
return False # ABI should be a list

# Check if there's at least one entry with 'name', 'inputs', and 'type'
Expand Down
1 change: 1 addition & 0 deletions pypechain/utilities/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def solidity_to_python_type(solidity_type: str, custom_types: list[str] = []) ->
"uint200",
"uint208",
"uint216",
"uint224",
"uint232",
"uint240",
"uint248",
Expand Down

0 comments on commit 730e236

Please sign in to comment.