報錯1
本報錯是fabric 1.X
Error: error getting chaincode bytes: failed to calculate dependencies: incomplete package: github.com/hyperledger/fabric-chaincode-go/shim
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!
apt-get install go 的版本比較低。卸載了先。然后下載go1.13.5.linux-amd64.tar.gz進行安裝。
# tar zxvf go1.13.5.linux-amd64.tar.gz
# mv go /usr/local/
# vim /etc/profile
#set golang env
export GOROOT=/usr/local/go
export GOPATH=/opt/goworkspace
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin
# source /etc/profile
# go version
go version go1.13.5 linux/amd64
環境變量:
# go env
換成國內代理:
# go env -w GOPROXY=https://goproxy.cn
# export GOPROXY=https://goproxy.cn
運行測試網絡
#cd /opt/fabric/fabric-samples/first-network
# ./byfn.sh down
#./byfn.sh up -c mychannel -s couchdb -a
有網友評論按照以上操作換了go版本后,依然報錯!?
首先檢查下fabric的版本,網友們的是2.0的。然后看下報錯信息:
Error: error getting chaincode bytes: failed to calculate dependencies: incomplete package: github.com/hyperledger/fabric-contract-api-go/contractapi
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========
找不到github.com/hyperledger/fabric-contract-api-go/contractapi依賴包,說明下載golang github.com/hyperledger/fabric-contract-api-go/contractapi依賴包的時候失敗了。
那么我們需要解決Golang1.13.x 無法下載問題,那這樣問題其實和之前一樣,主要是找個國內靠譜的代理,然后再重復的試試。
注意:Fabric 2.0的鏈碼與1.x相比,主要區別為
1、導入包的不同
1.x導入的包為:
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
2.0導入的包為:
"github.com/hyperledger/fabric-contract-api-go/contractapi"
2、方法結構不同
Fabric 2.0鏈碼沒有 Invoke(stub shim.ChaincodeStubInterface) pb.Response{ }方法。
3、方法中調用形式參數類型、返回值不同
1.x方法為:
createCar1(APIstub shim.ChaincodeStubInterface, args []string) pb.Response { }
2.0方法為:
Create(ctx contractapi.TransactionContextInterface,key string,value string)error { }
報錯2
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=1
+ set +x
2020-03-31 09:44:51.055 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Error: got unexpected status: BAD_REQUEST -- error applying config update to existing channel 'mychannel': error authorizing update: error validating ReadSet: proposed update requires that key [Group] /Channel/Application be at version 0, but it is currently at version 1
!!!!!!!!!!!!!!! Channel creation failed !!!!!!!!!!!!!!!!
========= ERROR !!! FAILED to execute End-2-End Scenario ===========
ERROR !!!! Test failed
root@ubuntu:/opt/fabric/fabric-samples/first-network#
已經存在mychannel,之前啟動的fabric network沒有正常停止,如果之前執行./byfn.sh up,那么相應的執行./byfn.sh down來停止fabric network。不要直接使用docker stop 或者 docker rm 停止刪除容器。
注意,環境變量的配置添加到/etc/bash.bashrc,使不論什么用戶登錄都生效。