forked from bitshares/python-bitshares
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.py
More file actions
44 lines (33 loc) · 1.28 KB
/
Copy pathinstance.py
File metadata and controls
44 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import bitshares as bts
class SharedInstance():
instance = None
config = {}
def shared_bitshares_instance():
""" This method will initialize ``SharedInstance.instance`` and return it.
The purpose of this method is to have offer single default
bitshares instance that can be reused by multiple classes.
"""
if not SharedInstance.instance:
clear_cache()
SharedInstance.instance = bts.BitShares(**SharedInstance.config)
return SharedInstance.instance
def set_shared_bitshares_instance(bitshares_instance):
""" This method allows us to override default bitshares instance for all
users of ``SharedInstance.instance``.
:param bitshares.bitshares.BitShares bitshares_instance: BitShares
instance
"""
clear_cache()
SharedInstance.instance = bitshares_instance
def clear_cache():
""" Clear Caches
"""
from .blockchainobject import BlockchainObject
BlockchainObject.clear_cache()
def set_shared_config(config):
""" This allows to set a config that will be used when calling
``shared_bitshares_instance`` and allows to define the configuration
without requiring to actually create an instance
"""
assert isinstance(config, dict)
SharedInstance.config = config