def _genesis2base64(self, network): """ convert genesis.block to Base64 :param network: network id :return: genesis block :rtype: bytearray """ try: dir_node = "{}/{}/".format(CELLO_HOME, network) name = "genesis.block" zname = "block.zip" zip_file("{}{}".format(dir_node, name), "{}{}".format(dir_node, zname)) with open("{}{}".format(dir_node, zname), "rb") as f_block: block = base64.b64encode(f_block.read()) return block except Exception as e: raise e
def _conversion_msp_tls_cfg(self, type, org, node): """ msp and tls , cfg from zip file to byte :param org: organization name :param type: node type :param node: node name :return: msp, tls, cfg :rtype: bytes """ try: if type == "peer": dir_node = "{}/{}/crypto-config/peerOrganizations/{}/peers/{}/" \ .format(CELLO_HOME, org, org, node + "." + org) name = "core.yaml" cname = "peer_config.zip" else: dir_node = "{}/{}/crypto-config/ordererOrganizations/{}/orderers/{}/" \ .format(CELLO_HOME, org, org.split(".", 1)[1], node + "." + org.split(".", 1)[1]) name = "orderer.yaml" cname = "orderer_config.zip" zip_dir("{}msp".format(dir_node), "{}msp.zip".format(dir_node)) with open("{}msp.zip".format(dir_node), "rb") as f_msp: msp = base64.b64encode(f_msp.read()) zip_dir("{}tls".format(dir_node), "{}tls.zip".format(dir_node)) with open("{}tls.zip".format(dir_node), "rb") as f_tls: tls = base64.b64encode(f_tls.read()) zip_file("{}{}".format(dir_node, name), "{}{}".format(dir_node, cname)) with open("{}{}".format(dir_node, cname), "rb") as f_cfg: cfg = base64.b64encode(f_cfg.read()) except Exception as e: raise e return msp, tls, cfg