mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 17:15:10 +00:00
Revert "WIP (#253)"
This reverts commit d5ce443bee.
Signed-off-by: Brett Logan <brett.t.logan@ibm.com>
This commit is contained in:
parent
d5ce443bee
commit
daa732d3d8
9 changed files with 376 additions and 240 deletions
|
|
@ -15,12 +15,6 @@ export PATH=${PWD}/../../bin:${PWD}:$PATH
|
||||||
export FABRIC_CFG_PATH=${PWD}
|
export FABRIC_CFG_PATH=${PWD}
|
||||||
export VERBOSE=false
|
export VERBOSE=false
|
||||||
|
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Print the usage message
|
# Print the usage message
|
||||||
function printHelp () {
|
function printHelp () {
|
||||||
echo "Usage: "
|
echo "Usage: "
|
||||||
|
|
@ -76,8 +70,10 @@ function generateOrg3() {
|
||||||
echo "############ Create Org1 Identities ######################"
|
echo "############ Create Org1 Identities ######################"
|
||||||
echo "##########################################################"
|
echo "##########################################################"
|
||||||
|
|
||||||
execute cryptogen generate --config=org3-crypto.yaml --output="../organizations"
|
set -x
|
||||||
|
cryptogen generate --config=org3-crypto.yaml --output="../organizations"
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
if [ $res -ne 0 ]; then
|
if [ $res -ne 0 ]; then
|
||||||
echo "Failed to generate certificates..."
|
echo "Failed to generate certificates..."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -131,13 +127,15 @@ function generateOrg3Definition() {
|
||||||
echo "##########################################################"
|
echo "##########################################################"
|
||||||
echo "####### Generating Org3 organization definition #########"
|
echo "####### Generating Org3 organization definition #########"
|
||||||
echo "##########################################################"
|
echo "##########################################################"
|
||||||
export FABRIC_CFG_PATH=$PWD
|
export FABRIC_CFG_PATH=$PWD
|
||||||
execute configtxgen -printOrg Org3MSP > ../organizations/peerOrganizations/org3.example.com/org3.json
|
set -x
|
||||||
res=$?
|
configtxgen -printOrg Org3MSP > ../organizations/peerOrganizations/org3.example.com/org3.json
|
||||||
if [ $res -ne 0 ]; then
|
res=$?
|
||||||
echo "Failed to generate Org3 config material..."
|
set +x
|
||||||
exit 1
|
if [ $res -ne 0 ]; then
|
||||||
fi
|
echo "Failed to generate Org3 config material..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function createOrg3 {
|
function createOrg3 {
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Enroll the CA admin"
|
echo "Enroll the CA admin"
|
||||||
echo
|
echo
|
||||||
|
|
@ -14,7 +11,9 @@ function createOrg3 {
|
||||||
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
|
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
|
||||||
# rm -rf $FABRIC_CA_CLIENT_HOME/msp
|
# rm -rf $FABRIC_CA_CLIENT_HOME/msp
|
||||||
|
|
||||||
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:11054 --caname ca-org3 --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://admin:adminpw@localhost:11054 --caname ca-org3 --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
echo 'NodeOUs:
|
echo 'NodeOUs:
|
||||||
Enable: true
|
Enable: true
|
||||||
|
|
@ -34,17 +33,23 @@ function createOrg3 {
|
||||||
echo
|
echo
|
||||||
echo "Register peer0"
|
echo "Register peer0"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client register --caname ca-org3 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org3 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Register user"
|
echo "Register user"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client register --caname ca-org3 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org3 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Register the org admin"
|
echo "Register the org admin"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client register --caname ca-org3 --id.name org3admin --id.secret org3adminpw --id.type admin --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org3 --id.name org3admin --id.secret org3adminpw --id.type admin --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
mkdir -p ../organizations/peerOrganizations/org3.example.com/peers
|
mkdir -p ../organizations/peerOrganizations/org3.example.com/peers
|
||||||
mkdir -p ../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com
|
mkdir -p ../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com
|
||||||
|
|
@ -52,14 +57,18 @@ function createOrg3 {
|
||||||
echo
|
echo
|
||||||
echo "## Generate the peer0 msp"
|
echo "## Generate the peer0 msp"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client enroll -u https://peer0:peer0pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp --csr.hosts peer0.org3.example.com --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://peer0:peer0pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp --csr.hosts peer0.org3.example.com --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp/config.yaml
|
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp/config.yaml
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "## Generate the peer0-tls certificates"
|
echo "## Generate the peer0-tls certificates"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client enroll -u https://peer0:peer0pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls --enrollment.profile tls --csr.hosts peer0.org3.example.com --csr.hosts localhost --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://peer0:peer0pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls --enrollment.profile tls --csr.hosts peer0.org3.example.com --csr.hosts localhost --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
|
|
||||||
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/tlscacerts/* ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/tlscacerts/* ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
||||||
|
|
@ -81,7 +90,9 @@ function createOrg3 {
|
||||||
echo
|
echo
|
||||||
echo "## Generate the user msp"
|
echo "## Generate the user msp"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client enroll -u https://user1:user1pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/users/User1@org3.example.com/msp --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://user1:user1pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/users/User1@org3.example.com/msp --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/users/User1@org3.example.com/msp/config.yaml
|
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/users/User1@org3.example.com/msp/config.yaml
|
||||||
|
|
||||||
|
|
@ -90,7 +101,10 @@ function createOrg3 {
|
||||||
echo
|
echo
|
||||||
echo "## Generate the org admin msp"
|
echo "## Generate the org admin msp"
|
||||||
echo
|
echo
|
||||||
execute fabric-ca-client enroll -u https://org3admin:org3adminpw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://org3admin:org3adminpw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp/config.yaml
|
cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp/config.yaml
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,17 +67,6 @@ function printHelp() {
|
||||||
echo " network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript"
|
echo " network.sh deployCC -ccn mychaincode -ccp ./user/mychaincode -ccv 1 -ccl javascript"
|
||||||
}
|
}
|
||||||
|
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
echo -e "\033[0;32mOutput\033[0m:"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function info() {
|
|
||||||
echo -e "\033[0;33mINFO\033[0m: ${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Obtain CONTAINER_IDS and remove them
|
# Obtain CONTAINER_IDS and remove them
|
||||||
# TODO Might want to make this optional - could clear other containers
|
# TODO Might want to make this optional - could clear other containers
|
||||||
# This function is called when you bring a network down
|
# This function is called when you bring a network down
|
||||||
|
|
@ -200,6 +189,7 @@ function checkPrereqs() {
|
||||||
|
|
||||||
# Create Organziation crypto material using cryptogen or CAs
|
# Create Organziation crypto material using cryptogen or CAs
|
||||||
function createOrgs() {
|
function createOrgs() {
|
||||||
|
|
||||||
if [ -d "organizations/peerOrganizations" ]; then
|
if [ -d "organizations/peerOrganizations" ]; then
|
||||||
rm -Rf organizations/peerOrganizations && rm -Rf organizations/ordererOrganizations
|
rm -Rf organizations/peerOrganizations && rm -Rf organizations/ordererOrganizations
|
||||||
fi
|
fi
|
||||||
|
|
@ -212,63 +202,89 @@ function createOrgs() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
info "Generate certificates using cryptogen tool"
|
echo "##########################################################"
|
||||||
info "Create Org1 Identities"
|
echo "##### Generate certificates using cryptogen tool #########"
|
||||||
|
echo "##########################################################"
|
||||||
|
echo
|
||||||
|
|
||||||
execute cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations"
|
echo "##########################################################"
|
||||||
|
echo "############ Create Org1 Identities ######################"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
|
set -x
|
||||||
|
cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations"
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
if [ $res -ne 0 ]; then
|
if [ $res -ne 0 ]; then
|
||||||
echo $'\e[1;32m'"Failed to generate certificates..."$'\e[0m'
|
echo $'\e[1;32m'"Failed to generate certificates..."$'\e[0m'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
|
|
||||||
info "Create Org2 Identities"
|
echo "##########################################################"
|
||||||
|
echo "############ Create Org2 Identities ######################"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
execute cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations"
|
set -x
|
||||||
|
cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations"
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
if [ $res -ne 0 ]; then
|
if [ $res -ne 0 ]; then
|
||||||
echo $'\e[1;32m'"Failed to generate certificates..."$'\e[0m'
|
echo $'\e[1;32m'"Failed to generate certificates..."$'\e[0m'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
|
|
||||||
info "Create Orderer Org Identities"
|
echo "##########################################################"
|
||||||
|
echo "############ Create Orderer Org Identities ###############"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
execute cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations"
|
set -x
|
||||||
|
cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations"
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
if [ $res -ne 0 ]; then
|
if [ $res -ne 0 ]; then
|
||||||
echo $'\e[1;32m'"Failed to generate certificates..."$'\e[0m'
|
echo $'\e[1;32m'"Failed to generate certificates..."$'\e[0m'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create crypto material using Fabric CAs
|
# Create crypto material using Fabric CAs
|
||||||
if [ "$CRYPTO" == "Certificate Authorities" ]; then
|
if [ "$CRYPTO" == "Certificate Authorities" ]; then
|
||||||
|
|
||||||
echo
|
echo
|
||||||
info "Creating Fabric CA's"
|
echo "##########################################################"
|
||||||
IMAGE_TAG=${CA_IMAGETAG} docker-compose -f "$COMPOSE_FILE_CA" up -d 2>&1
|
echo "##### Generate certificates using Fabric CA's ############"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
|
IMAGE_TAG=${CA_IMAGETAG} docker-compose -f $COMPOSE_FILE_CA up -d 2>&1
|
||||||
|
|
||||||
. organizations/fabric-ca/registerEnroll.sh
|
. organizations/fabric-ca/registerEnroll.sh
|
||||||
|
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
echo
|
echo "##########################################################"
|
||||||
info "Generate certificates using Fabric CA's"
|
echo "############ Create Org1 Identities ######################"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
info "Create Org1 Identities"
|
|
||||||
createOrg1
|
createOrg1
|
||||||
|
|
||||||
info "Create Org2 Identities"
|
echo "##########################################################"
|
||||||
|
echo "############ Create Org2 Identities ######################"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
createOrg2
|
createOrg2
|
||||||
|
|
||||||
info "Create Orderer Org Identities"
|
echo "##########################################################"
|
||||||
|
echo "############ Create Orderer Org Identities ###############"
|
||||||
|
echo "##########################################################"
|
||||||
|
|
||||||
createOrderer
|
createOrderer
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Generate CCP files for Org1 and Org2"
|
|
||||||
./organizations/ccp-generate.sh
|
|
||||||
echo
|
echo
|
||||||
|
echo "Generate CCP files for Org1 and Org2"
|
||||||
|
./organizations/ccp-generate.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
# Once you create the organization crypto material, you need to create the
|
# Once you create the organization crypto material, you need to create the
|
||||||
|
|
@ -299,23 +315,25 @@ function createOrgs() {
|
||||||
|
|
||||||
# Generate orderer system channel genesis block.
|
# Generate orderer system channel genesis block.
|
||||||
function createConsortium() {
|
function createConsortium() {
|
||||||
|
|
||||||
which configtxgen
|
which configtxgen
|
||||||
if [ "$?" -ne 0 ]; then
|
if [ "$?" -ne 0 ]; then
|
||||||
echo "configtxgen tool not found. exiting"
|
echo "configtxgen tool not found. exiting"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Generating Orderer Genesis block"
|
echo "######### Generating Orderer Genesis block ##############"
|
||||||
|
|
||||||
# Note: For some unknown reason (at least for now) the block file can't be
|
# Note: For some unknown reason (at least for now) the block file can't be
|
||||||
# named orderer.genesis.block or the orderer will fail to launch!
|
# named orderer.genesis.block or the orderer will fail to launch!
|
||||||
execute configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
|
set -x
|
||||||
|
configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
if [ $res -ne 0 ]; then
|
if [ $res -ne 0 ]; then
|
||||||
echo $'\e[1;32m'"Failed to generate orderer genesis block..."$'\e[0m'
|
echo $'\e[1;32m'"Failed to generate orderer genesis block..."$'\e[0m'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# After we create the org crypto material and the system channel genesis block,
|
# After we create the org crypto material and the system channel genesis block,
|
||||||
|
|
@ -326,6 +344,7 @@ function createConsortium() {
|
||||||
|
|
||||||
# Bring up the peer and orderer nodes using docker compose.
|
# Bring up the peer and orderer nodes using docker compose.
|
||||||
function networkUp() {
|
function networkUp() {
|
||||||
|
|
||||||
checkPrereqs
|
checkPrereqs
|
||||||
# generate artifacts if they don't exist
|
# generate artifacts if they don't exist
|
||||||
if [ ! -d "organizations/peerOrganizations" ]; then
|
if [ ! -d "organizations/peerOrganizations" ]; then
|
||||||
|
|
@ -350,7 +369,9 @@ function networkUp() {
|
||||||
|
|
||||||
## call the script to join create the channel and join the peers of org1 and org2
|
## call the script to join create the channel and join the peers of org1 and org2
|
||||||
function createChannel() {
|
function createChannel() {
|
||||||
|
|
||||||
## Bring up the network if it is not arleady up.
|
## Bring up the network if it is not arleady up.
|
||||||
|
|
||||||
if [ ! -d "organizations/peerOrganizations" ]; then
|
if [ ! -d "organizations/peerOrganizations" ]; then
|
||||||
echo "Bringing up network"
|
echo "Bringing up network"
|
||||||
networkUp
|
networkUp
|
||||||
|
|
@ -365,17 +386,21 @@ function createChannel() {
|
||||||
echo "Error !!! Create channel failed"
|
echo "Error !!! Create channel failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## Call the script to isntall and instantiate a chaincode on the channel
|
## Call the script to isntall and instantiate a chaincode on the channel
|
||||||
function deployCC() {
|
function deployCC() {
|
||||||
|
|
||||||
scripts/deployCC.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $CC_END_POLICY $CC_COLL_CONFIG $CLI_DELAY $MAX_RETRY $VERBOSE
|
scripts/deployCC.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $CC_END_POLICY $CC_COLL_CONFIG $CLI_DELAY $MAX_RETRY $VERBOSE
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ERROR !!! Deploying chaincode failed"
|
echo "ERROR !!! Deploying chaincode failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,19 @@
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function info() {
|
|
||||||
echo -e "\033[0;33mINFO\033[0m: ${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function createOrg1 {
|
function createOrg1 {
|
||||||
info "Enroll the CA admin"
|
|
||||||
|
echo
|
||||||
|
echo "Enroll the CA admin"
|
||||||
|
echo
|
||||||
mkdir -p organizations/peerOrganizations/org1.example.com/
|
mkdir -p organizations/peerOrganizations/org1.example.com/
|
||||||
|
|
||||||
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org1.example.com/
|
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org1.example.com/
|
||||||
|
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
|
||||||
|
# rm -rf $FABRIC_CA_CLIENT_HOME/msp
|
||||||
|
|
||||||
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:7054 --caname ca-org1 --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
set -x
|
||||||
echo
|
fabric-ca-client enroll -u https://admin:adminpw@localhost:7054 --caname ca-org1 --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
echo 'NodeOUs:
|
echo 'NodeOUs:
|
||||||
Enable: true
|
Enable: true
|
||||||
|
|
@ -32,30 +30,46 @@ function createOrg1 {
|
||||||
Certificate: cacerts/localhost-7054-ca-org1.pem
|
Certificate: cacerts/localhost-7054-ca-org1.pem
|
||||||
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml
|
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml
|
||||||
|
|
||||||
info "Register peer0"
|
|
||||||
execute fabric-ca-client register --caname ca-org1 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register peer0"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org1 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
info "Register user"
|
|
||||||
execute fabric-ca-client register --caname ca-org1 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register user"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org1 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
info "Register the org admin"
|
|
||||||
execute fabric-ca-client register --caname ca-org1 --id.name org1admin --id.secret org1adminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register the org admin"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org1 --id.name org1admin --id.secret org1adminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
mkdir -p organizations/peerOrganizations/org1.example.com/peers
|
mkdir -p organizations/peerOrganizations/org1.example.com/peers
|
||||||
mkdir -p organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com
|
mkdir -p organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com
|
||||||
|
|
||||||
info "Generate the peer0 msp"
|
|
||||||
execute fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp --csr.hosts peer0.org1.example.com --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the peer0 msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp --csr.hosts peer0.org1.example.com --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/config.yaml
|
cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/config.yaml
|
||||||
|
|
||||||
info "Generate the peer0-tls certificates"
|
|
||||||
execute fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls --enrollment.profile tls --csr.hosts peer0.org1.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the peer0-tls certificates"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls --enrollment.profile tls --csr.hosts peer0.org1.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
||||||
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/signcerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
|
cp ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/signcerts/* ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
|
||||||
|
|
@ -73,30 +87,43 @@ function createOrg1 {
|
||||||
mkdir -p organizations/peerOrganizations/org1.example.com/users
|
mkdir -p organizations/peerOrganizations/org1.example.com/users
|
||||||
mkdir -p organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com
|
mkdir -p organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com
|
||||||
|
|
||||||
info "Generate the user msp"
|
|
||||||
execute fabric-ca-client enroll -u https://user1:user1pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the user msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://user1:user1pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/config.yaml
|
cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/config.yaml
|
||||||
|
|
||||||
mkdir -p organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com
|
mkdir -p organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com
|
||||||
|
|
||||||
info "Generate the org admin msp"
|
|
||||||
execute fabric-ca-client enroll -u https://org1admin:org1adminpw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the org admin msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://org1admin:org1adminpw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml
|
cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function createOrg2 {
|
function createOrg2 {
|
||||||
info "Enroll the CA admin"
|
|
||||||
|
echo
|
||||||
|
echo "Enroll the CA admin"
|
||||||
|
echo
|
||||||
mkdir -p organizations/peerOrganizations/org2.example.com/
|
mkdir -p organizations/peerOrganizations/org2.example.com/
|
||||||
|
|
||||||
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org2.example.com/
|
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org2.example.com/
|
||||||
|
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
|
||||||
|
# rm -rf $FABRIC_CA_CLIENT_HOME/msp
|
||||||
|
|
||||||
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:8054 --caname ca-org2 --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
set -x
|
||||||
echo
|
fabric-ca-client enroll -u https://admin:adminpw@localhost:8054 --caname ca-org2 --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
echo 'NodeOUs:
|
echo 'NodeOUs:
|
||||||
Enable: true
|
Enable: true
|
||||||
|
|
@ -113,30 +140,46 @@ function createOrg2 {
|
||||||
Certificate: cacerts/localhost-8054-ca-org2.pem
|
Certificate: cacerts/localhost-8054-ca-org2.pem
|
||||||
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml
|
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml
|
||||||
|
|
||||||
info "Register peer0"
|
|
||||||
execute fabric-ca-client register --caname ca-org2 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register peer0"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org2 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
info "Register user"
|
|
||||||
execute fabric-ca-client register --caname ca-org2 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register user"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org2 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
info "Register the org admin"
|
|
||||||
execute fabric-ca-client register --caname ca-org2 --id.name org2admin --id.secret org2adminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register the org admin"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-org2 --id.name org2admin --id.secret org2adminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
mkdir -p organizations/peerOrganizations/org2.example.com/peers
|
mkdir -p organizations/peerOrganizations/org2.example.com/peers
|
||||||
mkdir -p organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com
|
mkdir -p organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com
|
||||||
|
|
||||||
info "Generate the peer0 msp"
|
|
||||||
execute fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp --csr.hosts peer0.org2.example.com --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the peer0 msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp --csr.hosts peer0.org2.example.com --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/config.yaml
|
cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/config.yaml
|
||||||
|
|
||||||
info "Generate the peer0-tls certificates"
|
|
||||||
execute fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls --enrollment.profile tls --csr.hosts peer0.org2.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the peer0-tls certificates"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls --enrollment.profile tls --csr.hosts peer0.org2.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/tlscacerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||||
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/signcerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
|
cp ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/signcerts/* ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt
|
||||||
|
|
@ -154,29 +197,42 @@ function createOrg2 {
|
||||||
mkdir -p organizations/peerOrganizations/org2.example.com/users
|
mkdir -p organizations/peerOrganizations/org2.example.com/users
|
||||||
mkdir -p organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com
|
mkdir -p organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com
|
||||||
|
|
||||||
info "Generate the user msp"
|
|
||||||
execute fabric-ca-client enroll -u https://user1:user1pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the user msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://user1:user1pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/config.yaml
|
cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/config.yaml
|
||||||
|
|
||||||
mkdir -p organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com
|
mkdir -p organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com
|
||||||
|
|
||||||
info "Generate the org admin msp"
|
|
||||||
execute fabric-ca-client enroll -u https://org2admin:org2adminpw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the org admin msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://org2admin:org2adminpw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/config.yaml
|
cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/config.yaml
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOrderer {
|
function createOrderer {
|
||||||
info "Enroll the CA admin"
|
|
||||||
|
echo
|
||||||
|
echo "Enroll the CA admin"
|
||||||
|
echo
|
||||||
mkdir -p organizations/ordererOrganizations/example.com
|
mkdir -p organizations/ordererOrganizations/example.com
|
||||||
|
|
||||||
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/ordererOrganizations/example.com
|
export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/ordererOrganizations/example.com
|
||||||
|
# rm -rf $FABRIC_CA_CLIENT_HOME/fabric-ca-client-config.yaml
|
||||||
|
# rm -rf $FABRIC_CA_CLIENT_HOME/msp
|
||||||
|
|
||||||
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:9054 --caname ca-orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
set -x
|
||||||
echo
|
fabric-ca-client enroll -u https://admin:adminpw@localhost:9054 --caname ca-orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
echo 'NodeOUs:
|
echo 'NodeOUs:
|
||||||
Enable: true
|
Enable: true
|
||||||
|
|
@ -193,27 +249,41 @@ function createOrderer {
|
||||||
Certificate: cacerts/localhost-9054-ca-orderer.pem
|
Certificate: cacerts/localhost-9054-ca-orderer.pem
|
||||||
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml
|
OrganizationalUnitIdentifier: orderer' > ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml
|
||||||
|
|
||||||
info "Register orderer"
|
|
||||||
execute fabric-ca-client register --caname ca-orderer --id.name orderer --id.secret ordererpw --id.type orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
|
||||||
echo
|
|
||||||
|
|
||||||
info "Register the orderer admin"
|
|
||||||
execute fabric-ca-client register --caname ca-orderer --id.name ordererAdmin --id.secret ordererAdminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "Register orderer"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-orderer --id.name orderer --id.secret ordererpw --id.type orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Register the orderer admin"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client register --caname ca-orderer --id.name ordererAdmin --id.secret ordererAdminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
mkdir -p organizations/ordererOrganizations/example.com/orderers
|
mkdir -p organizations/ordererOrganizations/example.com/orderers
|
||||||
mkdir -p organizations/ordererOrganizations/example.com/orderers/example.com
|
mkdir -p organizations/ordererOrganizations/example.com/orderers/example.com
|
||||||
|
|
||||||
mkdir -p organizations/ordererOrganizations/example.com/orderers/orderer.example.com
|
mkdir -p organizations/ordererOrganizations/example.com/orderers/orderer.example.com
|
||||||
|
|
||||||
info "Generate the orderer msp"
|
|
||||||
execute fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the orderer msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/config.yaml
|
cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/config.yaml
|
||||||
|
|
||||||
info "Generate the orderer-tls certificates"
|
|
||||||
execute fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls --enrollment.profile tls --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the orderer-tls certificates"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls --enrollment.profile tls --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/tlscacerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/tlscacerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt
|
||||||
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/signcerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
|
cp ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/signcerts/* ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
|
||||||
|
|
@ -228,9 +298,14 @@ function createOrderer {
|
||||||
mkdir -p organizations/ordererOrganizations/example.com/users
|
mkdir -p organizations/ordererOrganizations/example.com/users
|
||||||
mkdir -p organizations/ordererOrganizations/example.com/users/Admin@example.com
|
mkdir -p organizations/ordererOrganizations/example.com/users/Admin@example.com
|
||||||
|
|
||||||
info "Generate the admin msp"
|
|
||||||
execute fabric-ca-client enroll -u https://ordererAdmin:ordererAdminpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
|
||||||
echo
|
echo
|
||||||
|
echo "## Generate the admin msp"
|
||||||
|
echo
|
||||||
|
set -x
|
||||||
|
fabric-ca-client enroll -u https://ordererAdmin:ordererAdminpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
|
||||||
|
set +x
|
||||||
|
|
||||||
cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp/config.yaml
|
cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp/config.yaml
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,41 +13,38 @@ VERBOSE="$4"
|
||||||
# import utils
|
# import utils
|
||||||
. scripts/envVar.sh
|
. scripts/envVar.sh
|
||||||
|
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
echo -e "\033[0;32mOutput\033[0m:"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function info() {
|
|
||||||
echo -e "\033[0;33mINFO\033[0m: ${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ ! -d "channel-artifacts" ]; then
|
if [ ! -d "channel-artifacts" ]; then
|
||||||
mkdir channel-artifacts
|
mkdir channel-artifacts
|
||||||
fi
|
fi
|
||||||
|
|
||||||
createChannelTx() {
|
createChannelTx() {
|
||||||
execute configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/${CHANNEL_NAME}.tx -channelID $CHANNEL_NAME
|
|
||||||
|
set -x
|
||||||
|
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/${CHANNEL_NAME}.tx -channelID $CHANNEL_NAME
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
if [ $res -ne 0 ]; then
|
if [ $res -ne 0 ]; then
|
||||||
echo "Failed to generate channel configuration transaction..."
|
echo "Failed to generate channel configuration transaction..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createAncorPeerTx() {
|
createAncorPeerTx() {
|
||||||
|
|
||||||
for orgmsp in Org1MSP Org2MSP; do
|
for orgmsp in Org1MSP Org2MSP; do
|
||||||
info "Generating anchor peer update transaction for ${orgmsp}"
|
|
||||||
execute configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID $CHANNEL_NAME -asOrg ${orgmsp}
|
echo "####### Generating anchor peer update transaction for ${orgmsp} ##########"
|
||||||
res=$?
|
set -x
|
||||||
if [ $res -ne 0 ]; then
|
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID $CHANNEL_NAME -asOrg ${orgmsp}
|
||||||
echo "Failed to generate anchor peer update transaction for ${orgmsp}..."
|
res=$?
|
||||||
exit 1
|
set +x
|
||||||
fi
|
if [ $res -ne 0 ]; then
|
||||||
echo
|
echo "Failed to generate anchor peer update transaction for ${orgmsp}..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,14 +55,17 @@ createChannel() {
|
||||||
local COUNTER=1
|
local COUNTER=1
|
||||||
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
execute peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock ./channel-artifacts/${CHANNEL_NAME}.block --tls --cafile $ORDERER_CA >&log.txt
|
set -x
|
||||||
|
peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock ./channel-artifacts/${CHANNEL_NAME}.block --tls --cafile $ORDERER_CA >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
let rc=$res
|
let rc=$res
|
||||||
COUNTER=$(expr $COUNTER + 1)
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
done
|
done
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Channel creation failed"
|
verifyResult $res "Channel creation failed"
|
||||||
info "Channel ${CHANNEL_NAME} created"
|
echo
|
||||||
|
echo "===================== Channel '$CHANNEL_NAME' created ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,16 +76,18 @@ joinChannel() {
|
||||||
local rc=1
|
local rc=1
|
||||||
local COUNTER=1
|
local COUNTER=1
|
||||||
## Sometimes Join takes time, hence retry
|
## Sometimes Join takes time, hence retry
|
||||||
while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ] ; do
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
execute peer channel join -b ./channel-artifacts/$CHANNEL_NAME.block >&log.txt
|
set -x
|
||||||
|
peer channel join -b ./channel-artifacts/$CHANNEL_NAME.block >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
let rc=$res
|
let rc=$res
|
||||||
COUNTER=$((COUNTER + 1))
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
done
|
done
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
|
||||||
echo
|
echo
|
||||||
|
verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAnchorPeers() {
|
updateAnchorPeers() {
|
||||||
|
|
@ -96,21 +98,23 @@ updateAnchorPeers() {
|
||||||
## Sometimes Join takes time, hence retry
|
## Sometimes Join takes time, hence retry
|
||||||
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
execute peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA >&log.txt
|
set -x
|
||||||
|
peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
let rc=$res
|
let rc=$res
|
||||||
COUNTER=$(expr $COUNTER + 1)
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
done
|
done
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Anchor peer update failed"
|
verifyResult $res "Anchor peer update failed"
|
||||||
info "Anchor peers updated for org ${CORE_PEER_LOCALMSPID} on channel ${CHANNEL_NAME}"
|
echo "===================== Anchor peers updated for org '$CORE_PEER_LOCALMSPID' on channel '$CHANNEL_NAME' ===================== "
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyResult() {
|
verifyResult() {
|
||||||
if [ $1 -ne 0 ]; then
|
if [ $1 -ne 0 ]; then
|
||||||
echo "!!!!!!!!!!!!!!! ${2} !!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -119,30 +123,33 @@ verifyResult() {
|
||||||
FABRIC_CFG_PATH=${PWD}/configtx
|
FABRIC_CFG_PATH=${PWD}/configtx
|
||||||
|
|
||||||
## Create channeltx
|
## Create channeltx
|
||||||
echo
|
echo "### Generating channel create transaction '${CHANNEL_NAME}.tx' ###"
|
||||||
info "Generating channel create transaction ${CHANNEL_NAME}.tx"
|
|
||||||
createChannelTx
|
createChannelTx
|
||||||
|
|
||||||
## Create anchorpeertx
|
## Create anchorpeertx
|
||||||
info "Generating anchor peer update transactions"
|
echo "### Generating anchor peer update transactions ###"
|
||||||
createAncorPeerTx
|
createAncorPeerTx
|
||||||
|
|
||||||
FABRIC_CFG_PATH=$PWD/../config/
|
FABRIC_CFG_PATH=$PWD/../config/
|
||||||
|
|
||||||
## Create channel
|
## Create channel
|
||||||
info "Creating channel ${CHANNEL_NAME}"
|
echo "Creating channel "$CHANNEL_NAME
|
||||||
createChannel
|
createChannel
|
||||||
|
|
||||||
## Join all the peers to the channel
|
## Join all the peers to the channel
|
||||||
info "Join Org1 peers to the channel"
|
echo "Join Org1 peers to the channel..."
|
||||||
joinChannel 1
|
joinChannel 1
|
||||||
info "Join Org2 peers to the channel"
|
echo "Join Org2 peers to the channel..."
|
||||||
joinChannel 2
|
joinChannel 2
|
||||||
|
|
||||||
## Set the anchor peers for each org in the channel
|
## Set the anchor peers for each org in the channel
|
||||||
info "Updating anchor peers for org1"
|
echo "Updating anchor peers for org1..."
|
||||||
updateAnchorPeers 1
|
updateAnchorPeers 1
|
||||||
info "Updating anchor peers for org2"
|
echo "Updating anchor peers for org2..."
|
||||||
updateAnchorPeers 2
|
updateAnchorPeers 2
|
||||||
|
|
||||||
info "Channel successfully joined"
|
echo
|
||||||
|
echo "========= Channel successfully joined =========== "
|
||||||
|
echo
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -29,22 +29,12 @@ CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
|
||||||
|
|
||||||
FABRIC_CFG_PATH=$PWD/../config/
|
FABRIC_CFG_PATH=$PWD/../config/
|
||||||
|
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
echo -e "\033[0;32mOutput\033[0m:"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function info() {
|
|
||||||
echo -e "\033[0;33mINFO\033[0m: ${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# User has not provided a path, therefore the CC_NAME must
|
# User has not provided a path, therefore the CC_NAME must
|
||||||
# be the short name of a known chaincode sample
|
# be the short name of a known chaincode sample
|
||||||
echo
|
|
||||||
if [ "$CC_SRC_PATH" = "NA" ]; then
|
if [ "$CC_SRC_PATH" = "NA" ]; then
|
||||||
info "Determining the path to the chaincode"
|
echo Determining the path to the chaincode
|
||||||
# first see which chaincode we have. This will be based on the
|
# first see which chaincode we have. This will be based on the
|
||||||
# short name of the known chaincode sample
|
# short name of the known chaincode sample
|
||||||
if [ "$CC_NAME" = "basic" ]; then
|
if [ "$CC_NAME" = "basic" ]; then
|
||||||
|
|
@ -87,26 +77,25 @@ elif [ ! -d "$CC_SRC_PATH" ]; then
|
||||||
echo Path to chaincode does not exist. Please provide different path
|
echo Path to chaincode does not exist. Please provide different path
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
|
|
||||||
# do some language specific preparation to the chaincode before packaging
|
# do some language specific preparation to the chaincode before packaging
|
||||||
if [ "$CC_SRC_LANGUAGE" = "go" ]; then
|
if [ "$CC_SRC_LANGUAGE" = "go" ]; then
|
||||||
CC_RUNTIME_LANGUAGE=golang
|
CC_RUNTIME_LANGUAGE=golang
|
||||||
|
|
||||||
info "Vendoring Go dependencies at ${CC_SRC_PATH}"
|
echo Vendoring Go dependencies at $CC_SRC_PATH
|
||||||
pushd $CC_SRC_PATH
|
pushd $CC_SRC_PATH
|
||||||
GO111MODULE=on go mod vendor
|
GO111MODULE=on go mod vendor
|
||||||
popd
|
popd
|
||||||
info "Finished vendoring Go dependencies"
|
echo Finished vendoring Go dependencies
|
||||||
|
|
||||||
elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
|
elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
|
||||||
CC_RUNTIME_LANGUAGE=java
|
CC_RUNTIME_LANGUAGE=java
|
||||||
|
|
||||||
info "Compiling Java code"
|
echo Compiling Java code ...
|
||||||
pushd $CC_SRC_PATH
|
pushd $CC_SRC_PATH
|
||||||
./gradlew installDist
|
./gradlew installDist
|
||||||
popd
|
popd
|
||||||
info "Finished compiling Java code"
|
echo Finished compiling Java code
|
||||||
CC_SRC_PATH=$CC_SRC_PATH/build/install/$CC_NAME
|
CC_SRC_PATH=$CC_SRC_PATH/build/install/$CC_NAME
|
||||||
|
|
||||||
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
||||||
|
|
@ -115,12 +104,12 @@ elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
|
||||||
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
||||||
CC_RUNTIME_LANGUAGE=node
|
CC_RUNTIME_LANGUAGE=node
|
||||||
|
|
||||||
info "Compiling TypeScript code into JavaScript"
|
echo Compiling TypeScript code into JavaScript ...
|
||||||
pushd $CC_SRC_PATH
|
pushd $CC_SRC_PATH
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
popd
|
popd
|
||||||
info "Finished compiling TypeScript code into JavaScript"
|
echo Finished compiling TypeScript code into JavaScript
|
||||||
|
|
||||||
else
|
else
|
||||||
echo The chaincode language ${CC_SRC_LANGUAGE} is not supported by this script
|
echo The chaincode language ${CC_SRC_LANGUAGE} is not supported by this script
|
||||||
|
|
@ -146,6 +135,11 @@ else
|
||||||
CC_COLL_CONFIG="--collections-config $CC_COLL_CONFIG"
|
CC_COLL_CONFIG="--collections-config $CC_COLL_CONFIG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#if [ "$CC_INIT_FCN" = "NA" ]; then
|
||||||
|
# INIT_REQUIRED=""
|
||||||
|
#fi
|
||||||
|
|
||||||
# import utils
|
# import utils
|
||||||
. scripts/envVar.sh
|
. scripts/envVar.sh
|
||||||
|
|
||||||
|
|
@ -153,11 +147,13 @@ fi
|
||||||
packageChaincode() {
|
packageChaincode() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
execute peer lifecycle chaincode package ${CC_NAME}.tar.gz --path ${CC_SRC_PATH} --lang ${CC_RUNTIME_LANGUAGE} --label ${CC_NAME}_${CC_VERSION} >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode package ${CC_NAME}.tar.gz --path ${CC_SRC_PATH} --lang ${CC_RUNTIME_LANGUAGE} --label ${CC_NAME}_${CC_VERSION} >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Chaincode packaging on peer0.org${ORG} has failed"
|
verifyResult $res "Chaincode packaging on peer0.org${ORG} has failed"
|
||||||
info " Chaincode is packaged on peer0.org${ORG}"
|
echo "===================== Chaincode is packaged on peer0.org${ORG} ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,11 +161,13 @@ packageChaincode() {
|
||||||
installChaincode() {
|
installChaincode() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
execute peer lifecycle chaincode install ${CC_NAME}.tar.gz >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode install ${CC_NAME}.tar.gz >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Chaincode installation on peer0.org${ORG} has failed"
|
verifyResult $res "Chaincode installation on peer0.org${ORG} has failed"
|
||||||
info "Chaincode is installed on peer0.org${ORG}"
|
echo "===================== Chaincode is installed on peer0.org${ORG} ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,12 +175,14 @@ installChaincode() {
|
||||||
queryInstalled() {
|
queryInstalled() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
execute peer lifecycle chaincode queryinstalled >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode queryinstalled >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
PACKAGE_ID=$(sed -n "/${CC_NAME}_${CC_VERSION}/{s/^Package ID: //; s/, Label:.*$//; p;}" log.txt)
|
PACKAGE_ID=$(sed -n "/${CC_NAME}_${CC_VERSION}/{s/^Package ID: //; s/, Label:.*$//; p;}" log.txt)
|
||||||
verifyResult $res "Query installed on peer0.org${ORG} has failed"
|
verifyResult $res "Query installed on peer0.org${ORG} has failed"
|
||||||
info "Query installed successful on peer0.org${ORG} on channel"
|
echo "===================== Query installed successful on peer0.org${ORG} on channel ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,10 +190,12 @@ queryInstalled() {
|
||||||
approveForMyOrg() {
|
approveForMyOrg() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
execute peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} --version ${CC_VERSION} --package-id ${PACKAGE_ID} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} ${CC_END_POLICY} ${CC_COLL_CONFIG} >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} --version ${CC_VERSION} --package-id ${PACKAGE_ID} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} ${CC_END_POLICY} ${CC_COLL_CONFIG} >&log.txt
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Chaincode definition approved on peer0.org${ORG} on channel '$CHANNEL_NAME' failed"
|
verifyResult $res "Chaincode definition approved on peer0.org${ORG} on channel '$CHANNEL_NAME' failed"
|
||||||
info "Chaincode definition approved on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Chaincode definition approved on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,16 +204,18 @@ checkCommitReadiness() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
shift 1
|
shift 1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
info "Checking the commit readiness of the chaincode definition on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Checking the commit readiness of the chaincode definition on peer0.org${ORG} on channel '$CHANNEL_NAME'... ===================== "
|
||||||
local rc=1
|
local rc=1
|
||||||
local COUNTER=1
|
local COUNTER=1
|
||||||
# continue to poll
|
# continue to poll
|
||||||
# we either get a successful response, or reach MAX RETRY
|
# we either get a successful response, or reach MAX RETRY
|
||||||
while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ]; do
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ]; do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
info "Checking the commit readiness of the chaincode definition on peer0.org${ORG}, Retry after ${DELAY} seconds"
|
echo "Attempting to check the commit readiness of the chaincode definition on peer0.org${ORG}, Retry after $DELAY seconds."
|
||||||
execute peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME --name ${CC_NAME} --version ${CC_VERSION} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} ${CC_END_POLICY} ${CC_COLL_CONFIG} --output json >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME --name ${CC_NAME} --version ${CC_VERSION} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} ${CC_END_POLICY} ${CC_COLL_CONFIG} --output json >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
let rc=0
|
let rc=0
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
grep "$var" log.txt &>/dev/null || let rc=1
|
grep "$var" log.txt &>/dev/null || let rc=1
|
||||||
|
|
@ -220,30 +224,31 @@ checkCommitReadiness() {
|
||||||
done
|
done
|
||||||
cat log.txt
|
cat log.txt
|
||||||
if test $rc -eq 0; then
|
if test $rc -eq 0; then
|
||||||
info "Checking the commit readiness of the chaincode definition successful on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Checking the commit readiness of the chaincode definition successful on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== "
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
echo $'\e[1;31m'"!!!!!!!!!!!!!!! After $MAX_RETRY attempts, Check commit readiness result on peer0.org${ORG} is INVALID !!!!!!!!!!!!!!!!"$'\e[0m'
|
echo $'\e[1;31m'"!!!!!!!!!!!!!!! After $MAX_RETRY attempts, Check commit readiness result on peer0.org${ORG} is INVALID !!!!!!!!!!!!!!!!"$'\e[0m'
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# commitChaincodeDefinition VERSION PEER ORG (PEER ORG)...
|
# commitChaincodeDefinition VERSION PEER ORG (PEER ORG)...
|
||||||
commitChaincodeDefinition() {
|
commitChaincodeDefinition() {
|
||||||
parsePeerConnectionParameters "$@"
|
parsePeerConnectionParameters $@
|
||||||
res=$?
|
res=$?
|
||||||
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
|
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
|
||||||
|
|
||||||
# while 'peer chaincode' command can get the orderer endpoint from the
|
# while 'peer chaincode' command can get the orderer endpoint from the
|
||||||
# peer (if join was successful), let's supply it directly as we know
|
# peer (if join was successful), let's supply it directly as we know
|
||||||
# it using the "-o" option
|
# it using the "-o" option
|
||||||
execute peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} $PEER_CONN_PARMS --version ${CC_VERSION} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} ${CC_END_POLICY} ${CC_COLL_CONFIG} >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} $PEER_CONN_PARMS --version ${CC_VERSION} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} ${CC_END_POLICY} ${CC_COLL_CONFIG} >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Chaincode definition commit failed on peer0.org${ORG} on channel '$CHANNEL_NAME' failed"
|
verifyResult $res "Chaincode definition commit failed on peer0.org${ORG} on channel '$CHANNEL_NAME' failed"
|
||||||
info "Chaincode definition committed on channel '${CHANNEL_NAME}"
|
echo "===================== Chaincode definition committed on channel '$CHANNEL_NAME' ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,16 +257,18 @@ queryCommitted() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
EXPECTED_RESULT="Version: ${CC_VERSION}, Sequence: ${CC_SEQUENCE}, Endorsement Plugin: escc, Validation Plugin: vscc"
|
EXPECTED_RESULT="Version: ${CC_VERSION}, Sequence: ${CC_SEQUENCE}, Endorsement Plugin: escc, Validation Plugin: vscc"
|
||||||
info "Querying chaincode definition on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Querying chaincode definition on peer0.org${ORG} on channel '$CHANNEL_NAME'... ===================== "
|
||||||
local rc=1
|
local rc=1
|
||||||
local COUNTER=1
|
local COUNTER=1
|
||||||
# continue to poll
|
# continue to poll
|
||||||
# we either get a successful response, or reach MAX RETRY
|
# we either get a successful response, or reach MAX RETRY
|
||||||
while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ]; do
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ]; do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
info "Attempting to Query committed status on peer0.org${ORG}, Retry after ${DELAY} seconds."
|
echo "Attempting to Query committed status on peer0.org${ORG}, Retry after $DELAY seconds."
|
||||||
execute peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name ${CC_NAME} >&log.txt
|
set -x
|
||||||
|
peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name ${CC_NAME} >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
test $res -eq 0 && VALUE=$(cat log.txt | grep -o '^Version: '$CC_VERSION', Sequence: [0-9], Endorsement Plugin: escc, Validation Plugin: vscc')
|
test $res -eq 0 && VALUE=$(cat log.txt | grep -o '^Version: '$CC_VERSION', Sequence: [0-9], Endorsement Plugin: escc, Validation Plugin: vscc')
|
||||||
test "$VALUE" = "$EXPECTED_RESULT" && let rc=0
|
test "$VALUE" = "$EXPECTED_RESULT" && let rc=0
|
||||||
COUNTER=$(expr $COUNTER + 1)
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
|
|
@ -269,70 +276,74 @@ queryCommitted() {
|
||||||
echo
|
echo
|
||||||
cat log.txt
|
cat log.txt
|
||||||
if test $rc -eq 0; then
|
if test $rc -eq 0; then
|
||||||
info "Query chaincode definition successful on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Query chaincode definition successful on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== "
|
||||||
|
echo
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
echo $'\e[1;31m'"!!!!!!!!!!!!!!! After $MAX_RETRY attempts, Query chaincode definition result on peer0.org${ORG} is INVALID !!!!!!!!!!!!!!!!"$'\e[0m'
|
echo $'\e[1;31m'"!!!!!!!!!!!!!!! After $MAX_RETRY attempts, Query chaincode definition result on peer0.org${ORG} is INVALID !!!!!!!!!!!!!!!!"$'\e[0m'
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chaincodeInvokeInit() {
|
chaincodeInvokeInit() {
|
||||||
parsePeerConnectionParameters "$@"
|
parsePeerConnectionParameters $@
|
||||||
res=$?
|
res=$?
|
||||||
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
|
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
|
||||||
|
|
||||||
# while 'peer chaincode' command can get the orderer endpoint from the
|
# while 'peer chaincode' command can get the orderer endpoint from the
|
||||||
# peer (if join was successful), let's supply it directly as we know
|
# peer (if join was successful), let's supply it directly as we know
|
||||||
# it using the "-o" option
|
# it using the "-o" option
|
||||||
|
set -x
|
||||||
fcn_call='{"function":"'${CC_INIT_FCN}'","Args":[]}'
|
fcn_call='{"function":"'${CC_INIT_FCN}'","Args":[]}'
|
||||||
info "invoke fcn call:${fcn_call}"
|
echo invoke fcn call:${fcn_call}
|
||||||
execute peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA -C $CHANNEL_NAME -n ${CC_NAME} $PEER_CONN_PARMS --isInit -c ${fcn_call} >&log.txt
|
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile $ORDERER_CA -C $CHANNEL_NAME -n ${CC_NAME} $PEER_CONN_PARMS --isInit -c ${fcn_call} >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Invoke execution on $PEERS failed "
|
verifyResult $res "Invoke execution on $PEERS failed "
|
||||||
info "Invoke transaction successful on $PEERS on channel ${CHANNEL_NAME}"
|
echo "===================== Invoke transaction successful on $PEERS on channel '$CHANNEL_NAME' ===================== "
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
chaincodeQuery() {
|
chaincodeQuery() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
info "Querying on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Querying on peer0.org${ORG} on channel '$CHANNEL_NAME'... ===================== "
|
||||||
local rc=1
|
local rc=1
|
||||||
local COUNTER=1
|
local COUNTER=1
|
||||||
# continue to poll
|
# continue to poll
|
||||||
# we either get a successful response, or reach MAX RETRY
|
# we either get a successful response, or reach MAX RETRY
|
||||||
while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ]; do
|
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ]; do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
info "Attempting to Query peer0.org${ORG}, Retry after ${DELAY} seconds."
|
echo "Attempting to Query peer0.org${ORG}, Retry after $DELAY seconds."
|
||||||
execute peer chaincode query -C $CHANNEL_NAME -n ${CC_NAME} -c '{"Args":["queryAllCars"]}' >&log.txt
|
set -x
|
||||||
|
peer chaincode query -C $CHANNEL_NAME -n ${CC_NAME} -c '{"Args":["queryAllCars"]}' >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
let rc=$res
|
let rc=$res
|
||||||
COUNTER=$((COUNTER + 1))
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
cat log.txt
|
cat log.txt
|
||||||
if test $rc -eq 0; then
|
if test $rc -eq 0; then
|
||||||
info "Query successful on peer0.org${ORG} on channel ${CHANNEL_NAME}"
|
echo "===================== Query successful on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== "
|
||||||
|
echo
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
echo $'\e[1;31m'"!!!!!!!!!!!!!!! After $MAX_RETRY attempts, Query result on peer0.org${ORG} is INVALID !!!!!!!!!!!!!!!!"$'\e[0m'
|
echo $'\e[1;31m'"!!!!!!!!!!!!!!! After $MAX_RETRY attempts, Query result on peer0.org${ORG} is INVALID !!!!!!!!!!!!!!!!"$'\e[0m'
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## package the chaincode
|
## package the chaincode
|
||||||
packageChaincode 1
|
packageChaincode 1
|
||||||
|
|
||||||
## Install chaincode on peer0.org1 and peer0.org2
|
## Install chaincode on peer0.org1 and peer0.org2
|
||||||
info "Installing chaincode on peer0.org1"
|
echo "Installing chaincode on peer0.org1..."
|
||||||
installChaincode 1
|
installChaincode 1
|
||||||
info "Install chaincode on peer0.org2"
|
echo "Install chaincode on peer0.org2..."
|
||||||
installChaincode 2
|
installChaincode 2
|
||||||
|
|
||||||
## query whether the chaincode is installed
|
## query whether the chaincode is installed
|
||||||
|
|
@ -364,8 +375,10 @@ queryCommitted 2
|
||||||
## Invoke the chaincode - this does require that the chaincode have the 'initLedger'
|
## Invoke the chaincode - this does require that the chaincode have the 'initLedger'
|
||||||
## method defined
|
## method defined
|
||||||
if [ "$CC_INIT_FCN" = "NA" ]; then
|
if [ "$CC_INIT_FCN" = "NA" ]; then
|
||||||
info "Chaincode initialization is not required"
|
echo "===================== Chaincode initialization is not required ===================== "
|
||||||
echo
|
echo
|
||||||
else
|
else
|
||||||
chaincodeInvokeInit 1 2
|
chaincodeInvokeInit 1 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,6 @@ export PEER0_ORG1_CA=${PWD}/organizations/peerOrganizations/org1.example.com/pee
|
||||||
export PEER0_ORG2_CA=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
export PEER0_ORG2_CA=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||||
export PEER0_ORG3_CA=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
export PEER0_ORG3_CA=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
||||||
|
|
||||||
function info() {
|
|
||||||
echo -e "\033[0;33mINFO\033[0m: ${1}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set OrdererOrg.Admin globals
|
# Set OrdererOrg.Admin globals
|
||||||
setOrdererGlobals() {
|
setOrdererGlobals() {
|
||||||
export CORE_PEER_LOCALMSPID="OrdererMSP"
|
export CORE_PEER_LOCALMSPID="OrdererMSP"
|
||||||
|
|
@ -31,7 +27,7 @@ setGlobals() {
|
||||||
else
|
else
|
||||||
USING_ORG="${OVERRIDE_ORG}"
|
USING_ORG="${OVERRIDE_ORG}"
|
||||||
fi
|
fi
|
||||||
info "Using organization ${USING_ORG}"
|
echo "Using organization ${USING_ORG}"
|
||||||
if [ $USING_ORG -eq 1 ]; then
|
if [ $USING_ORG -eq 1 ]; then
|
||||||
export CORE_PEER_LOCALMSPID="Org1MSP"
|
export CORE_PEER_LOCALMSPID="Org1MSP"
|
||||||
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
|
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,6 @@ MAX_RETRY=5
|
||||||
# import environment variables
|
# import environment variables
|
||||||
. scripts/org3-scripts/envVarCLI.sh
|
. scripts/org3-scripts/envVarCLI.sh
|
||||||
|
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# fetchChannelConfig <channel_id> <output_json>
|
# fetchChannelConfig <channel_id> <output_json>
|
||||||
# Writes the current channel config for a given channel to a JSON file
|
# Writes the current channel config for a given channel to a JSON file
|
||||||
|
|
@ -43,10 +38,14 @@ fetchChannelConfig() {
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
|
|
||||||
echo "Fetching the most recent configuration block for the channel"
|
echo "Fetching the most recent configuration block for the channel"
|
||||||
execute peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile $ORDERER_CA
|
set -x
|
||||||
|
peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile $ORDERER_CA
|
||||||
|
set +x
|
||||||
|
|
||||||
echo "Decoding config block to JSON and isolating config to ${OUTPUT}"
|
echo "Decoding config block to JSON and isolating config to ${OUTPUT}"
|
||||||
execute configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}"
|
set -x
|
||||||
|
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}"
|
||||||
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
# createConfigUpdate <channel_id> <original_config.json> <modified_config.json> <output.pb>
|
# createConfigUpdate <channel_id> <original_config.json> <modified_config.json> <output.pb>
|
||||||
|
|
@ -58,13 +57,14 @@ createConfigUpdate() {
|
||||||
MODIFIED=$3
|
MODIFIED=$3
|
||||||
OUTPUT=$4
|
OUTPUT=$4
|
||||||
|
|
||||||
execute configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb
|
set -x
|
||||||
execute configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb
|
configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb
|
||||||
execute configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb
|
configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb
|
||||||
execute configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json
|
configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb
|
||||||
# TODO
|
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json
|
||||||
execute echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json
|
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json
|
||||||
execute configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}"
|
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}"
|
||||||
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
# signConfigtxAsPeerOrg <org> <configtx.pb>
|
# signConfigtxAsPeerOrg <org> <configtx.pb>
|
||||||
|
|
@ -73,7 +73,9 @@ signConfigtxAsPeerOrg() {
|
||||||
PEERORG=$1
|
PEERORG=$1
|
||||||
TX=$2
|
TX=$2
|
||||||
setGlobals $PEERORG
|
setGlobals $PEERORG
|
||||||
execute peer channel signconfigtx -f "${TX}"
|
set -x
|
||||||
|
peer channel signconfigtx -f "${TX}"
|
||||||
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
@ -84,7 +86,9 @@ echo
|
||||||
fetchChannelConfig 1 ${CHANNEL_NAME} config.json
|
fetchChannelConfig 1 ${CHANNEL_NAME} config.json
|
||||||
|
|
||||||
# Modify the configuration to append the new org
|
# Modify the configuration to append the new org
|
||||||
execute jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
|
set -x
|
||||||
|
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
|
||||||
|
set +x
|
||||||
|
|
||||||
# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb
|
# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb
|
||||||
createConfigUpdate ${CHANNEL_NAME} config.json modified_config.json org3_update_in_envelope.pb
|
createConfigUpdate ${CHANNEL_NAME} config.json modified_config.json org3_update_in_envelope.pb
|
||||||
|
|
@ -101,8 +105,12 @@ echo
|
||||||
echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= "
|
echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= "
|
||||||
echo
|
echo
|
||||||
setGlobals 2
|
setGlobals 2
|
||||||
execute peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${ORDERER_CA}
|
set -x
|
||||||
|
peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${ORDERER_CA}
|
||||||
|
set +x
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "========= Config transaction to add org3 to network submitted! =========== "
|
echo "========= Config transaction to add org3 to network submitted! =========== "
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -28,19 +28,15 @@ MAX_RETRY=5
|
||||||
# import environment variables
|
# import environment variables
|
||||||
. scripts/org3-scripts/envVarCLI.sh
|
. scripts/org3-scripts/envVarCLI.sh
|
||||||
|
|
||||||
# execute - Prints and executes the command
|
|
||||||
function execute() {
|
|
||||||
echo -e "\033[0;32mCommand\033[0m: ${*}"
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
## Sometimes Join takes time hence RETRY at least 5 times
|
## Sometimes Join takes time hence RETRY at least 5 times
|
||||||
joinChannelWithRetry() {
|
joinChannelWithRetry() {
|
||||||
ORG=$1
|
ORG=$1
|
||||||
setGlobals $ORG
|
setGlobals $ORG
|
||||||
|
|
||||||
execute peer channel join -b $CHANNEL_NAME.block >&log.txt
|
set -x
|
||||||
|
peer channel join -b $CHANNEL_NAME.block >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
|
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
|
||||||
COUNTER=$(expr $COUNTER + 1)
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
|
|
@ -55,8 +51,10 @@ joinChannelWithRetry() {
|
||||||
|
|
||||||
|
|
||||||
echo "Fetching channel config block from orderer..."
|
echo "Fetching channel config block from orderer..."
|
||||||
execute peer channel fetch 0 $CHANNEL_NAME.block -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt
|
set -x
|
||||||
|
peer channel fetch 0 $CHANNEL_NAME.block -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
verifyResult $res "Fetching config block from orderer has Failed"
|
verifyResult $res "Fetching config block from orderer has Failed"
|
||||||
|
|
||||||
|
|
@ -66,3 +64,5 @@ echo "===================== peer0.org3 joined channel '$CHANNEL_NAME' ==========
|
||||||
echo
|
echo
|
||||||
echo "========= Finished adding Org3 to your test network! ========= "
|
echo "========= Finished adding Org3 to your test network! ========= "
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue