TL; DR;转到下面的---- EDIT部分
我在独立的node.js应用程序中使用 hfc@0.6.5
。
memberrvc和peer以docker-compose
开头,其中:
membersrvc:
container_name: membersrvc
image: hyperledger/fabric-membersrvc:latest
ports:
- "7054:7054"
command: membersrvc
vp0:
container_name: peer
image: hyperledger/fabric-peer:latest
ports:
- "7050:7050"
- "7051:7051"
- "7053:7053"
environment:
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=vp0
- CORE_SECURITY_ENABLED=true
- CORE_PEER_PKI_ECA_PADDR=172.17.0.2:7054
- CORE_PEER_PKI_TCA_PADDR=172.17.0.2:7054
- CORE_PEER_PKI_TLSCA_PADDR=172.17.0.2:7054
- CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
[...]
links:
- membersrvc
command: sh -c "sleep 10; peer node start"
node.js应用程序成功注册新用户并尝试使用enrolledUser.deploy(deployRequest);
方法部署链代码。
作为deployRequest.chaincodePath
路径的值
'github.com/asset-chaincode/'
已设置。目录包含链代码.go
文件。
deployTx.on('complete', cb)
的回调打印其日志消息:
SUCCESS: Successfully deployed chaincode [chainCodeId:415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58], deploy request={"fcn":"init","args":[],"confidential":true,"metadata":{"type":"Buffer","data":[48,...155,253,0]},"chaincodePath":"github.com/gvlax/chaincodes/asset-chaincode"}, response={"uuid":"415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58","chaincodeID":"415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58"}
chaincodeId=415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58
然而,当我检查对等控制台的输出时, 我可以看到错误消息
- > full logs here:
peer | 15:40:00.416 [dockercontroller] deployImage -> ERRO 47a Error building images: The command '/bin/sh -c go install build-chaincode && cp src/build-chaincode/vendor/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin && mv $GOPATH/bin/build-chaincode $GOPATH/bin/23991376d1b935790631a448843fd12a9d60f7ab3f0b8b55f629cf0190077436' returned a non-zero code: 1
[...]
peer | ---> Running in 812439684bf7
peer | src/build-chaincode/asset-chaincode.go:25:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
peer | /opt/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)
peer | /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOPATH)
peer | src/build-chaincode/asset-chaincode.go:26:2: cannot find package "github.com/hyperledger/fabric/core/crypto/primitives" in any of:
peer | /opt/go/src/github.com/hyperledger/fabric/core/crypto/primitives (from $GOROOT)
peer | /opt/gopath/src/github.com/hyperledger/fabric/core/crypto/primitives (from $GOPATH)
peer | package build-chaincode
peer | imports github.com/hyperledger/fabric/vendor/github.com/op/go-logging: must be imported as github.com/op/go-logging
[...]
看起来有些问题与对等体上的链代码编译并不完全相关。 或者将链代码部署到对等体上无法解析链代码中相对导入路径的位置....
经过多次尝试和实验,我认为我的问题总是一样的:
无论在使用方法$GOPATH/src/gibhub.com/<mychaincode_dir>
(hfc@0.6.5)部署到对等体上的任何有效链代码(本地存储在目录enrolledUser.deploy(deployRequest)
+构建中,没有错误),结果总是相同的目标节点上的错误:
peer | Step 4 : RUN go install build-chaincode && cp src/build-chaincode/vendor/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin && mv $GOPATH/bin/build-chaincode $GOPATH/bin/0881d0fe8f4528e1369bfe917cd207d919a07758cc098e212ca74f6766c636d4
peer | ---> Running in b0ca2abbe609
peer | src/build-chaincode/asset-chaincode.go:25:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
peer | /opt/gopath/src/build-chaincode/vendor/github.com/hyperledger/fabric/core/chaincode/shim (vendor tree)
peer | /opt/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)
同行抱怨的cc的输入是:
import (
"encoding/base64"
"errors"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
[...]
此外,当我进入对等CLI时,可以在那里找到垫片......
$ docker exec -it peer bash
$ find / -name shim
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
$ echo $GOPATH/
/opt/gopath/
Fabric-peer图像没问题???
答案 0 :(得分:1)
使用hfc进行部署时,需要“提供”结构链代码包 - 请参阅http://hyperledger-fabric.readthedocs.io/en/v0.6/nodeSDK/node-sdk-indepth/#chaincode-deployment
您还可以查看https://github.com/IBM-Blockchain/SDK-Demo/tree/master/src/chaincode以获取使用SDK执行此操作的示例