一尘不染

HyperLedger结构链代码未更新

go

我正在尝试遵循此示例Hyperledger
Fabric代码:https : //github.com/hyperledger/education/tree/master/LFS171x/fabric-
material

最初,我用go文件chaincode / tuna-app / test.go替换了chaincode / tuna-app / tuna-
chaincode.go。test.go的更改仅在于我们通过其initLedger函数调用在分类帐中初始化的内容。它运行良好,不需要在tuna-app /
.startFabric.sh中进行任何更改。

现在,当我再次尝试通过其initLedger函数调用更改分类帐时,它没有发生。即使我评论函数本身,它仍然显示分类帐的旧内容。

如何使用可见的更改更新链码?

startFabric.sh包含以下代码:

set -e

# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1

starttime=$(date +%s)

if [ ! -d ~/.hfc-key-store/ ]; then
    mkdir ~/.hfc-key-store/
fi

# 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 tuna catches
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 tuna-app -v 1.0 -p github.com/test-app
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 tuna-app -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 tuna-app -c '{"function":"initLedger","Args":[""]}'

printf "\nTotal execution time : $(($(date +%s) - starttime)) secs ...\n\n"
printf "\nStart with the registerAdmin.js, then registerUser.js, then server.js\n\n"

我尝试通过对等链代码实例化后添加以下行:

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 upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

但是它给出了以下错误:

Error: Chaincode version is not provided for upgrade

当我将升级声明更改为:

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 upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"function":"initLedger","Args":[""]}'

错误更改为:

Error: Error endorsing chaincode: rpc error: code = Unknown desc = chaincode error (status: 500, message: version already exists for chaincode with name 'tuna-app')

阅读 206

收藏
2020-07-02

共1个答案

一尘不染

为了反映链式代码中的更改,采取了以下步骤:1.停止所有容器

docker stop $(docker ps -aq)
  1. 删除所有容器

docker rm -f $(docker ps -aq)

  1. 运行时查找以下图像docker images 。输出之一是其他超级账本二进制图像。

REPOSITORY TAG, IMAGE ID, CREATED, SIZE: dev-peer0.org1.example.com-tuna- app-1.0-b58eb592ed6ced10f52cc063bda0c303a4272089a3f9a99000d921f94b9bae9b, latest, 0919d7c15f0a, 3 minutes ago, 172MB

使用以下命令将其删除:

docker rmi 0919d7c15f0a

使用./startFabric.sh、npm install,node registerAdmin.js,node registerUser.js和node
server.js再次运行结构。它应该工作

2020-07-02