-
Notifications
You must be signed in to change notification settings - Fork 46
Contract.get_logs function #106
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
base: master
Are you sure you want to change the base?
Conversation
| raise "Number of provided arguments to constructor is incorrect. Was given #{ | ||
| arg_count | ||
| } args, looking for #{input_types_count}." | ||
| raise "Number of provided arguments to constructor is incorrect. Was given #{arg_count} args, looking for #{input_types_count}." |
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.
mix format
| event_data[key] | ||
| |> Integer.to_string(16) | ||
| |> String.downcase() | ||
| |> String.replace_prefix("", "0x") |
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 had to change these lines because most RPC don't accept numbers with leading 0's like:
Errors encountered in param 0: Invalid value "0x014f7c5b" supplied to : RpcFilterRequest/fromBlock: (QUANTITY | "earliest" | "latest" | "pending") | undefined/0: QUANTITY, Invalid value "0x0000000000000000000000000000000000000000000000000000000000000001" supplied to
: RpcFilterRequest/fromBlock: (QUANTITY | "earliest" | "latest" | "pending") | undefined/1: "earliest" | "latest" | "pending", Invalid value "0x0000000000000000000000000000000000000000000000000000000000000001" supplied to : RpcFilterRequest/toBlock: (QUANTITY | "earlie
st" | "latest" | "pending") | undefined/0: QUANTITY, Invalid value "0x0000000000000000000000000000000000000000000000000000000000000002" supplied to : RpcFilterRequest/toBlock: (QUANTITY | "earliest" | "latest" | "pending") | undefined/1: "earliest" | "latest" | "pendin
g"
Tested against hardhat native node & https://polygon-rpc.com & alchemy.
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 remember going about adding the 0x prefix a long time ago to fix other bugs. Maybe it isn't needed for logs.
@rupurt do you think this would break on other eth clients?
| assert {:ok, accounts} = ExW3.Client.call_client(:eth_accounts) | ||
| assert Enum.count(accounts) > 0 | ||
| assert ["0x" <> _ = account] = accounts | ||
| assert ["0x" <> _ = account | _] = accounts |
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.
When hardhat node or any other pre-populated you always have more than 1 account so, just ignore it =)
| assert log["transactionHash"] == simple_tx_hash | ||
| end | ||
|
|
||
| test "Testing formatted get logs", context do |
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.
based on get_filter_changes test
|
@Shelvak Thanks! These are welcome changes. Your approach to block watching is certainly the safest, glad that exw3 can be helpful for you. |
ExW3.Contract.get_logsfunction to get formatted logs between blocks for a given "contract".Need
The get_filter_changes is useful but has 2 problems (at least for me):
1- The query doesn't return logs between 2 given block numbers, just the "new" (like the name specify =) )
2- After a few manual tests, the filter_id disappear after a minute or so without quering. If the supervisor die for some reason you can't get the "missing changes" You have to create a new filter id and start from "now".
To work around these 2 issues, I prefer directly ask for a block range and process the returned logs, then ask again from where I left.
If anything can be improved let me know =)
I'll let a few comments in the PR to let you know why I had to make changes.
Manually tested on Polygon