Decentralized Network Crawler - decentralized_client
¶
Table of Contents
Description:
Decentralized Client Class for Crawling the Tradehub network. This client is the basis to all classes because it allows network calls to fail over to other nodes. This class is designed to find available public nodes to interact with for API and Websocket calls.
Usage:
from tradehub.decentralized_client import NetworkCrawlerClient
Classes:
|
This class crawls the Switcheo Validator network to build a list of accessible endpoints for APIs and Websockets. Execution of this function is as follows::. |
-
class
tradehub.decentralized_client.
NetworkCrawlerClient
(network: str = 'testnet', trusted_ip_list: Optional[list] = None, trusted_uri_list: Optional[list] = None, is_secure: bool = False, is_websocket_client: bool = False)[source]¶ Bases:
object
This class crawls the Switcheo Validator network to build a list of accessible endpoints for APIs and Websockets. Execution of this function is as follows:
NetworkCrawlerClient(network='mainnet', trusted_ip_list=None, trusted_uri_list=None, is_secure=False, is_websocket_client=True)
Methods:
parse_validator_status
(request_json, …)Function to parse each peer’s JSON element and build information about each.
sentry_status_request
([uri])This function is here to ensure the nodes that have open network connections also have their persistence service running.
tradehub_get_request
(path[, params])This is a wrapper for the get request function to allow for retrying network calls on different available validators if a request fails.
tradehub_post_request
(path[, data, …])This is a wrapper for the post request function to allow for retrying network calls on different available validators if a request fails.
Crawl the Tradehub Validators to test for available API endpoints.
validator_status_request
(validator_ip)Function that makes the network requests to the Tradehub validators across the network.
websocket_status_check
(ip[, port])Function to check if the websocket port is open for communication.
-
parse_validator_status
(request_json: dict, validator_ip: str)[source]¶ Function to parse each peer’s JSON element and build information about each.
Execution of this function is as follows:
parse_validator_status(request_json='/status', validator_ip='54.255.5.46')
The expected return result for this function is as follows:
{ 'moniker': 'spock', 'id': 'ca1189045e84d2be5db0a1ed326ce7cd56015f11', 'ip': '54.255.5.46', 'version': '0.33.7', 'network': 'switcheo-tradehub-1', 'latest_block_hash': 'DF194D43058D3CD89DD98A7DA28164B239B9693C822A1DB16CCC27FB49CA587B', 'latest_block_height': '7995864', 'latest_block_time': '2021-02-27T19:51:00.162091183Z', 'earliest_block_height': '1', 'earliest_block_time': '2020-08-14T07:32:27.856700491Z', 'catching_up': False, 'validator_address': '7091A72888509B3F3069231081621DC988D63542', 'validator_pub_key_type': 'tendermint/PubKeyEd25519', 'validator_pub_key': 'epMp0h65WflL7r8tPGQwusVMbCHgy7ucRg8eDlEJPW0=', 'validator_voting_power': '0' }
- Parameters
request_json – Dictionary of the return response from the validator status request.
validator_ip – String of the IP address to connect to.
- Returns
Dictionary of validator information.
-
sentry_status_request
(uri: bool = False)[source]¶ This function is here to ensure the nodes that have open network connections also have their persistence service running. Many times the network connection is open for communication but the persistence service will not be on.
Execution of this function is as follows:
sentry_status_request(uri=True)
- Parameters
uri – Bool value for a URI or IP address.
-
tradehub_get_request
(path: str, params: Optional[dict] = None)[source]¶ This is a wrapper for the get request function to allow for retrying network calls on different available validators if a request fails.
Execution of this function is as follows:
tradehub_get_request(path='/txs')
- Parameters
path – String of the path being used for the network request that is going to be made.
params – Dict values that will added to the get request.
- Returns
Dictionary of the return request based on the network path sent.
-
tradehub_post_request
(path: str, data: Optional[dict] = None, json_data: Optional[dict] = None, params: Optional[dict] = None)[source]¶ This is a wrapper for the post request function to allow for retrying network calls on different available validators if a request fails.
Execution of this function is as follows:
tradehub_post_request(path='/txs')
- Parameters
path – String of the path being used for the network request that is going to be made.
data – Dict values that will added to the post request.
json_data – Dict values that will added to the post request.
params – Dict values that will added to the post request.
- Returns
Dictionary of the return request based on the network path sent.
-
validator_crawler_mp
()[source]¶ Crawl the Tradehub Validators to test for available API endpoints.
Execution of this function is as follows:
validator_crawler_mp()
-
validator_status_request
(validator_ip: str)[source]¶ Function that makes the network requests to the Tradehub validators across the network.
Execution of this function is as follows:
validator_status_request(validator_ip='54.255.5.46')
The expected return result for this function is as follows:
{ 'moniker': 'spock', 'id': 'ca1189045e84d2be5db0a1ed326ce7cd56015f11', 'ip': '54.255.5.46', 'version': '0.33.7', 'network': 'switcheo-tradehub-1', 'latest_block_hash': 'DF194D43058D3CD89DD98A7DA28164B239B9693C822A1DB16CCC27FB49CA587B', 'latest_block_height': '7995864', 'latest_block_time': '2021-02-27T19:51:00.162091183Z', 'earliest_block_height': '1', 'earliest_block_time': '2020-08-14T07:32:27.856700491Z', 'catching_up': False, 'validator_address': '7091A72888509B3F3069231081621DC988D63542', 'validator_pub_key_type': 'tendermint/PubKeyEd25519', 'validator_pub_key': 'epMp0h65WflL7r8tPGQwusVMbCHgy7ucRg8eDlEJPW0=', 'validator_voting_power': '0', 'validator_status': 'Active', 'connected_nodes': [ { 'node_id': 'd57a64f41487b5e421e91b71dceb0784cae57733', 'node_ip': '195.201.82.228', 'node_full': 'd57a64f41487b5e421e91b71dceb0784cae57733@195.201.82.228' }, ... ] }
- Parameters
validator_ip – String of the IP address to connect to.
- Returns
Dictionary of validators that the crawler has found with the status.
-
websocket_status_check
(ip: str, port: int = 5000)[source]¶ Function to check if the websocket port is open for communication. This is called as part of the sentry check because calling the websocket also requires the persistence service to be available.
Execution of this function is as follows:
websocket_status_check(ip='54.255.5.46', port=5000)
- Parameters
ip – String of the IP address to connect to.
port – Int value for the port to be checked.
-