-
Notifications
You must be signed in to change notification settings - Fork 4
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
[explorer/nodewatch] task: add new route #343
Open
AnthonyLaw
wants to merge
13
commits into
dev
Choose a base branch
from
task/new-route
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+660
−84
Open
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eadd734
[explorer/nodewatch] task: add new filed on NodeDescriptor and unit test
AnthonyLaw 574bc4d
[explorer/nodewatch] task: update unit test
AnthonyLaw 5052074
[explorer/nodewatch] task: add few new api symbol endpoint
AnthonyLaw 3442a05
[explorer/nodewatch] task: fix lint issue
AnthonyLaw 1832550
[explorer/nodewatch] task: update unit test
AnthonyLaw 6bd5ee5
[explorer/nodewatch] task: rename enable to enabled
AnthonyLaw 1e2628f
[explorer/nodewatch] task: rename and update filter logic
AnthonyLaw 9688016
[explorer/nodewatch] task: and more unit test and minor refactor
AnthonyLaw 214790a
[explorer/nodewatch] task: refactor and unit test
AnthonyLaw 9a18900
[explorer/nodewatch] task: more refactor and unit test
AnthonyLaw 34721cb
[explorer/nodewatch] task: improve unit test
AnthonyLaw 3010a0c
[explorer/nodewatch] task: fix undetected unit test
AnthonyLaw ab1851b
[explorer/nodewatch] task: add validate public key
AnthonyLaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import asyncio | ||
import datetime | ||
import random | ||
|
||
from zenlog import log | ||
|
||
|
@@ -65,15 +66,46 @@ def html_nodes(self): | |
'explorer_endpoint': self.explorer_endpoint | ||
}) | ||
|
||
def json_nodes(self, role, exact_match=False): | ||
"""Returns all nodes with matching role.""" | ||
def json_nodes(self, **kwargs): | ||
"""Returns all nodes with condition.""" | ||
|
||
def role_filter(descriptor): | ||
return role == descriptor.roles if exact_match else role == (role & descriptor.roles) | ||
role = kwargs.get('role', None) | ||
exact_match = kwargs.get('exact_match', False) | ||
limit = kwargs.get('limit', None) | ||
ssl = kwargs.get('ssl', None) | ||
order = kwargs.get('order', None) | ||
|
||
return list(map( | ||
def filter_custom(descriptor): | ||
Jaguar0625 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
role_condition = True | ||
|
||
if role is not None: | ||
role_condition = role == descriptor.roles if exact_match else role == (role & descriptor.roles) | ||
|
||
if ssl is not None: | ||
ssl_condition = (descriptor.is_https_enable == ssl and descriptor.is_wss_enable == ssl) | ||
return role_condition and ssl_condition | ||
|
||
return role_condition | ||
|
||
nodes = list(map( | ||
lambda descriptor: descriptor.to_json(), | ||
filter(role_filter, self.repository.node_descriptors))) | ||
filter(filter_custom, self.repository.node_descriptors))) | ||
|
||
if order is not None: | ||
if order == 'random': | ||
Jaguar0625 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
random.shuffle(nodes) | ||
|
||
if limit is not None: | ||
nodes = nodes[:limit] | ||
|
||
return nodes | ||
|
||
def json_node(self, filter_field, public_key): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might want to consider checking if public_key is proper public key and returning 400 if not |
||
"""Returns a node with matching public key.""" | ||
|
||
matching_items = [item.to_json() for item in self.repository.node_descriptors if item.to_json()[filter_field] == public_key] | ||
Jaguar0625 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return next(iter(matching_items), None) | ||
|
||
def json_height_chart(self): | ||
"""Builds a JSON height chart.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
enable => enabled (x2)
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.
do we actually need BOTH of these?
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.
For the explorer, we will need the
is_https_enable
, for the wallet it needsis_wss_enable
.Can we consider if https enable, we can assume wss is enable?
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.
yes, i would.
cc: @gimre-xymcity