-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Move filter method to use Method class #1778
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
Conversation
ba906e7 to
cc2dd32
Compare
07af185 to
2d42385
Compare
135e28b to
3e51053
Compare
| try: | ||
| (method_str, params), response_formatters = method.process_params(module, *args, **kwargs) # noqa: E501 | ||
| except _UseExistingFilter as err: | ||
| return LogFilter(eth_module=module, filter_id=err.filter_id) |
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.
@pipermerriam I can't figure out how to pull this out without going back to passing around a string method name, since all of the formatters are chosen based on the method name. Let me know if you see another way!
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.
If we can't get this out, lets consider making it generic. I'd suggest doing that as a follow up to this PR.
Roughly speaking, it looks like we need an official way for a Method to short-circut the JSON-RPC request and to return a value that is generated locally. That could be using something like an exception like we did here, but I think that's probably not the best choice here because it feels like a heavy way to implement what is effectively an if/else.
We might need to return something more structured from process_params that we can then switch on.
request = method.preprocess_request(module, *args, **kwargs)
if request.is_json_rpc:
... # do the actual request
elif request.has_static_response:
... # directly return the response value.
else:
... # dunno, maybe just raise Exception("Invariant")I don't know if this is going to work, or be clean. Just my stab at what the API could look like. I think you'll be doing yourself and everyone on the team a favor to spend some time working on these APIs, especially in making them less cryptic in how they work.
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.
Yeah, agreed. I'll do some mucking around with it in another PR.
|
I think this is ready for a final look @marcgarreau and @pipermerriam! |
| try: | ||
| (method_str, params), response_formatters = method.process_params(module, *args, **kwargs) # noqa: E501 | ||
| except _UseExistingFilter as err: | ||
| return LogFilter(eth_module=module, filter_id=err.filter_id) |
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.
If we can't get this out, lets consider making it generic. I'd suggest doing that as a follow up to this PR.
Roughly speaking, it looks like we need an official way for a Method to short-circut the JSON-RPC request and to return a value that is generated locally. That could be using something like an exception like we did here, but I think that's probably not the best choice here because it feels like a heavy way to implement what is effectively an if/else.
We might need to return something more structured from process_params that we can then switch on.
request = method.preprocess_request(module, *args, **kwargs)
if request.is_json_rpc:
... # do the actual request
elif request.has_static_response:
... # directly return the response value.
else:
... # dunno, maybe just raise Exception("Invariant")I don't know if this is going to work, or be clean. Just my stab at what the API could look like. I think you'll be doing yourself and everyone on the team a favor to spend some time working on these APIs, especially in making them less cryptic in how they work.
b357c90 to
e6e4f9f
Compare
e6e4f9f to
017f24d
Compare
81a1249 to
0c0b40a
Compare
What was wrong?
Filter is the last method in Eth that wasn't using Method. This PR fixes that.
Todo:
Cute Animal Picture