Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fabcar.go chaincode of hyperledger does not accept the changes and modification and always run previous chaincode

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"
like image 235
Malik Usman Avatar asked Mar 25 '19 04:03

Malik Usman


People also ask

What is Chaincode in Hyperledger fabric?

Chaincode is a program, written in Go, node. js, or Java that implements a prescribed interface. Chaincode runs in a secured Docker container isolated from the endorsing peer process. Chaincode initializes and manages ledger state through transactions submitted by applications.

What are the four stages of Chaincode life cycle?

We provide four commands to manage a chaincode's lifecycle: package , install , instantiate , and upgrade .

How do you package Chaincode in Hyperledger fabric?

(Hyperledger Fabric v2. 2.4) To deploy a chaincode, it must be approved by organizations and then committed to a channel. After a chaincode is deployed, peers are able to accept chaincode invocations and can endorse transactions.

Which of the following functions are required for Chaincode development?

Invoking the Chaincode In our case, our application will simply have two functions: set and get , that allow the value of an asset to be set or its current state to be retrieved.


1 Answers

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
like image 120
Farkhod Abdukodirov Avatar answered Sep 27 '22 20:09

Farkhod Abdukodirov