Esempio n. 1
0
def channel_tx(opts):
    """Create and save Channel Transaction to K8S.

    Args:
        opts (dict): Nephos options dict.
    """
    # Change to blockchain materials directory
    chdir(opts["core"]["dir_config"])
    # Create Channel Tx
    for channel in get_channels(opts):
        channel_key = f"{opts['channels'][channel]['channel_name']}.tx"
        channel_file = join(opts["core"]["dir_crypto"], channel_key)
        if not exists(channel_file):
            # Channel transaction creation and storage
            execute(
                f"configtxgen -profile {opts['channels'][channel]['channel_profile']} -channelID {opts['channels'][channel]['channel_name']} -outputCreateChannelTx {channel_file}"
            )
        else:
            logging.info(f"{channel_file} already exists")
        # Create the channel transaction secret
        for msp in get_msps(opts=opts):
            if msp not in opts["channels"][channel]["msps"]:
                continue
            peer_namespace = get_namespace(opts, msp=msp)
            secret_from_file(
                secret=opts["channels"][channel]["secret_channel"],
                namespace=peer_namespace,
                key=channel_key,
                filename=channel_file,
            )
            # Return to original directory
    chdir(PWD)
Esempio n. 2
0
def create_channel(opts):
    """Create Channel for Peer.

    Args:
        opts (dict): Nephos options dict.
        
    """
    ord_msp = get_an_orderer_msp(opts=opts)
    ord_namespace = get_namespace(opts, msp=ord_msp)
    ord_name = random.choice(list(get_orderers(opts=opts, msp=ord_msp)))
    cmd_suffix = peer_channel_suffix(opts, ord_msp, ord_name)

    for msp in get_msps(opts=opts):
        peer_namespace = get_namespace(opts, msp=msp)

        for channel in get_channels(opts=opts):
            channel_name = opts["channels"][channel]["channel_name"]
            secret_channel = opts["channels"][channel]["secret_channel"]
            if msp not in opts["channels"][channel]["msps"]:
                continue
            for index, release in enumerate(get_peers(opts=opts, msp=msp)):
                # Get peer pod
                pod_ex = get_helm_pod(peer_namespace, release, "hlf-peer")

                # Check if the file exists
                has_channel = False
                while not has_channel:
                    has_channel = get_channel_block(
                        pod_ex, ord_name, ord_namespace, channel_name, cmd_suffix
                    )
                    if not has_channel:
                        pod_ex.execute(
                            (
                                "bash -c 'peer channel create "
                                + f"-o {ord_name}-hlf-ord.{ord_namespace}.svc.cluster.local:7050 "
                                + f"-c {channel_name} -f /hl_config/channel/{secret_channel}/{channel_name}.tx {cmd_suffix}'"
                            )
                        )
                res, _ = pod_ex.execute("peer channel list")
                channels = (res.split("Channels peers has joined: ")[1]).split()
                if channel_name not in channels:
                    pod_ex.execute(
                        (
                            "bash -c "
                            + "'CORE_PEER_MSPCONFIGPATH=$ADMIN_MSP_PATH "
                            + f"peer channel join -b /var/hyperledger/{channel_name}.block {cmd_suffix}'"
                        )
                    )
Esempio n. 3
0
 def test_get_channels(self):
     assert {"AChannel", "BChannel"} == get_channels(opts=self.OPTS)