Skip to content

Commit

Permalink
[api] make sure to use increasing request ids, more flexibility for m…
Browse files Browse the repository at this point in the history
…ethod overwriting
  • Loading branch information
xeroc committed Jun 24, 2016
1 parent c73fea4 commit 27c4bb6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions grapheneapi/graphenewsrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ class GrapheneWebsocketRPC(object):
subsystem, please use ``GrapheneWebsocket`` instead.
"""
api_id = {}

def __init__(self, url, user="", password=""):
self.api_id = {}
self._request_id = 0
self.url = url
self.user = user
self.password = password
self.wsconnect()
self.register_apis()

def get_request_id(self):
self._request_id += 1
return self._request_id

def wsconnect(self):
while True:
Expand All @@ -57,9 +62,11 @@ def wsconnect(self):
except KeyboardInterrupt:
break
except:
log.warning("Cannot connect to WS node: %s" % self.url)
log.warning("Lost connection to node: %s. Retrying in 10 seconds" % self.url)
time.sleep(10)
self.login(self.user, self.password, api_id=1)

def register_apis(self):
self.api_id["database"] = self.database(api_id=1)
self.api_id["history"] = self.history(api_id=1)
self.api_id["network_broadcast"] = self.network_broadcast(api_id=1)
Expand Down Expand Up @@ -318,7 +325,7 @@ def method(*args, **kwargs):
query = {"method": "call",
"params": [api_id, name, list(args)],
"jsonrpc": "2.0",
"id": 0}
"id": self.get_request_id()}
r = self.rpcexec(query)
return r
return method

0 comments on commit 27c4bb6

Please sign in to comment.