Skip to content

Commit

Permalink
[api] don't use static variables to allow usage of library against mu…
Browse files Browse the repository at this point in the history
…ltiple chains simultanously
  • Loading branch information
xeroc committed Jul 11, 2016
1 parent 1f35291 commit db78e4c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 41 deletions.
32 changes: 16 additions & 16 deletions grapheneapi/grapheneclient.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .grapheneapi import GrapheneAPI
from .graphenews import GrapheneWebsocket
from collections import OrderedDict

import logging
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -315,24 +314,25 @@ class GrapheneClient() :
graphene.run()
"""
wallet_host = None
wallet_port = None
wallet_user = None
wallet_password = None
witness_url = None
witness_user = None
witness_password = None
prefix = None
def __init__(self, config):

#: RPC connection to the cli-wallet
rpc = None
#: Definition of usual member variables
self.wallet_host = None
self.wallet_port = None
self.wallet_user = None
self.wallet_password = None
self.witness_url = None
self.witness_user = None
self.witness_password = None
self.prefix = None

#: Websocket connection to the witness/full node
ws = None
#: RPC connection to the cli-wallet
self.rpc = None

def __init__(self, config):
""" Initialize configuration
"""
#: Websocket connection to the witness/full node
self.ws = None

# Initialize configuration
available_features = dir(config)

if ("wallet_host" in available_features and
Expand Down
47 changes: 22 additions & 25 deletions grapheneapi/graphenewsprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,36 @@ class GrapheneWebsocketProtocol(WebSocketClientProtocol):
behavior.
"""

#: loop will be used to indicate the loss of connection
loop = None

#: Database callbacks and IDs for object subscriptions
database_callbacks = {}
database_callbacks_ids = {}
def __init__(self):
#: loop will be used to indicate the loss of connection
self.loop = None

#: Accounts and callbacks for account updates
accounts = []
accounts_callback = None
#: Database callbacks and IDs for object subscriptions
self.database_callbacks = {}
self.database_callbacks_ids = {}

#: Markets to subscribe to
markets = []
#: Accounts and callbacks for account updates
self.accounts = []
self.accounts_callback = None

#: Assets to subscribe to
assets = []
#: Markets to subscribe to
self.markets = []

#: Storage of Objects to reduce latency and load
objectMap = None
#: Assets to subscribe to
self.assets = []

#: Event Callback registrations and fnts
onEventCallbacks = {}
#: Storage of Objects to reduce latency and load
self.objectMap = None

#: Registered APIs with corresponding API-IDs
api_ids = {}
#: Event Callback registrations and fnts
self.onEventCallbacks = {}

#: Incremental Request ID and request storage (FIXME: request storage
#: is not cleaned up)
request_id = 0
requests = {}
#: Registered APIs with corresponding API-IDs
self.api_ids = {}

def __init__(self):
pass
#: Incremental Request ID and request storage
self.request_id = 0
self.requests = {}

def _get_request_id(self):
self.request_id += 1
Expand Down

0 comments on commit db78e4c

Please sign in to comment.