2017-12-06 22:30:57 +08:00
|
|
|
#!/bin/bash
|
|
|
|
# Demo to use configtxlator to modify orderer config
|
|
|
|
# Usage: bash test_configtxlator solo|kafka
|
|
|
|
# Configtxlator APIs:
|
2021-03-04 06:06:06 +08:00
|
|
|
# Json -> ProtoBuf: http://$SERVER:$PORT/protolator/encode/<message.Name>
|
|
|
|
# ProtoBuf -> Json: http://$SERVER:$PORT/protolator/decode/<message.Name>
|
|
|
|
# Compute Update: http://$SERVER:$PORT/configtxlator/compute/update-from-configs
|
2017-12-06 22:30:57 +08:00
|
|
|
# <message.Name> could be: common.Block, common.Envelope, common.ConfigEnvelope, common.ConfigUpdateEnvelope, common.Config, common.ConfigUpdate
|
|
|
|
# More details about configtxlator, see http://hlf.readthedocs.io/en/latest/configtxlator.html
|
|
|
|
|
|
|
|
if [ -f ./func.sh ]; then
|
2021-03-04 06:06:06 +08:00
|
|
|
source ./func.sh
|
2017-12-06 22:30:57 +08:00
|
|
|
elif [ -f scripts/func.sh ]; then
|
2021-03-04 06:06:06 +08:00
|
|
|
source scripts/func.sh
|
2017-12-06 22:30:57 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ $# -ne 1 ] && echo_r "Usage: bash test_configtxlator solo|kafka" && exit 1
|
|
|
|
|
|
|
|
MODE=$1
|
|
|
|
|
|
|
|
pushd $MODE/${CHANNEL_ARTIFACTS}
|
|
|
|
|
|
|
|
# Must run `make gen_config` to generate config files first
|
|
|
|
|
|
|
|
echo_b "Clean potential existing container $CTL_CONTAINER"
|
|
|
|
[ "$(docker ps -a | grep $CTL_CONTAINER)" ] && docker rm -f $CTL_CONTAINER
|
|
|
|
|
|
|
|
echo_b "Start configtxlator service in background (listen on port 7059)"
|
|
|
|
docker run \
|
2021-03-04 06:06:06 +08:00
|
|
|
-d -it \
|
|
|
|
--name ${CTL_CONTAINER} \
|
|
|
|
-p 127.0.0.1:7059:7059 \
|
|
|
|
-v ${PWD}:/tmp \
|
|
|
|
-w /tmp \
|
|
|
|
${CTL_IMG} \
|
|
|
|
configtxlator start --port=7059
|
2017-12-06 22:30:57 +08:00
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
2018-09-29 17:44:36 +08:00
|
|
|
echo_b "Convert all block files into json"
|
2019-05-02 17:30:13 +08:00
|
|
|
for block_file in *.block; do
|
2021-03-04 06:06:06 +08:00
|
|
|
configtxlatorDecode "common.Block" ${block_file} ${block_file}.json
|
|
|
|
decode_result=$?
|
|
|
|
#echo_b "Parse payload..."
|
|
|
|
#[ ${decode_result} -eq 0 ] && jq "$PAYLOAD_PATH" ${block_file}.json > ${block_file}_payload.json
|
2017-12-06 22:30:57 +08:00
|
|
|
done
|
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Update the content of orderer genesis file"
|
2019-05-02 17:30:13 +08:00
|
|
|
if [ -f ${ORDERER0_GENESIS_BLOCK} ]; then
|
2021-03-04 06:06:06 +08:00
|
|
|
echo_b "Checking existing Orderer.BatchSize.max_message_count in the genesis json"
|
|
|
|
jq "$MAX_BATCH_SIZE_PATH" ${ORDERER0_GENESIS_BLOCK}.json
|
2017-12-06 22:30:57 +08:00
|
|
|
|
2021-03-04 06:06:06 +08:00
|
|
|
echo_b "Creating new genesis json with updated Orderer.BatchSize.max_message_count"
|
|
|
|
jq "$MAX_BATCH_SIZE_PATH=100" ${ORDERER0_GENESIS_BLOCK}.json >${ORDERER0_GENESIS_BLOCK}_updated.json
|
2017-12-06 22:30:57 +08:00
|
|
|
|
2021-03-04 06:06:06 +08:00
|
|
|
echo_b "Re-Encoding the updated orderer genesis json to block"
|
|
|
|
configtxlatorEncode "common.Block" ${ORDERER0_GENESIS_BLOCK}_updated.json ${ORDERER0_GENESIS_BLOCK}_updated.block
|
2017-12-06 22:30:57 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo_b "Stop configtxlator service"
|
|
|
|
docker rm -f $CTL_CONTAINER
|
|
|
|
|
|
|
|
echo_g "Test configtxlator for $MODE Passed"
|