Reputation: 61
I am new in hyperledger fabric and install all the pre requirement and hyperledger fabric fabcar chain code is run correctly but when I changed fabcar.go in hyperledger fabic chain code and when I run it the old cars will be show and no changes accepted.
I read similar question but answer is not clear please tell me in detail how to delete the previous chain code and install new chain code that I write in sample-fabric/chaincode/fabcar/go/fabric.go
Please help me I will very thankful I am stuck in this problem since 3 days.
following is in startFabric.sh file code
#!/bin/bash
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
# Exit on first error
set -e
# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1
starttime=$(date +%s)
LANGUAGE=${1:-"golang"}
CC_SRC_PATH=github.com/mychain/go
if [ "$LANGUAGE" = "node" -o "$LANGUAGE" = "NODE" ]; then
CC_SRC_PATH=/opt/gopath/src/github.com/fabcar/node
fi
# clean the keystore
rm -rf ./hfc-key-store
# launch network; create channel and join peer to channel
cd ../basic-network
./start.sh
# Now launch the CLI container in order to install, instantiate chaincode
# and prime the ledger with our 10 cars
docker-compose -f ./docker-compose.yml up -d cli
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp" cli peer chaincode install -n fabcar -v 1.0 -p "$CC_SRC_PATH" -l "$LANGUAGE"
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$LANGUAGE" -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[""]}'
printf "\nTotal setup execution time : $(($(date +%s) - starttime)) secs ...\n\n\n"
printf "Start by installing required packages run 'npm install'\n"
printf "Then run 'node enrollAdmin.js', then 'node registerUser'\n\n"
printf "The 'node invoke.js' will fail until it has been updated with valid arguments\n"
printf "The 'node query.js' may be run at anytime once the user has been registered\n\n"
Upvotes: 6
Views: 804
Reputation: 537
You need to teardown your environment before using the teardown.sh script.
Try to check if you have older chaincode images and delete that
docker images | grep fabcar docker
rmi $(docker images fabcar* -q)
sometimes Fabric don't rebuild chaincode if the images persists
If you can't teardown, install and instantiate the chaincode with other name it will change the chaincode namespace and you will not see the old records anymore.
Upvotes: 2
Reputation: 654
Every time you change something in the chaincode you have to redeploy the chaincode and instantiate it.
The startfabric.sh script does the same thing for you but there is one thing which was missed out here is when you install the chaincode with the script you have to change the version of the chaincode in the startfabric.sh.
As a chaincode image would already be there with v1.0 ,so its not overwritten.
There are two ways to achieve what you want
1)Change the chaincode version or the name in the startfabric.sh like
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp" cli peer chaincode install -n fabcar -v 1.1 -p "$CC_SRC_PATH" -l "$LANGUAGE"
2)another way is to remove the old chaincode image by following command
docker images | grep fabcar docker
rmi $(docker images fabcar* -q)
Hope this helps you!
Upvotes: 1
Reputation: 932
If you'd like to interact with th "fabcar" chaincode by changing the parameters on the fabcar.go chaincode, firstly u have to stop the network then remove all previous network modules, then enter the fabcar.go file, change cars' list, then bring the network up again, it should change old cars' list to the newest one. For this, u have 2 options:
1) create teardown.sh script file:
$teardown.sh (script file source code)
set -e
#Shut down the Docker containers for the system tests.
docker-compose -f docker-compose.yml kill && docker-compose -f docker-compose.yml
down
# remove chaincode docker images
docker rmi $(docker images dev-* -q)
2) delete node-modules, and prune docker volume:
$cd...fabric-samples/fabcar/javascript
$rmdir node_modules
$docker stop $(docker ps -a -q)
$docker rm $(docker ps -a -q)
$ docker volume prune
$cd...fabric-samples/fabcar
$startFabric.sh
$cd...fabric-samples/fabcar/javascript
$npm install -g
$node query.js
Upvotes: 3