forked from accordproject/hlf-cicero-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·72 lines (56 loc) · 4.56 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
# You must install `jq` to run this script
#
# Run this script from the root of the hlf-cicero-contract directory
# the script packages the chaincode and then installs it onto org1 and org2
# it is based on: https://hyperledger-fabric.readthedocs.io/en/master/deploy_chaincode.html#install-the-chaincode-package
# set these two values based on your HLF install location
export HLF_TEST_NETWORK=${HLF_INSTALL_DIR}/test-network
# end set
rm *.tar.gz
npm install
export PATH=${HLF_INSTALL_DIR}/bin:$PATH
export FABRIC_CFG_PATH=${HLF_INSTALL_DIR}/config/
peer version
# package the chaincode
export CC_VERSION=$(cat package.json | jq -r ".version")
echo Packaging chaincode ${CC_VERSION}
peer lifecycle chaincode package cicero_${CC_VERSION}.tar.gz --path . --lang node --label cicero_${CC_VERSION}
# install on org1
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode install cicero_${CC_VERSION}.tar.gz
echo Installed on org1
# install on org2
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_TLS_ROOTCERT_FILE=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051
peer lifecycle chaincode install cicero_${CC_VERSION}.tar.gz
echo Installed on org2
# get the last installed package id for the CC version
peer lifecycle chaincode queryinstalled
export CC_PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r "[.installed_chaincodes[] | select(.label == \"cicero_${CC_VERSION}\") | .package_id][-1]")
echo "Chaincode package id: " ${CC_PACKAGE_ID}
# get the sequence number to use
export CC_SEQUENCE=$(peer lifecycle chaincode querycommitted --channelID mychannel cicero --output json | jq -r ".chaincode_definitions[0].sequence+1")
echo "Sequence number" ${CC_SEQUENCE}
# approveformyorg
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name cicero --version ${CC_VERSION} --package-id $CC_PACKAGE_ID --sequence ${CC_SEQUENCE} --tls --cafile ${HLF_TEST_NETWORK}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
echo "Approved for org2"
# approve chaincode org1
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${HLF_TEST_NETWORK}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name cicero --version ${CC_VERSION} --package-id $CC_PACKAGE_ID --sequence ${CC_SEQUENCE} --tls --cafile ${HLF_TEST_NETWORK}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
echo "Approved for org1"
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name cicero --version ${CC_VERSION} --sequence ${CC_SEQUENCE} --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
echo "checkcommitreadiness"
# we commit the chaincode
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name cicero --version ${CC_VERSION} --sequence ${CC_SEQUENCE} --tls --cafile ${HLF_TEST_NETWORK}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${HLF_TEST_NETWORK}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${HLF_TEST_NETWORK}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
echo "chaincode committed"