github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/examples/configtxupdate/reconfig_membership/script.sh (about)

     1  #!/bin/bash
     2  
     3  CDIR=$(dirname $(basename "$0"))
     4  
     5  # Defaults
     6  : ${CHANNEL:="example"}
     7  : ${OUTDIR:="example_output"}
     8  mkdir -p ${OUTDIR} || die "could not create output dir ${OUTDIR}"
     9  
    10  CONFIG_BLOCK_PB="${OUTDIR}/config_block.pb"
    11  CONFIG_BLOCK_JSON="${OUTDIR}/config_block.json"
    12  CONFIG_JSON="${OUTDIR}/config.json"
    13  CONFIG_PB="${OUTDIR}/config.pb"
    14  UPDATED_CONFIG_JSON="${OUTDIR}/updated_config.json"
    15  UPDATED_CONFIG_PB="${OUTDIR}/updated_config.pb"
    16  CONFIG_UPDATE_PB="${OUTDIR}/config_update.pb"
    17  CONFIG_UPDATE_JSON="${OUTDIR}/config_update.json"
    18  CONFIG_UPDATE_IN_ENVELOPE_PB="${OUTDIR}/config_update_in_envelope.pb"
    19  CONFIG_UPDATE_IN_ENVELOPE_JSON="${OUTDIR}/config_update_in_envelope.json"
    20  
    21  CHANNEL_CREATE_TX=${OUTDIR}/channel_create_tx.pb
    22  
    23  . ${CDIR}/../common_scripts/common.sh
    24  
    25  bigMsg "Beginning config update membership example"
    26  
    27  findPeer || die "could not find peer binary"
    28  
    29  findConfigtxgen || die "could not find configtxgen binary"
    30  
    31  echo -e "Executing:\n\tconfigtxgen -channelID '${CHANNEL}' -outputCreateChannelTx '${CHANNEL_CREATE_TX}' -profile SampleSingleMSPChannel"
    32  ${CONFIGTXGEN} -channelID "${CHANNEL}" -outputCreateChannelTx "${CHANNEL_CREATE_TX}" -profile SampleSingleMSPChannel || die "error creating channel create tx"
    33  
    34  assertFileContainsProto "${CHANNEL_CREATE_TX}"
    35  
    36  bigMsg "Submitting channel create tx to orderer"
    37  
    38  createChannel "${CHANNEL}" "${CHANNEL_CREATE_TX}"
    39  
    40  bigMsg "Renaming current config block"
    41  
    42  echo -e "Executing:\n\tmv '${CHANNEL}.block' '${CONFIG_BLOCK_PB}'"
    43  mv "${CHANNEL}.block" "${CONFIG_BLOCK_PB}"
    44  
    45  bigMsg "Decoding current config block"
    46  
    47  decode common.Block "${CONFIG_BLOCK_PB}" "${CONFIG_BLOCK_JSON}"
    48  
    49  bigMsg "Isolating current config"
    50  
    51  echo -e "Executing:\tjq .data.data[0].payload.data.config '${CONFIG_BLOCK_JSON}' > '${CONFIG_JSON}'"
    52  jq .data.data[0].payload.data.config "${CONFIG_BLOCK_JSON}" > "${CONFIG_JSON}" || die "Unable to extract config from config block"
    53  
    54  pauseIfInteractive
    55  
    56  bigMsg "Generating new config"
    57  
    58  jq '. * {"channel_group":{"groups":{"Application":{"groups":{"ExampleOrg": .channel_group.groups.Application.groups.SampleOrg}}}}}'  "${CONFIG_JSON}"  | jq '.channel_group.groups.Application.groups.ExampleOrg.values.MSP.value.config.name = "ExampleOrg"' > "${UPDATED_CONFIG_JSON}"
    59  
    60  echo "Used JQ to write new config with 'ExampleOrg' defined to ${UPDATED_CONFIG_JSON}"
    61  
    62  pauseIfInteractive
    63  
    64  bigMsg "Translating original config to proto"
    65  
    66  encode common.Config "${CONFIG_JSON}" "${CONFIG_PB}"
    67  
    68  bigMsg "Translating updated config to proto"
    69  
    70  encode common.Config "${UPDATED_CONFIG_JSON}" "${UPDATED_CONFIG_PB}"
    71  
    72  bigMsg "Computing config update"
    73  
    74  computeUpdate "${CHANNEL}" "${CONFIG_PB}" "${UPDATED_CONFIG_PB}" "${CONFIG_UPDATE_PB}"
    75  
    76  bigMsg "Decoding config update"
    77  
    78  decode common.ConfigUpdate "${CONFIG_UPDATE_PB}" "${CONFIG_UPDATE_JSON}"
    79  
    80  bigMsg "Generating config update envelope"
    81  
    82  wrapConfigEnvelope "${CONFIG_UPDATE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_JSON}"
    83  
    84  bigMsg "Encoding config update envelope"
    85  
    86  encode common.Envelope "${CONFIG_UPDATE_IN_ENVELOPE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_PB}"
    87  
    88  bigMsg "Sending config update to channel"
    89  
    90  updateConfig ${CHANNEL} "${CONFIG_UPDATE_IN_ENVELOPE_PB}"
    91  
    92  bigMsg "Config Update Successful!"