打包链代码后,安装命令,将错误读取为gzip流:gzip:无效标头



Hyperledger Fabric V2.3.x

对等V2.3.3

Go V1.16

完全错误:

Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not parse as a chaincode install package: error reading as gzip stream: gzip: invalid header

我的设置:

CORE_PEER_TLS_ROOTCERT_FILE=./crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=./crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
ORDERER_CA=./crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_ADDRESS=peer1.org1.example.com:7051

以前调用的命令(成功(:

peer chaincode package mycc.tar.gz -p . -n mycc --lang golang -v 1.0

命令(我得到错误(:

peer lifecycle chaincode install mycc.tar.gz

*如果需要任何其他信息,请发表评论


go.mod(用于安装依赖项(

module github.com/chaincode
go 1.16
require (
github.com/golang/protobuf v1.3.2 // indirect
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200424173110-d7076418f212 // indirect
github.com/hyperledger/fabric-contract-api-go v1.1.0
github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e // indirect
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/tools v0.1.7 // indirect
)

chaincode.go(几行(

package chaincode
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
)
// SmartContract provides functions for managing an Asset
type SmartContract struct {
contractapi.Contract
}
// Asset describes basic details of what makes up a simple asset
//Insert struct field in alphabetic order => to achieve determinism accross languages
// golang keeps the order when marshal to json but doesn't order automatically
type Asset struct {
AppraisedValue int    `json:"AppraisedValue"`
Color          string `json:"Color"`
ID             string `json:"ID"`
Owner          string `json:"Owner"`
Size           int    `json:"Size"`
}

问题出在我使用命令安装的包上

GO111MODULE=on go mod vendor

我在";go.mod";而不是1.16,因为安装的go版本是";1.16";。

(安装了不兼容的程序包,因此生成的程序包文件不是正确的gzip文件(

解决方案:

  • 删除供应商文件夹
  • 使用正确的go版本编写go.mod或使用go init(https://golang.org/doc/tutorial/create-module)
  • 运行GO111MODULE=on go mod vendor
  • 运行对等生命周期包命令
  • 运行对等生命周期安装命令

最新更新