github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/examples/configtxupdate/reconfig_batchsize/script.sh (about) 1 #!/bin/bash 2 3 CDIR=$(dirname $(basename "$0")) 4 5 # Defaults 6 : ${CHANNEL:="testchainid"} 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 . ${CDIR}/../common_scripts/common.sh 22 23 bigMsg "Beginning config update batchsize example" 24 25 findPeer || die "could not find peer binary" 26 27 bigMsg "Fetching current config block" 28 29 fetchConfigBlock "${CHANNEL}" "${CONFIG_BLOCK_PB}" 30 31 bigMsg "Decoding current config block" 32 33 decode common.Block "${CONFIG_BLOCK_PB}" "${CONFIG_BLOCK_JSON}" 34 35 bigMsg "Isolating current config" 36 37 echo -e "Executing:\tjq .data.data[0].payload.data.config '${CONFIG_BLOCK_JSON}' > '${CONFIG_JSON}'" 38 jq .data.data[0].payload.data.config "${CONFIG_BLOCK_JSON}" > "${CONFIG_JSON}" || die "Unable to extract config from config block" 39 40 pauseIfInteractive 41 42 bigMsg "Generating new config" 43 44 OLD_BATCH_SIZE=$(jq ".channel_group.groups.Orderer.values.BatchSize.value.max_message_count" "${CONFIG_JSON}") 45 NEW_BATCH_SIZE=$(($OLD_BATCH_SIZE+1)) 46 47 echo -e "Executing:\tjq '.channel_group.groups.Orderer.values.BatchSize.value.max_message_count = $NEW_BATCH_SIZE' '${CONFIG_JSON}' > '${UPDATED_CONFIG_JSON}'" 48 jq ".channel_group.groups.Orderer.values.BatchSize.value.max_message_count = $NEW_BATCH_SIZE" "${CONFIG_JSON}" > "${UPDATED_CONFIG_JSON}" || die "Error updating batch size" 49 50 pauseIfInteractive 51 52 bigMsg "Translating original config to proto" 53 54 encode common.Config "${CONFIG_JSON}" "${CONFIG_PB}" 55 56 bigMsg "Translating updated config to proto" 57 58 encode common.Config "${UPDATED_CONFIG_JSON}" "${UPDATED_CONFIG_PB}" 59 60 bigMsg "Computing config update" 61 62 computeUpdate "${CHANNEL}" "${CONFIG_PB}" "${UPDATED_CONFIG_PB}" "${CONFIG_UPDATE_PB}" 63 64 bigMsg "Decoding config update" 65 66 decode common.ConfigUpdate "${CONFIG_UPDATE_PB}" "${CONFIG_UPDATE_JSON}" 67 68 bigMsg "Generating config update envelope" 69 70 wrapConfigEnvelope "${CONFIG_UPDATE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_JSON}" 71 72 bigMsg "Encoding config update envelope" 73 74 encode common.Envelope "${CONFIG_UPDATE_IN_ENVELOPE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_PB}" 75 76 bigMsg "Sending config update to channel" 77 78 updateConfig ${CHANNEL} "${CONFIG_UPDATE_IN_ENVELOPE_PB}" 79 80 bigMsg "Config Update Successful!"