fabric-samples/first-network/scripts/step1org3.sh
Arnaud J Le Hors 1d69e9e2d1 [FAB-7540] Simplifies Reconfigure Your Network tutorial
This change brings a new set of scripts and configuration files to the
first-network sample to make it easier for people to follow the new
tutorial on how to add a third org to the network setup in BYFN.

To function properly the new Extend You First Network script (eyfn.sh)
must be run after byfn.sh is run and with the same parameters. So,
valid uses include:

./byfn.sh up
./eyfn.sh up

or

./byfn.sh up -c testchannel -s couchdb -l node
./eyfn.sh up -c testchannel -s couchdb -l node

A single './eyfn.sh down' command is however necessary to take the
whole network down.

Patch-set #2: fixes ./eyfn.sh down
Patch-set #3: removed unused option from Usage and spurious whitespaces
Patch-set #4: added missing test file

Change-Id: I9c926b52f2243dda1c5f9368112c314a6c5c6929
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
2018-02-10 09:36:19 +01:00

91 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# This script is designed to be run in the org3cli container as the
# first step of the EYFN tutorial. It creates and submits a
# configuration transaction to add org3 to the network previously
# setup in the BYFN tutorial.
#
CHANNEL_NAME="$1"
DELAY="$2"
LANGUAGE="$3"
TIMEOUT="$4"
: ${CHANNEL_NAME:="mychannel"}
: ${DELAY:="3"}
: ${LANGUAGE:="golang"}
: ${TIMEOUT:="10"}
LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]`
COUNTER=1
MAX_RETRY=5
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/"
if [ "$LANGUAGE" = "node" ]; then
CC_SRC_PATH="/opt/gopath/src/github.com/chaincode/chaincode_example02/node/"
fi
echo
echo "========= Creating config transaction to add org3 to network =========== "
echo
echo "Installing and starting configtxlater"
apt-get -y update && apt-get -y install jq
configtxlator start >/dev/null 2>&1 &
CONFIGTXLATOR_URL=http://127.0.0.1:7059
echo "Fetching the most recent configuration block for the channel"
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c ${CHANNEL_NAME} --tls --cafile ${ORDERER_CA}
echo "Creating config transaction adding org3 to the network"
# translate channel configuration block into JSON format
curl -X POST --data-binary @config_block.pb "$CONFIGTXLATOR_URL/protolator/decode/common.Block" | jq . > config_block.json
# strip away all of the encapsulating wrappers
jq .data.data[0].payload.data.config config_block.json > config.json
# append new org to the configuration
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json >& updated_config.json
# translate json config files back to protobuf
curl -X POST --data-binary @config.json "$CONFIGTXLATOR_URL/protolator/encode/common.Config" > config.pb
curl -X POST --data-binary @updated_config.json "$CONFIGTXLATOR_URL/protolator/encode/common.Config" > updated_config.pb
# get delta between old and new configs
curl -X POST -F channel=${CHANNEL_NAME} -F "original=@config.pb" -F "updated=@updated_config.pb" "${CONFIGTXLATOR_URL}/configtxlator/compute/update-from-configs" > org3_update.pb
# translate protobuf delta to json
curl -X POST --data-binary @org3_update.pb "$CONFIGTXLATOR_URL/protolator/decode/common.ConfigUpdate" | jq . > org3_update.json
# wrap delta in an envelope message
echo '{"payload":{"header":{"channel_header":{"channel_id":"'${CHANNEL_NAME}'", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json
# translate json back to protobuf
curl -X POST --data-binary @org3_update_in_envelope.json "$CONFIGTXLATOR_URL/protolator/encode/common.Envelope" > org3_update_in_envelope.pb
echo
echo "========= Config transaction to add org3 to network created ===== "
echo
echo "Signing config transaction"
echo
peer channel signconfigtx -f org3_update_in_envelope.pb
echo
echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= "
echo
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --tls --cafile ${ORDERER_CA}
echo
echo "========= Config transaction to add org3 to network submitted! =========== "
echo
exit 0