Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit 6d596f2

Browse files
Ram-srinipankajgoyal2
authored andcommitted
Optimization to fabric wrapper class
Read network.json file once in wrapper class. Signed-off-by: Ramakrishna Srinivasamurthy <ramakrishna.srinivasamurthy@intel.com>
1 parent 4a3c20f commit 6d596f2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

sdk/avalon_sdk/connector/blockchains/fabric/fabric_wrapper.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ class FabricWrapper():
3737
It provides wrapper functions to invoke and query chain code.
3838
"""
3939

40+
# Class variable
41+
network_config = None
42+
43+
@classmethod
44+
def init_network_config(cls, net_config_file):
45+
# Read network file path from fabric toml file.
46+
# Initalize the class variable network_config
47+
if FabricWrapper.network_config is None:
48+
logging.info("INITIALIZING network_config")
49+
with open(net_config_file, 'r') as profile:
50+
FabricWrapper.network_config = json.load(profile)
51+
4052
def __init__(self, config):
4153
"""
4254
Constructor to initialize wrapper with required parameter.
@@ -46,15 +58,13 @@ def __init__(self, config):
4658
These parameters are read from a .toml file
4759
"""
4860
if self.__validate(config):
49-
# Read network file path from fabric toml file.
50-
with open(self.__network_conf_file, 'r') as profile:
51-
self.__network_config = json.load(profile)
61+
FabricWrapper.init_network_config(self.__network_conf_file)
5262
self.__channel_name = config["fabric"]["channel_name"]
53-
self.__orgname = base.get_net_info(self.__network_config,
63+
self.__orgname = base.get_net_info(FabricWrapper.network_config,
5464
'client', 'organization')
5565
logging.debug("Org name choose: {}".format(self.__orgname))
5666
self.__peername = random.choice(base.get_net_info(
57-
self.__network_config, 'organizations', self.__orgname,
67+
FabricWrapper.network_config, 'organizations', self.__orgname,
5868
'peers'))
5969
# Get a txn committer
6070
self.__txn_committer = tx_committer.TxCommitter(

0 commit comments

Comments
 (0)