golos.ws_client

Copyright:

+===================================================+
|                 © 2019 Privex Inc.                |
|               https://www.privex.io               |
+===================================================+
|                                                   |
|        Privex's Golos Library                     |
|        License: X11/MIT                           |
|                                                   |
|        Core Developer(s):                         |
|                                                   |
|          (+)  Chris (@someguy123) [Privex]        |
|                                                   |
+===================================================+

Privex's Golos Python Library
Copyright (c) 2019    Privex Inc. ( https://www.privex.io )

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

error_handler([data, msg])

Extracts and renders the format string inside of a Graphene JSON error object, then raises the appropriate exception using _find_exception()

Classes

WsClient([report, nodes])

Simple Golos JSON-WebSocket-RPC API This class serves as an abstraction layer for easy use of the Golos API.

class golos.ws_client.WsClient(report=False, nodes: Union[List[str], str] = None, **kwargs)[source]

Bases: object

Simple Golos JSON-WebSocket-RPC API This class serves as an abstraction layer for easy use of the Golos API.

With manually specified nodes:

>>> rpc = WsClient(nodes=['wss://golosd.privex.io'])

With no arguments (use the default nodes):

>>> rpc = WsClient()
Args:

nodes (list): A list of Golos WebSocket RPC nodes to connect to.

Any call available to that node can be issued using the instance

>>> rpc.call('command', 'my_param1', 'other_param2')
MAX_RETRIES = 5
RETRY_DELAY = 1
call(name, *args) → Union[dict, list, bool][source]

Make a JsonRPC call to the current working WS node.

Basic Usage:

>>> accs = WsClient().call('get_accounts', ['someguy123'])
>>> accs[0]['owner']
'someguy123'
Parameters
  • name (str) – The API method to call, e.g. get_accounts

  • args (Any) – Any extra positional args will be passed as parameters to the JsonRPC call

Raises

RetriesExceeded – When too many failures occurred while re-trying the JsonRPC call / WS connection.

Return dict|list result

The result from the call, generally as a dict or list

Return bool result

In the event of minor errors, False or None may be returned.

close()[source]

Close the connection on the websocket.WebSocket object

next_node()[source]
node_connect(url: str = None)[source]
sslopt_ca_certs = {'cert_reqs': <VerifyMode.CERT_NONE: 0>}
ws_connect()[source]

Attempt to connect to a working GOLOS WebSockets node.

golos.ws_client.error_handler(data: dict = None, msg: str = None)[source]

Extracts and renders the format string inside of a Graphene JSON error object, then raises the appropriate exception using _find_exception()

Example usage:

With a Graphene error result:

>>> response = dict(
...     error=dict(
...         message="Could not find API ${api}", data=dict(api='market_history'), code=-381
...     )
... )
>>> error_handler(data=response)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
APINotFound: 'Error Code -381: Could not find API "market_history"'

With a plain string error message:

>>> error_handler(msg='random error msg')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
GolosException: 'random error msg'
Parameters
  • data (dict) – The original graphene JSON dict response, containing the error key

  • msg (str) – If specified, will not parse data, instead will directly pass msg to _find_exception() - raising the appropriate exception based on your message.