Signed-off-by: Brett Logan <brett.t.logan@ibm.com>
This commit is contained in:
Brett Logan 2020-07-20 00:44:04 -04:00
parent dc4dcd482e
commit 48120ee2d8
5 changed files with 140 additions and 180 deletions

View file

@ -70,9 +70,14 @@ function printHelp() {
# execute - Prints and executes the command # execute - Prints and executes the command
function execute() { function execute() {
echo -e "\033[0;32mCommand\033[0m: ${*}" 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
@ -195,7 +200,6 @@ 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
@ -208,14 +212,8 @@ function createOrgs() {
exit 1 exit 1
fi fi
echo echo
echo "##########################################################" info "Generate certificates using cryptogen tool"
echo "##### Generate certificates using cryptogen tool #########" info "Create Org1 Identities"
echo "##########################################################"
echo
echo "##########################################################"
echo "############ Create Org1 Identities ######################"
echo "##########################################################"
execute cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations" execute cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations"
res=$? res=$?
@ -223,10 +221,9 @@ function createOrgs() {
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
echo "##########################################################" info "Create Org2 Identities"
echo "############ Create Org2 Identities ######################"
echo "##########################################################"
execute cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations" execute cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations"
res=$? res=$?
@ -234,10 +231,9 @@ function createOrgs() {
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
echo "##########################################################" info "Create Orderer Org Identities"
echo "############ Create Orderer Org Identities ###############"
echo "##########################################################"
execute cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations" execute cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations"
res=$? res=$?
@ -245,46 +241,34 @@ function createOrgs() {
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
echo "##########################################################" info "Creating Fabric CA's"
echo "##### Generate certificates using Fabric CA's ############" IMAGE_TAG=${CA_IMAGETAG} docker-compose -f "$COMPOSE_FILE_CA" up -d 2>&1
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
echo "############ Create Org1 Identities ######################" info "Generate certificates using Fabric CA's"
echo "##########################################################"
info "Create Org1 Identities"
createOrg1 createOrg1
echo "##########################################################" info "Create Org2 Identities"
echo "############ Create Org2 Identities ######################"
echo "##########################################################"
createOrg2 createOrg2
echo "##########################################################" info "Create Orderer Org Identities"
echo "############ Create Orderer Org Identities ###############"
echo "##########################################################"
createOrderer createOrderer
fi fi
echo info "Generate CCP files for Org1 and Org2"
echo "Generate CCP files for Org1 and Org2"
./organizations/ccp-generate.sh ./organizations/ccp-generate.sh
echo
} }
# Once you create the organization crypto material, you need to create the # Once you create the organization crypto material, you need to create the
@ -315,14 +299,13 @@ 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
echo "######### Generating Orderer Genesis block ##############" info "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!
@ -332,6 +315,7 @@ function createConsortium() {
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,
@ -342,7 +326,6 @@ 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
@ -367,9 +350,7 @@ 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
@ -384,21 +365,17 @@ 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
} }

View file

@ -4,15 +4,18 @@ function execute() {
"${@}" "${@}"
} }
function info() {
echo -e "\033[0;33mINFO\033[0m: ${1}"
}
function createOrg1 { function createOrg1 {
echo info "Enroll the CA admin"
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/
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:7054 --caname ca-org1 --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem execute fabric-ca-client enroll -u https://admin:adminpw@localhost:7054 --caname ca-org1 --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem
echo
echo 'NodeOUs: echo 'NodeOUs:
Enable: true Enable: true
@ -29,36 +32,30 @@ 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
echo info "Register peer0"
echo "Register peer0"
echo
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 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 info "Register user"
echo "Register user"
echo
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 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 info "Register the org admin"
echo "Register the org admin"
echo
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 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
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
echo info "Generate the peer0 msp"
echo "## Generate the peer0 msp"
echo
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 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
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
echo info "Generate the peer0-tls certificates"
echo "## Generate the peer0-tls certificates"
echo
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 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
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
@ -76,34 +73,30 @@ 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
echo info "Generate the user msp"
echo "## Generate the user msp"
echo
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 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
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
echo info "Generate the org admin msp"
echo "## Generate the org admin msp"
echo
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 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
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 {
echo info "Enroll the CA admin"
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/
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:8054 --caname ca-org2 --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem execute fabric-ca-client enroll -u https://admin:adminpw@localhost:8054 --caname ca-org2 --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem
echo
echo 'NodeOUs: echo 'NodeOUs:
Enable: true Enable: true
@ -120,35 +113,30 @@ 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
echo info "Register peer0"
echo "Register peer0"
echo
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 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 info "Register user"
echo "Register user"
echo
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 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 info "Register the org admin"
echo "Register the org admin"
echo
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 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
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
echo info "Generate the peer0 msp"
echo "## Generate the peer0 msp"
echo
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 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
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
echo info "Generate the peer0-tls certificates"
echo "## Generate the peer0-tls certificates"
echo
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 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
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
@ -166,33 +154,29 @@ 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
echo info "Generate the user msp"
echo "## Generate the user msp"
echo
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 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
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
echo info "Generate the org admin msp"
echo "## Generate the org admin msp"
echo
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 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
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 {
echo info "Enroll the CA admin"
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
execute fabric-ca-client enroll -u https://admin:adminpw@localhost:9054 --caname ca-orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem execute fabric-ca-client enroll -u https://admin:adminpw@localhost:9054 --caname ca-orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem
echo
echo 'NodeOUs: echo 'NodeOUs:
Enable: true Enable: true
@ -209,32 +193,27 @@ 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"
echo
echo "Register orderer"
echo
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 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
echo info "Register the orderer admin"
echo "Register the orderer admin"
echo
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 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
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
echo info "Generate the orderer msp"
echo "## Generate the orderer msp"
echo
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 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
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
echo info "Generate the orderer-tls certificates"
echo "## Generate the orderer-tls certificates"
echo
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 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
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
@ -249,10 +228,9 @@ 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
echo info "Generate the admin msp"
echo "## Generate the admin msp"
echo
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 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
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
} }

View file

@ -16,9 +16,14 @@ VERBOSE="$4"
# execute - Prints and executes the command # execute - Prints and executes the command
function execute() { function execute() {
echo -e "\033[0;32mCommand\033[0m: ${*}" 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
@ -31,12 +36,11 @@ createChannelTx() {
exit 1 exit 1
fi fi
echo echo
} }
createAncorPeerTx() { createAncorPeerTx() {
for orgmsp in Org1MSP Org2MSP; do for orgmsp in Org1MSP Org2MSP; do
echo "####### Generating anchor peer update transaction for ${orgmsp} ##########" info "Generating anchor peer update transaction for ${orgmsp}"
execute configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID $CHANNEL_NAME -asOrg ${orgmsp} execute configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID $CHANNEL_NAME -asOrg ${orgmsp}
res=$? res=$?
if [ $res -ne 0 ]; then if [ $res -ne 0 ]; then
@ -61,8 +65,7 @@ createChannel() {
done done
cat log.txt cat log.txt
verifyResult $res "Channel creation failed" verifyResult $res "Channel creation failed"
echo info "Channel ${CHANNEL_NAME} created"
echo "===================== Channel '$CHANNEL_NAME' created ===================== "
echo echo
} }
@ -73,16 +76,16 @@ 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 -a $COUNTER -lt $MAX_RETRY ] ; do while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ] ; do
sleep $DELAY sleep $DELAY
execute peer channel join -b ./channel-artifacts/$CHANNEL_NAME.block >&log.txt execute peer channel join -b ./channel-artifacts/$CHANNEL_NAME.block >&log.txt
res=$? res=$?
let rc=$res let rc=$res
COUNTER=$(expr $COUNTER + 1) COUNTER=$((COUNTER + 1))
done done
cat log.txt cat log.txt
echo
verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' " verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' "
echo
} }
updateAnchorPeers() { updateAnchorPeers() {
@ -100,14 +103,14 @@ updateAnchorPeers() {
done done
cat log.txt cat log.txt
verifyResult $res "Anchor peer update failed" verifyResult $res "Anchor peer update failed"
echo "===================== Anchor peers updated for org '$CORE_PEER_LOCALMSPID' on channel '$CHANNEL_NAME' ===================== " info "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
@ -116,33 +119,30 @@ verifyResult() {
FABRIC_CFG_PATH=${PWD}/configtx FABRIC_CFG_PATH=${PWD}/configtx
## Create channeltx ## Create channeltx
echo "### Generating channel create transaction '${CHANNEL_NAME}.tx' ###" echo
info "Generating channel create transaction ${CHANNEL_NAME}.tx"
createChannelTx createChannelTx
## Create anchorpeertx ## Create anchorpeertx
echo "### Generating anchor peer update transactions ###" info "Generating anchor peer update transactions"
createAncorPeerTx createAncorPeerTx
FABRIC_CFG_PATH=$PWD/../config/ FABRIC_CFG_PATH=$PWD/../config/
## Create channel ## Create channel
echo "Creating channel "$CHANNEL_NAME info "Creating channel ${CHANNEL_NAME}"
createChannel createChannel
## Join all the peers to the channel ## Join all the peers to the channel
echo "Join Org1 peers to the channel..." info "Join Org1 peers to the channel"
joinChannel 1 joinChannel 1
echo "Join Org2 peers to the channel..." info "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
echo "Updating anchor peers for org1..." info "Updating anchor peers for org1"
updateAnchorPeers 1 updateAnchorPeers 1
echo "Updating anchor peers for org2..." info "Updating anchor peers for org2"
updateAnchorPeers 2 updateAnchorPeers 2
echo info "Channel successfully joined"
echo "========= Channel successfully joined =========== "
echo
exit 0

View file

@ -32,13 +32,19 @@ FABRIC_CFG_PATH=$PWD/../config/
# execute - Prints and executes the command # execute - Prints and executes the command
function execute() { function execute() {
echo -e "\033[0;32mCommand\033[0m: ${*}" 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
echo Determining the path to the chaincode info "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
@ -81,25 +87,26 @@ 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
echo Vendoring Go dependencies at $CC_SRC_PATH info "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
echo Finished vendoring Go dependencies info "Finished vendoring Go dependencies"
elif [ "$CC_SRC_LANGUAGE" = "java" ]; then elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
CC_RUNTIME_LANGUAGE=java CC_RUNTIME_LANGUAGE=java
echo Compiling Java code ... info "Compiling Java code"
pushd $CC_SRC_PATH pushd $CC_SRC_PATH
./gradlew installDist ./gradlew installDist
popd popd
echo Finished compiling Java code info "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
@ -108,12 +115,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
echo Compiling TypeScript code into JavaScript ... info "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
echo Finished compiling TypeScript code into JavaScript info "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
@ -139,11 +146,6 @@ 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
@ -155,7 +157,7 @@ packageChaincode() {
res=$? res=$?
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"
echo "===================== Chaincode is packaged on peer0.org${ORG} ===================== " info " Chaincode is packaged on peer0.org${ORG}"
echo echo
} }
@ -167,7 +169,7 @@ installChaincode() {
res=$? res=$?
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"
echo "===================== Chaincode is installed on peer0.org${ORG} ===================== " info "Chaincode is installed on peer0.org${ORG}"
echo echo
} }
@ -180,7 +182,7 @@ queryInstalled() {
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"
echo "===================== Query installed successful on peer0.org${ORG} on channel ===================== " info "Query installed successful on peer0.org${ORG} on channel"
echo echo
} }
@ -191,7 +193,7 @@ approveForMyOrg() {
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 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
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"
echo "===================== Chaincode definition approved on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== " info "Chaincode definition approved on peer0.org${ORG} on channel ${CHANNEL_NAME}"
echo echo
} }
@ -200,14 +202,14 @@ checkCommitReadiness() {
ORG=$1 ORG=$1
shift 1 shift 1
setGlobals $ORG setGlobals $ORG
echo "===================== Checking the commit readiness of the chaincode definition on peer0.org${ORG} on channel '$CHANNEL_NAME'... ===================== " info "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 -a $COUNTER -lt $MAX_RETRY ]; do while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ]; do
sleep $DELAY sleep $DELAY
echo "Attempting to check the commit readiness of the chaincode definition on peer0.org${ORG}, Retry after $DELAY seconds." info "Checking 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 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
res=$? res=$?
let rc=0 let rc=0
@ -218,18 +220,19 @@ checkCommitReadiness() {
done done
cat log.txt cat log.txt
if test $rc -eq 0; then if test $rc -eq 0; then
echo "===================== Checking the commit readiness of the chaincode definition successful on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== " info "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 "
@ -240,7 +243,7 @@ commitChaincodeDefinition() {
res=$? res=$?
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"
echo "===================== Chaincode definition committed on channel '$CHANNEL_NAME' ===================== " info "Chaincode definition committed on channel '${CHANNEL_NAME}"
echo echo
} }
@ -249,14 +252,14 @@ 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"
echo "===================== Querying chaincode definition on peer0.org${ORG} on channel '$CHANNEL_NAME'... ===================== " info "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 -a $COUNTER -lt $MAX_RETRY ]; do while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ]; do
sleep $DELAY sleep $DELAY
echo "Attempting to Query committed status on peer0.org${ORG}, Retry after $DELAY seconds." info "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 execute peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name ${CC_NAME} >&log.txt
res=$? res=$?
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')
@ -266,18 +269,18 @@ queryCommitted() {
echo echo
cat log.txt cat log.txt
if test $rc -eq 0; then if test $rc -eq 0; then
echo "===================== Query chaincode definition successful on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== " info "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 "
@ -285,51 +288,51 @@ chaincodeInvokeInit() {
# 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
fcn_call='{"function":"'${CC_INIT_FCN}'","Args":[]}' fcn_call='{"function":"'${CC_INIT_FCN}'","Args":[]}'
echo invoke fcn call:${fcn_call} info "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 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
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Invoke execution on $PEERS failed " verifyResult $res "Invoke execution on $PEERS failed "
echo "===================== Invoke transaction successful on $PEERS on channel '$CHANNEL_NAME' ===================== " info "Invoke transaction successful on $PEERS on channel ${CHANNEL_NAME}"
echo echo
} }
chaincodeQuery() { chaincodeQuery() {
ORG=$1 ORG=$1
setGlobals $ORG setGlobals $ORG
echo "===================== Querying on peer0.org${ORG} on channel '$CHANNEL_NAME'... ===================== " info "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 -a $COUNTER -lt $MAX_RETRY ]; do while [ $rc -ne 0 ] && [ $COUNTER -lt $MAX_RETRY ]; do
sleep $DELAY sleep $DELAY
echo "Attempting to Query peer0.org${ORG}, Retry after $DELAY seconds." info "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 execute peer chaincode query -C $CHANNEL_NAME -n ${CC_NAME} -c '{"Args":["queryAllCars"]}' >&log.txt
res=$? res=$?
let rc=$res let rc=$res
COUNTER=$(expr $COUNTER + 1) COUNTER=$((COUNTER + 1))
done done
echo echo
cat log.txt cat log.txt
if test $rc -eq 0; then if test $rc -eq 0; then
echo "===================== Query successful on peer0.org${ORG} on channel '$CHANNEL_NAME' ===================== " info "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
echo "Installing chaincode on peer0.org1..." info "Installing chaincode on peer0.org1"
installChaincode 1 installChaincode 1
echo "Install chaincode on peer0.org2..." info "Install chaincode on peer0.org2"
installChaincode 2 installChaincode 2
## query whether the chaincode is installed ## query whether the chaincode is installed
@ -361,10 +364,8 @@ 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
echo "===================== Chaincode initialization is not required ===================== " info "Chaincode initialization is not required"
echo echo
else else
chaincodeInvokeInit 1 2 chaincodeInvokeInit 1 2
fi fi
exit 0

View file

@ -12,6 +12,10 @@ 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"
@ -27,7 +31,7 @@ setGlobals() {
else else
USING_ORG="${OVERRIDE_ORG}" USING_ORG="${OVERRIDE_ORG}"
fi fi
echo "Using organization ${USING_ORG}" info "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