-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Remove explicit send calls, part deux #4408
Remove explicit send calls, part deux #4408
Conversation
This makes it more inline with the method 'send' of which synchronous_send is the, well, synchronous version.
This is again a small step in the right direction. The network module is going to accumulate more and more of these simple methods. Once everything is moved into that module, that module is going to be split. Note that I've left the scripts which use scripts/util.py alone. I suspect the same functionality can be reached when using just lib/network.py and that scripts/util.py is obsolete.
Websocket still has some references, that'll take more work to remove. Once the network module has been split this should be easy. I took the liberty to rename a variable to better show what it is.
The naming scheme I'm following for the newly introduced methods in the network module is: 'blockchain.<subject>.<action>' -> def <action>_(for|to)_<subject>
This makes it easier to keep track of the methods which are due to be extracted.
This is the final step to formalize (the informal) interface of the network module. A chance of note is changed interface for async/sync calls. It is no longer required to use the `synchronous_send` call. Merely NOT passing a callback makes the call synchronous. I feel this makes the API more intuitive to work with and easier to replace with a different network module.
The pattern which emerged for calling the lambda yielded an slight refactor. I'm not happy with the name for the `__invoke` method.
This parameter doesn't seem to be used a lot and removing it makes the remaining calls easier. Potentionally a contentious choice!
Doing so makes the method name consistent with the other ElectrumX protocol method names.
Now every method is intuitive in what it does, no special handling required. The `broadcast_transaction` method is weird. I've opted not to change the return type b/c I found it hard to know what the exact consequences are. But ideally this method should just works as all the other ElectrumX related messages. On the other hand this shows nicely how you _can_ do something differnt quite easy.
The new name reflects what it does.
I've used flake8-diff (and ignored a couple of line length warnings).
This fell through the cracks when this branch was rebased.
An oversight while refactoring.
Without this statement the transaction would have been broadcasted twice.
lib/network.py
Outdated
@@ -1059,27 +1034,132 @@ def follow_chain(self, index): | |||
def get_local_height(self): | |||
return self.blockchain().height() | |||
|
|||
def synchronous_get(self, request, timeout=30): | |||
def __wait_for(it): |
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.
Even if it's not needed, could you make this a @staticmethod
?
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.
This is indeed not needed but I'll gladly conform.
lib/network.py
Outdated
|
||
return result.get('result') | ||
|
||
def __with_default_synchronous_callback(invocation, callback): |
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.
same; staticmethod
?
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.
idem
lib/network.py
Outdated
|
||
def get_transactions(self, transaction_hashes, callback=None): | ||
command = 'blockchain.transaction.get' | ||
messages = [(command, tx_hash) for tx_hash in transaction_hashes] |
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.
(command, [tx_hash])
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.
good catch.
This is a continuation of #4376. The only thing changed is one commit fixing a bug in the original PR, I thought I could reopen the PR but I can't after I rebased the commits. Ping @SomberNight, @kyuupichan.
From the original:
The goal here was to make the code base easier to understand and more decoupled. All the ElectrumX protocol mentions are now in the network module. Except for two instances in the websockets module.
Functionally almost nothing changed. The only thing which changed is that in the commands module an optional timeout parameter could be passed. That parameter has been removed in favor of simpler code.
Contributed by FDF