Skip to content

Commit

Permalink
[GrapheneClient] Store core_asset inf GrapheneClient
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Mar 30, 2016
1 parent df7ef7f commit cdd73d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 6 additions & 6 deletions grapheneapi/grapheneclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def __init__(self, config):
self.wallet_user,
self.wallet_password)

core_asset = self.rpc.get_object("1.3.0")[0]
self.core_asset = self.rpc.get_object("1.3.0")[0]

# Connect to Witness Node
if "witness_url" in available_features:
Expand Down Expand Up @@ -446,16 +446,16 @@ def __init__(self, config):
{"registered-network-broadcast":
config.onRegisterNetworkBroadcast})

core_asset = self.ws.get_object("1.3.0")
self.core_asset = self.ws.get_object("1.3.0")

if not core_asset :
if not self.core_asset :
raise Exception("Neither WS nor RPC propery configured!")

if core_asset["symbol"] == "BTS" :
if self.core_asset["symbol"] == "BTS" :
self.prefix = "BTS"
elif core_asset["symbol"] == "MUSE" :
elif self.core_asset["symbol"] == "MUSE" :
self.prefix = "MUSE"
elif core_asset["symbol"] == "CORE" :
elif self.core_asset["symbol"] == "CORE" :
self.prefix = "GPH"

""" Get network configuration
Expand Down
16 changes: 16 additions & 0 deletions grapheneapi/graphenewsrpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import threading
from websocket import create_connection
import json
import time


class RPCError(Exception):
Expand Down Expand Up @@ -41,6 +43,20 @@ def __init__(self, url, user="", password=""):
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)
# self.enable_pings()

def _send_ping(self, interval, event):
while not event.wait(interval):
self.last_ping_tm = time.time()
if self.sock:
self.sock.ping()

def enable_pings(self):
event = threading.Event()
ping_interval = 30
thread = threading.Thread(target=self._send_ping, args=(ping_interval, event))
thread.setDaemon(True)
thread.start()

def get_call_id(self):
""" Get the ID for the next RPC call """
Expand Down

0 comments on commit cdd73d7

Please sign in to comment.