New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose get_event_data
, get_function_info
utilities
#3268
Conversation
470a26b
to
83ca21c
Compare
Overall great, my only question is how to obtain an |
746fd30
to
bb97192
Compare
bb97192
to
04064f3
Compare
04064f3
to
8b6c666
Compare
8b6c666
to
7b04074
Compare
7b04074
to
132652b
Compare
There are now two additional utilities I made public to assist with the
|
Build filter params using `construct_event_filter_params` Find ABIs for events and functions with `find_matching_event_abi`, `find_matching_fn_abi` Fix imports
132652b
to
286bbdb
Compare
Not to throw a wrench in the spokes, but before we make this public via an API, do you think this is worth a re-consideration: #2489 ? |
On second thought, if we can handle this strictness in the codec itself this should remain unchanged. See my comment here. That might be a more elegant solution than passing Thoughts? |
I like the idea of putting this within the codec itself as it seems much more flexible. I think if we decide to add more contract utility functions the flag could be required for other functions that deal with events. It looks like the decode issue could happen for any kind of log, so if that is true it would be easier to maintain in the codec. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay as a first step to expose these methods, but I think we could really improve on this API. For example, it might be nice to return an object for get_function_info
instead of a tuple. It also feels clunky to be passing around the codec. Feel free to take or leave, but I think if we put these methods on the web3 instance instead, we don't need to pass the codec through. I'm curious too if you have any other ideas about where we might make the API better.
|
||
Inspect a contract function from an ABI as follows: | ||
|
||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These code blocks would be really good candidates for doctests. I think there are some examples of doctests in this file, but let me know if you need more direction than that!
@kclowes Great ideas, I also think we can do better with these. I see several functions that deal with In addition to I think the I think we can expose the same functionality of the function and event abi helpers but with descriptive names. After an initial think through those candidates, I came up with the following: # get all functions in a contract
fns = w3.get_contract_functions(contract_abi: ABI)
# ABIFunction
fn = fns[0]
fn_name = fn["name"]
fn_abi = w3.get_contract_function_abi(contract_abi, fn_name, fn_args, fn_kwargs)
fn_arguments = w3.get_contract_function_arguments(fn_abi, fn_args, fn_kwargs)
fn_selector = w3.get_contract_function_selector(fn_abi)
fn_signature = w3.get_contract_function_signature(fn_abi)
# get all events in a contract
events = w3.get_contract_events(contract_abi)
# ABIEvent
event = events[0]
event_name = event["event"]
event_abi = w3.get_contract_event_abi(contract_abi, event_name, event_arg_names)
event_argument_names = w3.get_contract_event_argument_names(event_abi)
event_inputs = w3.get_contract_event_inputs(event_abi, indexed=True)
event = w3.get_contract_event_log(event_abi, log_entry) |
Good ideas! I like those! This is what Ethers exposes too, for reference. |
Closing this, proceeding in #3401 |
What was wrong?
Closes #1596
Relates to #3036
get_event_data
,get_function_info
utilities were inaccessible for public use even though many people have the need to use these functions without instantiating aContract
.Further refactoring to be covered in #3279
How was it fixed?
Expose these functions via
web3.contract.utils
.Todo:
Cute Animal Picture