Skip to content

Conversation

@reedsa
Copy link
Contributor

@reedsa reedsa commented Apr 24, 2024

What was wrong?

Related to Issue #3279

Dependent PRs:
web3.py: #3408, #3401

eth-utils: ethereum/eth-utils#271

How was it fixed?

Exposes encode_abi ABI utility.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

Screen Shot 2024-04-23 at 5 25 55 PM

@reedsa reedsa force-pushed the abi-encode-util branch 5 times, most recently from 95af2f5 to 3f5a4aa Compare April 25, 2024 23:50
reedsa pushed a commit to reedsa/web3.py that referenced this pull request Apr 26, 2024
Stuart Reed added 11 commits May 16, 2024 12:42
* Use ABI types from `eth_typing`

* Fix reference to `ABIEventParam` and `ABIFunctionParam` types

* Import `get_abi_input_types` and `get_abi_output_types` from `eth-utils`

* Rename `collapse_if_tuple` -> `get_normalized_abi_arg_type`

* Import `get_abi_input_names` and `get_abi_output_names` from `eth_utils`
@reedsa reedsa force-pushed the abi-encode-util branch from d4e78a5 to 9c87e06 Compare May 16, 2024 18:42
@reedsa reedsa marked this pull request as ready for review May 16, 2024 19:05
@reedsa reedsa requested review from fselmo, kclowes and pacrob May 16, 2024 19:05
Copy link
Collaborator

@fselmo fselmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this needs rebasing and some conflict resolution but my review was requested so I left a first pass of comments. I think we can remove the need for is_async altogether from the utility method and pass in appropriate normalizers for each code block instead. I also don't think this is up to date with the latest eth-typing changes so I made some comments on using ABIComponent and ABICallable where appropriate. I may have missed some but in general it looks like this needs to be updated to match the current state of things there.

handle_offchain_lookup,
)

# from eth_utils import ( # NOQA
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be addressed. Are we waiting on anything here?



def encode_abi(
function_abi: Union[ABIFunction, ABIConstructor, ABIFallback, ABIReceive],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the new ABICallable, right?

if "inputs" not in abi and abi["type"] == "fallback":
return []
return [arg["name"] for arg in abi["inputs"]]
normalizers = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just have one set of normalizers, instead of data_normalizers and normalizers? We can probably take out the is_async from this utility method and just be able to pass in the data normalizers. I think that feature let's us achieve everything we want. From within the code block, the sync code can pass in all the normalizers it needs and the async code can do the same.

:param type: `HexStr`
:param arguments: Arguments used for the transaction request.
:param type: `Any`
:param is_async: Enable async transaction encoder.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably remove this if we go with my thought below.

:param data_normalizers: List of custom normalizers to apply to the data.
:param type: `list[Callable[..., Tuple[TypeStr, Any]]]`
:param abi_codec: Codec used for encoding and decoding.
:param type: `ABICodec`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:param type: `ABICodec`
:param type: `ABICodec` (optional)

abi_bytes_to_bytes,
abi_string_to_text,
]
if not w3.eth.is_async:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment about removing the is_async from the utility method. I think we can just build the appropriate normalizers here in the code block instead of trying to use an is_async flag for a general public utility method that's trying to encode abi. We can build the right normalizers for each code block and pass it in instead, one appropriate for the sync code block and another that is appropriate for the async code.


def named_tree(
abi: Iterable[Union[ABIFunctionParams, ABIFunction, ABIEvent, Dict[TypeStr, Any]]],
abi: Iterable[Union[ABIFunctionParam, ABIFunction, ABIEvent, Dict[TypeStr, Any]]],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
abi: Iterable[Union[ABIFunctionParam, ABIFunction, ABIEvent, Dict[TypeStr, Any]]],
abi: Iterable[Union[ABIComponent, ABIFunction, ABIEvent, Dict[TypeStr, Any]]],


def _named_subtree(
abi: Union[ABIFunctionParams, ABIFunction, ABIEvent, Dict[TypeStr, Any]],
abi: Union[ABIFunctionParam, ABIFunction, ABIEvent, Dict[TypeStr, Any]],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
abi: Union[ABIFunctionParam, ABIFunction, ABIEvent, Dict[TypeStr, Any]],
abi: Union[ABIComponent, ABIFunction, ABIEvent, Dict[TypeStr, Any]],



def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParams]:
def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParam]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParam]:
def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIComponent]:



def get_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParams]:
def get_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParam]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParam]:
def get_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIComponent]:

@reedsa reedsa removed request for kclowes and pacrob June 17, 2024 19:19
@reedsa reedsa closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants