我是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/[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"

最佳答案

如果您想通过更改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

关于hyperledger-fabric - super 货币的fabcar.go链代码不接受更改和修改,并且始终运行先前的chaincod,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55331334/

10-12 19:41