mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-18 07:55:10 +00:00
Add endorsement policy to chaincode deployment script (#247)
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com> Co-authored-by: NIKHIL E GUPTA <negupta@us.ibm.com>
This commit is contained in:
parent
b4ed9e5afd
commit
f4c439ce8a
2 changed files with 64 additions and 11 deletions
|
|
@ -29,20 +29,26 @@ function printHelp() {
|
|||
echo " "$'\e[0;32m'restart$'\e[0m' - restart the network
|
||||
echo
|
||||
echo " Flags:"
|
||||
echo " Used with "$'\e[0;32m'network.sh up$'\e[0m', $'\e[0;32m'network.sh createChannel$'\e[0m':
|
||||
echo " -ca <use CAs> - create Certificate Authorities to generate the crypto material"
|
||||
echo " -c <channel name> - channel name to use (defaults to \"mychannel\")"
|
||||
echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
|
||||
echo " -r <max retry> - CLI times out after certain number of attempts (defaults to 5)"
|
||||
echo " -d <delay> - delay duration in seconds (defaults to 3)"
|
||||
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
|
||||
echo " -cai <ca_imagetag> - the image tag to be used for CA (defaults to \"${CA_IMAGETAG}\")"
|
||||
echo " -verbose - verbose mode"
|
||||
echo " Used with "$'\e[0;32m'network.sh deployCC$'\e[0m'
|
||||
echo " -c <channel name> - deploy chaincode to channel"
|
||||
echo " -ccn <name> - the short name of the chaincode to deploy: basic (default),ledger, private, secured"
|
||||
echo " -ccl <language> - the programming language of the chaincode to deploy: go (default), java, javascript, typescript"
|
||||
echo " -ccv <version> - chaincode version. 1.0 (default)"
|
||||
echo " -ccs <sequence> - chaincode definition sequence. Must be an integer, 1 (default), 2, 3, etc"
|
||||
echo " -ccp <path> - Optional, chaincode path. Path to the chaincode. When provided the -ccn will be used as the deployed name and not the short name of the known chaincodes."
|
||||
echo " -ccp <path> - Optional, path to the chaincode. When provided the -ccn will be used as the deployed name and not the short name of the known chaincodes."
|
||||
echo " -ccep <policy> - Optional, chaincode endorsement policy, using signature policy syntax. The default policy requires an endorsement from Org1 and Org2"
|
||||
echo " -cccg <collection-config> - Optional, path to a private data collections configuration file"
|
||||
echo " -cci <fcn name> - Optional, chaincode init required function to invoke. When provided this function will be invoked after deployment of the chaincode and will define the chaincode as initialization required."
|
||||
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
|
||||
echo " -cai <ca_imagetag> - the image tag to be used for CA (defaults to \"${CA_IMAGETAG}\")"
|
||||
echo " -verbose - verbose mode"
|
||||
echo
|
||||
echo " -h - print this message"
|
||||
echo
|
||||
echo " Possible Mode and flag combinations"
|
||||
|
|
@ -383,10 +389,11 @@ function createChannel() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
## Call the script to isntall and instantiate a chaincode on the channel
|
||||
function deployCC() {
|
||||
|
||||
scripts/deployCC.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $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
|
||||
echo "ERROR !!! Deploying chaincode failed"
|
||||
|
|
@ -440,6 +447,10 @@ CHANNEL_NAME="mychannel"
|
|||
CC_NAME="basic"
|
||||
# chaincode path defaults to "NA"
|
||||
CC_SRC_PATH="NA"
|
||||
# endorsement policy defaults to "NA". This would allow chaincodes to use the majority default policy.
|
||||
CC_END_POLICY="NA"
|
||||
# collection configuration defaults to "NA"
|
||||
CC_COLL_CONFIG="NA"
|
||||
# chaincode init function defaults to "NA"
|
||||
CC_INIT_FCN="NA"
|
||||
# use this as the default docker-compose yaml definition
|
||||
|
|
@ -534,6 +545,14 @@ while [[ $# -ge 1 ]] ; do
|
|||
CC_SRC_PATH="$2"
|
||||
shift
|
||||
;;
|
||||
-ccep )
|
||||
CC_END_POLICY="$2"
|
||||
shift
|
||||
;;
|
||||
-cccg )
|
||||
CC_COLL_CONFIG="$2"
|
||||
shift
|
||||
;;
|
||||
-cci )
|
||||
CC_INIT_FCN="$2"
|
||||
shift
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ CC_SRC_LANGUAGE=${4:-"go"}
|
|||
CC_VERSION=${5:-"1.0"}
|
||||
CC_SEQUENCE=${6:-"1"}
|
||||
CC_INIT_FCN=${7:-"NA"}
|
||||
DELAY=${8:-"3"}
|
||||
MAX_RETRY=${9:-"5"}
|
||||
VERBOSE=${10:-"false"}
|
||||
CC_END_POLICY=${8:-"NA"}
|
||||
CC_COLL_CONFIG=${9:-"NA"}
|
||||
DELAY=${10:-"3"}
|
||||
MAX_RETRY=${11:-"5"}
|
||||
VERBOSE=${12:-"false"}
|
||||
|
||||
echo --- executing with the following
|
||||
echo - CHANNEL_NAME:$'\e[0;32m'$CHANNEL_NAME$'\e[0m'
|
||||
|
|
@ -16,6 +18,8 @@ echo - CC_SRC_PATH:$'\e[0;32m'$CC_SRC_PATH$'\e[0m'
|
|||
echo - CC_SRC_LANGUAGE:$'\e[0;32m'$CC_SRC_LANGUAGE$'\e[0m'
|
||||
echo - CC_VERSION:$'\e[0;32m'$CC_VERSION$'\e[0m'
|
||||
echo - CC_SEQUENCE:$'\e[0;32m'$CC_SEQUENCE$'\e[0m'
|
||||
echo - CC_END_POLICY:$'\e[0;32m'$CC_END_POLICY$'\e[0m'
|
||||
echo - CC_COLL_CONFIG:$'\e[0;32m'$CC_COLL_CONFIG$'\e[0m'
|
||||
echo - CC_INIT_FCN:$'\e[0;32m'$CC_INIT_FCN$'\e[0m'
|
||||
echo - DELAY:$'\e[0;32m'$DELAY$'\e[0m'
|
||||
echo - MAX_RETRY:$'\e[0;32m'$MAX_RETRY$'\e[0m'
|
||||
|
|
@ -25,6 +29,8 @@ CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
|
|||
|
||||
FABRIC_CFG_PATH=$PWD/../config/
|
||||
|
||||
|
||||
|
||||
# User has not provided a path, therefore the CC_NAME must
|
||||
# be the short name of a known chaincode sample
|
||||
if [ "$CC_SRC_PATH" = "NA" ]; then
|
||||
|
|
@ -59,6 +65,17 @@ if [ "$CC_SRC_PATH" = "NA" ]; then
|
|||
elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
|
||||
CC_SRC_PATH="$CC_SRC_PATH/chaincode-typescript/"
|
||||
fi
|
||||
|
||||
# check that the language is available for the sample chaincode
|
||||
if [ ! -d "$CC_SRC_PATH" ]; then
|
||||
echo The smart contract language "$CC_SRC_LANGUAGE" is not yet available for
|
||||
echo the "$CC_NAME" sample smart contract
|
||||
exit 1
|
||||
fi
|
||||
## Make sure that the path the chaincode exists if provided
|
||||
elif [ ! -d "$CC_SRC_PATH" ]; then
|
||||
echo Path to chaincode does not exist. Please provide different path
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# do some language specific preparation to the chaincode before packaging
|
||||
|
|
@ -106,6 +123,23 @@ if [ "$CC_INIT_FCN" = "NA" ]; then
|
|||
INIT_REQUIRED=""
|
||||
fi
|
||||
|
||||
if [ "$CC_END_POLICY" = "NA" ]; then
|
||||
CC_END_POLICY=""
|
||||
else
|
||||
CC_END_POLICY="--signature-policy $CC_END_POLICY"
|
||||
fi
|
||||
|
||||
if [ "$CC_COLL_CONFIG" = "NA" ]; then
|
||||
CC_COLL_CONFIG=""
|
||||
else
|
||||
CC_COLL_CONFIG="--collections-config $CC_COLL_CONFIG"
|
||||
fi
|
||||
|
||||
|
||||
#if [ "$CC_INIT_FCN" = "NA" ]; then
|
||||
# INIT_REQUIRED=""
|
||||
#fi
|
||||
|
||||
# import utils
|
||||
. scripts/envVar.sh
|
||||
|
||||
|
|
@ -157,7 +191,7 @@ approveForMyOrg() {
|
|||
ORG=$1
|
||||
setGlobals $ORG
|
||||
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} >&log.txt
|
||||
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
|
||||
verifyResult $res "Chaincode definition approved on peer0.org${ORG} on channel '$CHANNEL_NAME' failed"
|
||||
|
|
@ -179,7 +213,7 @@ checkCommitReadiness() {
|
|||
sleep $DELAY
|
||||
echo "Attempting to check the commit readiness of the chaincode definition on peer0.org${ORG}, Retry after $DELAY seconds."
|
||||
set -x
|
||||
peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME --name ${CC_NAME} --version ${CC_VERSION} --sequence ${CC_SEQUENCE} ${INIT_REQUIRED} --output json >&log.txt
|
||||
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=$?
|
||||
set +x
|
||||
let rc=0
|
||||
|
|
@ -209,7 +243,7 @@ commitChaincodeDefinition() {
|
|||
# peer (if join was successful), let's supply it directly as we know
|
||||
# it using the "-o" option
|
||||
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} >&log.txt
|
||||
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=$?
|
||||
set +x
|
||||
cat log.txt
|
||||
|
|
|
|||
Loading…
Reference in a new issue