Open carver opened 4 years ago
Poking around this and your other couple issues now 👀
Was able to reproduce this, but I'm unclear on expected behavior. Should ContractEvent.processLog()
and ContractEvent().processLog()
have identical output?
Should
ContractEvent.processLog()
andContractEvent().processLog()
have identical output?
So, there seems to be some kind of half-baked feature to filter events by argument name. I don't really understand that use case, and it doesn't seem tested at the contract API level.
Maybe it's worth looking a little deeper about what how the argument_names
input to the ContractEvent
init method work. (and maybe removing it until there's a properly supported feature there?)
But yeah, my naive expectation was for ContractEvent.processLog()
to work without instantiating the event. Without looking at the web3 API, I sort of expected an instantiated event to be like a bound function call, where the event would have some values attached, and you could do something like encode it from there. But that's not a current need I have.
Hey there, @carver ! Is this issue still open? I would love to contribute to this. Please let me know. Thanks!
I believe so. A contribution would be great! I would ask Marc, but he's out right now. Maybe @kclowes knows for sure.
@smishy05 Yep, it's still open! Feel free to open a PR and tag me if you need any direction! Thanks!
Thanks @carver and @kclowes! I am new to open source and I have been looking at other issues as well in web3py! Will open a PR in one which seems more reachable now.
Maybe:
1. make .abi a @property that caches the result of _get_event_abi()
2. drop .abi altogether and use _get_event_abi() everywhere internally
3. set .abi when ContractEvents builds all its event attrs
I think my preference is # 1
Most importantly: add a test showing that this is broken, and make sure the test works by seeing it fail before implementing the fix.
@carver - Are the three steps mentioned by you a good start for this?
@smishy05 Those were options on how to solve the problem. So you'd want to pick one, write a test and then implement a fix. I'd go with option #1. Thanks!
Hey @carver and @kclowes !
I have gone through the contract.py
and I was able regenerate the error.
This is the code that I used for getting the error.
from web3 import Web3
import json
json_file_path = "./abi.json"
with open(json_file_path, 'r') as j:
contents = json.loads(j.read())
network_url = 'http://localhost:8545'
web3 = Web3(Web3.HTTPProvider(network_url))
address = "0x1f942eF89297cC2A0eF5e5FC9c52D617B3f34011"
acontract = web3.eth.contract(address=address, abi=contents)
tx_hash = acontract.functions.getValue(5, 10).transact({'from': web3.eth.accounts[0]})
receipt = web3.eth.get_transaction_receipt(tx_hash)
log_to_process = receipt['logs'][0]
ev = acontract.events.Increment.processLog(log_to_process)
print(ev)
I have migrated the contract using Truffle and used Ganache for deployment (I think this information is superfluous, however I have mentioned it if it has any significance). Hence, I wanted to ask if this code is fine?
What should be the parameter that would indicate if I have resolved the issue? That is, what should be expected from my side? Should the output of ContractEvent.processLog()
and ContractEvent().processLog()
be the same?
As suggested by @carver , do I have to simply add the @property
that catches the result of _get_event_abi()
? Also by the term caches the result, do you mean that _get_event_abi()
is the getter function for the @property
?
It would be great if you could clarify these doubts. Also, sorry for multiple questions!
Waiting for your response and many thanks!
Hi @carver and @kclowes !
I have opened a PR and I used # 2 for solving this issue. I have put the reason for not using # 1 for solving the issue. Please let me know if I have gone wrong somewhere.
Hoping to hear from you soon,
Many thanks!
What was wrong?
When
ContractEvent.processLog()
is called (instead ofContractEvent().processLog()
), you get this:How can it be fixed?
The event ABI is only set on initialization, which doesn't make sense to me.
Maybe:
.abi
a@property
that caches the result of_get_event_abi()
.abi
altogether and use_get_event_abi()
everywhere internally.abi
whenContractEvents
builds all its event attrsI think my preference is # 1
Most importantly: add a test showing that this is broken, and make sure the test works by seeing it fail before implementing the fix.