mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-26 19:45:10 +00:00
If the path of the project contains spaces, the "test-network/scripts/envVar.sh" script sets the value of "$ORDERER_CA" to a value containg "${PWD}" which, in turn, contains space(s).
When the variable used in "test-network/scripts/createChannel.sh", The first part of the value (before the first space) is handled as the whole value for "--cafile". Other parts are considered to be part of the command!
I tried putting (escaped) quotes in the "test-network/scripts/envVar.sh" definition for the variable "$ORDERER_CA" to make the fix more general, but the quotation marks were sometime interpreted to be part of the path that consisted of concatenated parts somewhere and it did not work.
While this edit will fix this issue, I belive this is just a work around. I expect that there is a better way to solve the root cause of the problem instead of just fixing it in one place. Moreover, All variables/paths that may include spaces should be properly handled as well.
Thanks
Signed-off-by: Waleed Mortaja <waleedmortaja@protonmail.com>
98 lines
2.3 KiB
Bash
Executable file
98 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# imports
|
|
. scripts/envVar.sh
|
|
. scripts/utils.sh
|
|
|
|
CHANNEL_NAME="$1"
|
|
DELAY="$2"
|
|
MAX_RETRY="$3"
|
|
VERBOSE="$4"
|
|
: ${CHANNEL_NAME:="mychannel"}
|
|
: ${DELAY:="3"}
|
|
: ${MAX_RETRY:="5"}
|
|
: ${VERBOSE:="false"}
|
|
|
|
if [ ! -d "channel-artifacts" ]; then
|
|
mkdir channel-artifacts
|
|
fi
|
|
|
|
createChannelTx() {
|
|
set -x
|
|
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/${CHANNEL_NAME}.tx -channelID $CHANNEL_NAME
|
|
res=$?
|
|
{ set +x; } 2>/dev/null
|
|
verifyResult $res "Failed to generate channel configuration transaction..."
|
|
}
|
|
|
|
createChannel() {
|
|
setGlobals 1
|
|
# Poll in case the raft leader is not set yet
|
|
local rc=1
|
|
local COUNTER=1
|
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
|
sleep $DELAY
|
|
set -x
|
|
peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock $BLOCKFILE --tls --cafile "$ORDERER_CA" >&log.txt
|
|
res=$?
|
|
{ set +x; } 2>/dev/null
|
|
let rc=$res
|
|
COUNTER=$(expr $COUNTER + 1)
|
|
done
|
|
cat log.txt
|
|
verifyResult $res "Channel creation failed"
|
|
}
|
|
|
|
# joinChannel ORG
|
|
joinChannel() {
|
|
FABRIC_CFG_PATH=$PWD/../config/
|
|
ORG=$1
|
|
setGlobals $ORG
|
|
local rc=1
|
|
local COUNTER=1
|
|
## Sometimes Join takes time, hence retry
|
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
|
sleep $DELAY
|
|
set -x
|
|
peer channel join -b $BLOCKFILE >&log.txt
|
|
res=$?
|
|
{ set +x; } 2>/dev/null
|
|
let rc=$res
|
|
COUNTER=$(expr $COUNTER + 1)
|
|
done
|
|
cat log.txt
|
|
verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
|
}
|
|
|
|
setAnchorPeer() {
|
|
ORG=$1
|
|
docker exec cli ./scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME
|
|
}
|
|
|
|
FABRIC_CFG_PATH=${PWD}/configtx
|
|
|
|
## Create channeltx
|
|
infoln "Generating channel create transaction '${CHANNEL_NAME}.tx'"
|
|
createChannelTx
|
|
|
|
FABRIC_CFG_PATH=$PWD/../config/
|
|
BLOCKFILE="./channel-artifacts/${CHANNEL_NAME}.block"
|
|
|
|
## Create channel
|
|
infoln "Creating channel ${CHANNEL_NAME}"
|
|
createChannel
|
|
successln "Channel '$CHANNEL_NAME' created"
|
|
|
|
## Join all the peers to the channel
|
|
infoln "Joining org1 peer to the channel..."
|
|
joinChannel 1
|
|
infoln "Joining org2 peer to the channel..."
|
|
joinChannel 2
|
|
|
|
## Set the anchor peers for each org in the channel
|
|
infoln "Setting anchor peer for org1..."
|
|
setAnchorPeer 1
|
|
infoln "Setting anchor peer for org2..."
|
|
setAnchorPeer 2
|
|
|
|
successln "Channel '$CHANNEL_NAME' joined"
|