docker-compose-files/hyperledger_fabric/test/cc-invoke.sh

50 lines
1.4 KiB
Bash
Raw Normal View History

2021-04-02 12:33:49 +08:00
#!/bin/bash
# Invoke a chaincode
2021-08-19 05:19:57 +08:00
# Usage: ./script mspId channelId peerAddr ordererAddr ccName mspPath=${PWD}/msp-mspId
2021-04-02 12:33:49 +08:00
# Entry function
main() {
if [ $# -lt 5 ]; then
echo "Not enough argument supplied"
2021-08-19 05:19:57 +08:00
echo "$(basename $0) mspId channelId peerAddr ordererAddr ccName mspPath=${PWD}/msp-mspId"
2021-04-02 12:33:49 +08:00
exit 1
fi
local mspId=$1
2021-08-19 05:19:57 +08:00
local channelId=$2
local peerAddr=$3
local ordererAddr=$4
2021-04-02 12:33:49 +08:00
local ccName=$5
local mspPath=${6:-${PWD}/msp-${mspId}} # Suppose the local msp path named as msp-${msp_id}
export FABRIC_LOGGING_SPEC="debug"
export CORE_PEER_ADDRESS="${peerAddr}"
export CORE_PEER_LOCALMSPID=${mspId}
export CORE_PEER_MSPCONFIGPATH=${mspPath}
export CORE_PEER_TLS_ROOTCERT_FILE=${mspPath}/tlscacerts/tlsca.cert
export CORE_PEER_TLS_ENABLED=true
peer chaincode invoke \
--connTimeout="30s" \
-o "${ordererAddr}" \
2021-08-19 05:19:57 +08:00
-C "${channelId}" \
2021-04-02 12:33:49 +08:00
-n "${ccName}" \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
2021-08-19 05:19:57 +08:00
-c '{"Args":["Init","a","100","b","100"]}' \
--isInit \
2021-04-02 12:33:49 +08:00
--tls \
--cafile "${CORE_PEER_TLS_ROOTCERT_FILE}"
2021-08-19 05:19:57 +08:00
#-c '{"Args":["invoke","a","b","10"]}' \
2021-04-02 12:33:49 +08:00
peer chaincode query \
--connTimeout=30s \
2021-08-19 05:19:57 +08:00
-C "${channelId}" \
2021-04-02 12:33:49 +08:00
-n "${ccName}" \
--peerAddresses "${peerAddr}" \
--tlsRootCertFiles "${CORE_PEER_TLS_ROOTCERT_FILE}" \
2021-08-19 05:19:57 +08:00
-c '{"Args":["query","a"]}'
2021-04-02 12:33:49 +08:00
}
main "$@"