- 一、基础环境准备
- 1、 安装docker
- 2、 安装docker compose
- 3、 安装golang
- 4、 安装Node
- 5、 安装 Git
- 二、fabric 源码安装
- 1、下载源码
- 2、使用测试网络
- 三、chaincode部署(以go为例)
- 1、打包链码
- 1.1、安装依赖
- 1.2、使用peer CLI打包链码,
- 2、安装打包的链码
- 3、审议链码定义
- 4、向Channel中提交链码定义
- 5、调用链码
- 6、升级链码
- 四、使用SDK与fabric网络交互
- 五、参考文档
安装docker依赖库:
yum install -y yum-utils device-mapper-persistent-data lvm2
添加Docker CE的软件源信息:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo dnf makecache
安装最新版docker:
yum -y install docker-ce systemctl start docker
查看是否安装成功:
docker version
注意:在 安装时可能会出现模块依赖问题,
解决方案:
-
下载docker-ce的repo
curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
-
安装依赖
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm
-
安装docker-ce
yum install docker-ce
即可解决。
查看docker版本:
[lj@localhost yum.repos.d]$ sudo docker version [sudo] lj 的密码: Client: Docker Engine - Community Version: 20.10.16 API version: 1.41 Go version: go1.17.10 Git commit: aa7e414 Built: Thu May 12 09:19:45 2022 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.16 API version: 1.41 (minimum version 1.12) Go version: go1.17.10 Git commit: f756502 Built: Thu May 12 09:18:08 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.4 GitCommit: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16 runc: Version: 1.1.1 GitCommit: v1.1.1-0-g52de29d docker-init: Version: 0.19.0 GitCommit: de40ad0 [lj@localhost yum.repos.d]$2、 安装docker compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
赋权
chmod +x /usr/local/bin/docker-compose
查看版本:
docker-compose version
结果
[root@localhost yum.repos.d]# docker-compose version docker-compose version 1.25.5, build 8a1c60f6 docker-py version: 4.1.0 CPython version: 3.7.5 OpenSSL version: OpenSSL 1.1.0l 10 Sep 20193、 安装golang
下载文件:
wget -P /usr/local https://dl.google.com/go/go1.16.linux-amd64.tar.gz
解压文件到 /usr/local(可以自行选择路径)
cd /usr/local tar -zxvf go1.16.linux-amd64.tar.gz
配置环境
vim /etc/profile
写入
export PATH=$PATH:/usr/local/go/bin export GOROOT=/usr/local/go export GOPATH=/root/go/ #根据自己的路径进行修改
使环境配置生效
source /etc/profile
查看版本
go version
结果
[root@localhost ~]# vim /etc/profile [root@localhost ~]# source /etc/profile [root@localhost ~]# go version go version go1.16 linux/amd644、 安装Node
wget https://npm.taobao.org/mirrors/node/v14.4.0/node-v14.4.0-linux-x64.tar.xz
tar -xvf node-v14.4.0-linux-x64.tar.xz
cd node-v14.4.0-linux-x64/
cd bin
sudo ln -s ${PWD}/node /usr/bin/node
sudo ln -s ${PWD}/npm /usr/bin/npm
[lj@localhost ~]$ wget https://npm.taobao.org/mirrors/node/v14.4.0/node-v14.4.0-linux-x64.tar.xz --2022-06-03 21:22:55-- https://npm.taobao.org/mirrors/node/v14.4.0/node-v14.4.0-linux-x64.tar.xz 正在解析主机 npm.taobao.org (npm.taobao.org)... 114.55.80.225 正在连接 npm.taobao.org (npm.taobao.org)|114.55.80.225|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily 位置:https://cdn.npmmirror.com/binaries/node/v14.4.0/node-v14.4.0-linux-x64.tar.xz [跟随至新的 URL] --2022-06-03 21:22:55-- https://cdn.npmmirror.com/binaries/node/v14.4.0/node-v14.4.0-linux-x64.tar.xz 正在解析主机 cdn.npmmirror.com (cdn.npmmirror.com)... 183.204.38.243, 183.204.38.239, 183.204.38.238, ... 正在连接 cdn.npmmirror.com (cdn.npmmirror.com)|183.204.38.243|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:20837612 (20M) [application/x-xz] 正在保存至: “node-v14.4.0-linux-x64.tar.xz” 100%[========================================================================================================================================================>] 20,837,612 9.92MB/s 用时 2.0s 2022-06-03 21:22:57 (9.92 MB/s) - 已保存 “node-v14.4.0-linux-x64.tar.xz” [20837612/20837612])
查看版本
[lj@localhost bin]$ npm -v 6.14.5 [lj@localhost bin]$ node -v v14.4.05、 安装 Git
yum install git
查看版本
git version二、fabric 源码安装 1、下载源码
git clone https://github.com/hyperledger/fabric.git
cd fabric/scripts #下载镜像和二进制文件: sudo ./bootstrap.sh
过程会比较慢,有可能出现卡顿的情况,多试几次。
2、使用测试网络跑之前先清一下docker网络环境
docker stop $(docker ps -aq) docker rm $(docker ps -qa)
启动test-network测试网络:
cd /home/lj/fabric/scripts/fabric-samples/test-network #(改成自己的安装目录) ./network.sh up
结果如下
[root@localhost test-network]# ./network.sh up Using docker and docker-compose Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' LOCAL_VERSION=2.3.0 DOCKER_IMAGE_VERSION=2.3.0 Creating peer0.org1.example.com ... done Creating orderer.example.com ... done Creating peer0.org2.example.com ... done Creating cli ... done CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES da86cd62b2cc hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli e663bfeb201f hyperledger/fabric-peer:latest "peer node start" 2 seconds ago Up Less than a second 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp peer0.org2.example.com 149fc15023d5 hyperledger/fabric-orderer:latest "orderer" 2 seconds ago Up Less than a second 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp orderer.example.com e2f5ac4e9918 hyperledger/fabric-peer:latest "peer node start" 2 seconds ago Up Less than a second 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp peer0.org1.example.com
查看docker容器:
docker ps
[root@localhost test-network]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 21caae6bbc81 hyperledger/fabric-tools:latest "/bin/bash" 20 minutes ago Up 20 minutes cli 3a624444b3cf hyperledger/fabric-peer:latest "peer node start" 20 minutes ago Up 20 minutes 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp peer0.org2.example.com cf821462d4c3 hyperledger/fabric-orderer:latest "orderer" 20 minutes ago Up 20 minutes 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp orderer.example.com 0f59c549dffd hyperledger/fabric-peer:latest "peer node start" 20 minutes ago Up 20 minutes 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp peer0.org1.example.com
- 至此,fabric测试网络test-network跑通了。
创建channel,使用network.sh脚本创建来创建一个连接org1和org2组织并加入他们peer的通道,命令如下:
./network.sh createChannel
[root@localhost test-network]# ./network.sh createChannel
Using docker and docker-compose
Creating channel 'mychannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb
Network Running Already
Using docker and docker-compose
Generating channel genesis block 'mychannel.block'
/home/lj/fabric/scripts/fabric-samples/bin/configtxgen
+ configtxgen -profile TwoOrgsApplicationGenesis -outputBlock ./channel-artifacts/mychannel.block -channelID mychannel
2022-05-29 13:42:27.026 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-05-29 13:42:27.033 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft
2022-05-29 13:42:27.033 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
2022-05-29 13:42:27.033 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /home/lj/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml
2022-05-29 13:42:27.043 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block
2022-05-29 13:42:27.043 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Creating application channel genesis block
2022-05-29 13:42:27.043 CST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
Creating channel mychannel
Using organization 1
+ osnadmin channel join --channel-id mychannel --config-block ./channel-artifacts/mychannel.block -o localhost:7053 --ca-file /home/lj/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --client-cert /home/lj/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt --client-key /home/lj/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key
+ res=0
Status: 201
{
"name": "mychannel",
"url": "/participation/v1/channels/mychannel",
"consensusRelation": "consenter",
"status": "active",
"height": 1
}
Channel 'mychannel' created
Joining org1 peer to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
2022-05-29 13:42:33.319 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-29 13:42:33.350 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
Joining org2 peer to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/mychannel.block
+ res=0
2022-05-29 13:42:36.466 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-29 13:42:36.485 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
Setting anchor peer for org1...
Using organization 1
Fetching channel config for channel mychannel
Using organization 1
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2022-05-29 05:42:36.822 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-29 05:42:36.826 UTC [cli.common] readBlock -> INFO 002 Received block: 0
2022-05-29 05:42:36.826 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 0
2022-05-29 05:42:36.830 UTC [cli.common] readBlock -> INFO 004 Received block: 0
Decoding config block to JSON and isolating config to Org1MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
+ jq '.channel_group.groups.Application.groups.Org1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' Org1MSPconfig.json
Generating anchor peer update transaction for Org1 on channel mychannel
+ configtxlator proto_encode --input Org1MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org1.example.com",' '"port":' 7051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org1MSPanchors.tx
2022-05-29 05:42:37.170 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-29 05:42:37.192 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org1MSP' on channel 'mychannel'
Setting anchor peer for org2...
Using organization 2
Fetching channel config for channel mychannel
Using organization 2
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
2022-05-29 05:42:37.440 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-29 05:42:37.443 UTC [cli.common] readBlock -> INFO 002 Received block: 1
2022-05-29 05:42:37.443 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 1
2022-05-29 05:42:37.444 UTC [cli.common] readBlock -> INFO 004 Received block: 1
Decoding config block to JSON and isolating config to Org2MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
+ jq '.data.data[0].payload.data.config' config_block.json
Generating anchor peer update transaction for Org2 on channel mychannel
+ jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' Org2MSPconfig.json
+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config --output original_config.pb
+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config --output modified_config.pb
+ configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
++ cat config_update.json
+ jq .
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"mychannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org2.example.com",' '"port":' 9051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org2MSPanchors.tx
2022-05-29 05:42:37.725 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-29 05:42:37.741 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'mychannel'
Channel 'mychannel' joined
也可以带上channel标签,命令如下(-c channelName):
./network.sh createChannel -c channel1
如果要在一个步骤中启动网络并创建频道,可以同时使用up和create channel模式:
./network.sh up createChannel
在通道上启动链码
使用network.sh创建通道之后,可以使用以下命令在通道上启动链码(默认使用go语言):
./network.sh deployCC
[root@localhost test-network]# ./network.sh deployCC Using docker and docker-compose deploying chaincode on channel 'mychannel' executing with the following - CHANNEL_NAME: mychannel - CC_NAME: NA - CC_SRC_PATH: NA - CC_SRC_LANGUAGE: NA - CC_VERSION: 1.0 - CC_SEQUENCE: 1 - CC_END_POLICY: NA - CC_COLL_CONFIG: NA - CC_INIT_FCN: NA - DELAY: 3 - MAX_RETRY: 5 - VERBOSE: false No chaincode name was provided. Valid call example: ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go Deploying chaincode failed
提示:
No chaincode name was provided. Valid call example: ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go Deploying chaincode failed
意思是默认缺省参数的方式不太行,需要指定 -ccn -ccp 参数。
当补全 -ccn 和 -ccp 参数后,继续执行:
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go Using docker and docker-compose deploying chaincode on channel 'mychannel' executing with the following - CHANNEL_NAME: mychannel - CC_NAME: basic - CC_SRC_PATH: ../asset-transfer-basic/chaincode-go - CC_SRC_LANGUAGE: go - CC_VERSION: 1.0 - CC_SEQUENCE: 1 - CC_END_POLICY: NA - CC_COLL_CONFIG: NA - CC_INIT_FCN: NA - DELAY: 3 - MAX_RETRY: 5 - VERBOSE: false Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go /home/lj/fabric/scripts/fabric-samples/asset-transfer-basic/chaincode-go /home/lj/fabric/scripts/fabric-samples/test-network go: github.com/golang/protobuf@v1.3.2: Get "https://proxy.golang.org/github.com/golang/protobuf/@v/v1.3.2.mod": dial tcp 172.217.163.49:443: connect: connection refused /home/lj/fabric/scripts/fabric-samples/test-network Finished vendoring Go dependencies + peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0 + res=1 Error: failed to normalize chaincode path: 'go list' failed with: go: github.com/golang/protobuf@v1.3.2: Get "https://proxy.golang.org/github.com/golang/protobuf/@v/v1.3.2.mod": dial tcp 172.217.163.49:443: connect: connection refused: exit status 1 Chaincode packaging has failed Deploying chaincode failed
提示:
Error: failed to normalize chaincode path: 'go list' failed with: go: github.com/golang/protobuf@v1.3.2: Get "https://proxy.golang.org/github.com/golang/protobuf/@v/v1.3.2.mod": dial tcp 172.217.163.49:443: connect: connection refused: exit status 1 Chaincode packaging has failed Deploying chaincode failed
go list 发生失败,这时通过 go env 可以看到,go 的代理默认是:https://proxy.golang.org,direct.
将代理更改为:goproxy.cn,direct。
执行:
go env -w GOPROXY=https://goproxy.cn,direct
再次执行 go env 可以看到代理已经更换了。
好,再去执行:
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
执行结果
[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go Using docker and docker-compose deploying chaincode on channel 'mychannel' executing with the following - CHANNEL_NAME: mychannel - CC_NAME: basic - CC_SRC_PATH: ../asset-transfer-basic/chaincode-go - CC_SRC_LANGUAGE: go - CC_VERSION: 1.0 - CC_SEQUENCE: 1 - CC_END_POLICY: NA - CC_COLL_CONFIG: NA - CC_INIT_FCN: NA - DELAY: 3 - MAX_RETRY: 5 - VERBOSE: false Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go /home/lj/fabric/scripts/fabric-samples/asset-transfer-basic/chaincode-go /home/lj/fabric/scripts/fabric-samples/test-network go: downloading github.com/hyperledger/fabric-contract-api-go v1.1.0 go: downloading github.com/hyperledger/fabric-chaincode-go v0.0.0-20200424173110-d7076418f212 go: downloading github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e go: downloading github.com/stretchr/testify v1.5.1 go: downloading github.com/golang/protobuf v1.3.2 go: downloading google.golang.org/grpc v1.23.0 go: downloading github.com/xeipuuv/gojsonschema v1.2.0 go: downloading github.com/go-openapi/spec v0.19.4 go: downloading github.com/gobuffalo/packr v1.30.1 go: downloading github.com/davecgh/go-spew v1.1.1 go: downloading github.com/pmezard/go-difflib v1.0.0 go: downloading gopkg.in/yaml.v2 v2.2.8 go: downloading google.golang.org/genproto v0.0.0-20180831171423-11092d34479b go: downloading golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 go: downloading github.com/go-openapi/jsonpointer v0.19.3 go: downloading github.com/go-openapi/jsonreference v0.19.2 go: downloading github.com/go-openapi/swag v0.19.5 go: downloading github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 go: downloading github.com/gobuffalo/envy v1.7.0 go: downloading github.com/gobuffalo/packd v0.3.0 go: downloading golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542 go: downloading github.com/PuerkitoBio/purell v1.1.1 go: downloading github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e go: downloading github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f go: downloading github.com/joho/godotenv v1.3.0 go: downloading github.com/rogpeppe/go-internal v1.3.0 go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 go: downloading golang.org/x/text v0.3.2 /home/lj/fabric/scripts/fabric-samples/test-network Finished vendoring Go dependencies + peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0 + res=0 Chaincode is packaged Installing chaincode on peer0.org1... Using organization 1 + peer lifecycle chaincode install basic.tar.gz + res=0 2022-05-29 14:14:08.299 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:


