我是Hyperledger Fabric的新手,安装了所有前提条件,并且Hyperledger Fabric fabcar链代码正确运行,但是当我在hyperledger fabic链代码中更改fabcar.go并运行它时,将显示旧车并且没有任何变化接受。
我阅读了类似的问题,但答案尚不清楚,请详细告诉我如何删除先前在sample-fabric / chaincode / fabcar / go / fabric.go中编写的链代码并安装新的链代码。
请帮助我,我将非常感激自3天以来陷入这一问题。
以下是在startFabric.sh文件代码中
#!/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/Admin@org1.example.com/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/Admin@org1.example.com/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/Admin@org1.example.com/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"
答案 0 :(得分:3)
如果您想通过更改fabcar.go链码上的参数来与“ fabcar”链码进行交互,则首先您必须停止网络,然后删除所有先前的网络模块,然后输入fabcar.go文件,更改汽车列表,然后重新建立网络,它将旧汽车列表更改为最新列表。为此,您有2个选择:
1)创建teardown.sh脚本文件:
$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)删除节点模块,并修剪docker卷:
$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
答案 1 :(得分:2)
在使用teardown.sh脚本之前,您需要拆除环境。
尝试检查您是否有较旧的链码图像并将其删除
docker images | grep fabcar docker
rmi $(docker images fabcar* -q)
有时如果图像仍然存在,Fabric不会重建链码
如果无法拆除,请使用其他名称安装并实例化链码,它将更改链码名称空间,并且您将不再看到旧记录。
答案 2 :(得分:1)
每次更改链码中的某些内容时,都必须重新部署链码并实例化它。
startfabric.sh脚本会为您做同样的事情,但是这里遗漏了一件事情,那就是当您使用脚本安装链码时,必须在startfabric.sh中更改链码的版本。
因为v1.0中已经有一个链码图像,所以它不会被覆盖。
有两种方法可以实现所需的目标
1)更改链码版本或startfabric.sh中的名称,例如
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/Admin@org1.example.com/msp" cli peer chaincode install -n fabcar -v 1.1 -p "$CC_SRC_PATH" -l "$LANGUAGE"
2)另一种方法是按照以下命令删除旧的链码图像
docker images | grep fabcar docker
rmi $(docker images fabcar* -q)
希望这对您有帮助!