Fabric v2.3测试网络 - 在通道中启动链码返回结果分析

Fabric v2.3 测试网络,在通道中启动链码命令如下:

./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

 以上命令操作分为以下步骤:

1.  打包智能合约

2. 安装链码包

3. 通道中组织批准链码定义

4. 提交链码定义到通道中

要安装的智能合约asset-transfer-basic路径:

 若上面命令执行失败,可手动安装go依赖(第一次执行没有vendor目录)

[root@localhost fabric-samples]# cd asset-transfer-basic/chaincode-go/  #进入目录
[root@localhost chaincode-go]# ls                                       #查看目录内容
assetTransfer.go  chaincode  go.mod  go.sum                             #此时没有vendor目录
[root@localhost chaincode-go]# go env                                   #查看go环境配置
......
GOPROXY="https://proxy.golang.org,direct"                               #查看代理设置
......
[root@localhost chaincode-go]# go env -w GOPROXY=https://goproxy.cn     #更改代理
[root@localhost chaincode-go]# go mod vendor                            #安装依赖
[root@localhost chaincode-go]# ls                                       #查看目录内容
assetTransfer.go  chaincode  go.mod  go.sum  vendor                     #此时出现vendor目录

 以下是对在通道中启动链码命令的返回结果做了一下注释:

[root@localhost test-network]# ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

#上面命令中的 deployCC 是在peer0.org1.example.com和peer0.org2.example.com上安装asset-transfer-basic链码
# -ccn 链码名称
# -ccp 链码路径
# -ccl 链码语言

#在通道mychannel中部署链码
deploying chaincode on channel 'mychannel'
executing with the following
- CHANNEL_NAME: mychannel                                #通道名mychannel
- CC_NAME: basic                                         #链码名basic
- CC_SRC_PATH: ../asset-transfer-basic/chaincode-go      #源文件路径所在的位置
- CC_SRC_LANGUAGE: go                                    #脚本语言go
- CC_VERSION: 1.0                                        #链码版本1.0
- CC_SEQUENCE: 1                                         #链码被定义或者更新多少次的指数
- CC_END_POLICY: NA
- CC_COLL_CONFIG: NA
- CC_INIT_FCN: NA
- DELAY: 3
- MAX_RETRY: 5                                          #最多5次重试
- VERBOSE: false
Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go
/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/asset-transfer-basic/chaincode-go /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
Finished vendoring Go dependencies
# 命令:打包
# package 包名称
# --path  智能合约代码位置
# --lang  智能合约代码所用的语言
# --label 链码标签
+ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
+ res=0
#链码打包完成,包名为basic.tar.gz
Chaincode is packaged

#在节点peer0.org1.example.com上安装链码
Installing chaincode on peer0.org1...
Using organization 1
# 命令:安装链码
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
# 安装完成将会显示下面2行内容
2021-10-31 07:52:47.674 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nJbasic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda\022\tbasic_1.0" > 
2021-10-31 07:52:47.674 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda
#在节点peer0.org1.example.com上安装链码完成
Chaincode is installed on peer0.org1

#在节点peer0.org2.example.com上安装链码
Install chaincode on peer0.org2...
Using organization 2
# 命令:安装链码
+ peer lifecycle chaincode install basic.tar.gz
+ res=0
# 安装完成将会显示下面2行内容
2021-10-31 07:52:56.026 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nJbasic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda\022\tbasic_1.0" > 
2021-10-31 07:52:56.026 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: basic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda
#在节点peer0.org2.example.com上安装链码完成
Chaincode is installed on peer0.org2

Using organization 1
# 命令:查询节点安装的链码信息
+ peer lifecycle chaincode queryinstalled
+ res=0
# 查询结果(包含链码包ID与标签)
Installed chaincodes on peer:
Package ID: basic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda, Label: basic_1.0
Query installed successful on peer0.org1 on channel

Using organization 1
# 命令:链码在组织1中被同意
+ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda --sequence 1
# 结果:组织1已同意
+ res=0
2021-10-31 07:52:58.122 CST [chaincodeCmd] ClientWait -> INFO 001 txid [7300b8cf1e17b31f6697073c9a701ea1b5ba3be2534585e148a85cda3c4cf587] committed with status (VALID) at localhost:7051
Chaincode definition approved on peer0.org1 on channel 'mychannel'

Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
# 命令:查看通道成员是否同意了相同的链码定义
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
# 结果:组织1同意了链码定义,组织2未同意
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'

Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": false
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'

Using organization 2
# 命令:链码在组织2中被同意
+ peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name basic --version 1.0 --package-id basic_1.0:346b35825b660445a5d3da8b8902a4b20bbf10ee50832bdd81bb811bede62cda --sequence 1
# 结果:组织2已同意
+ res=0
2021-10-31 07:53:06.312 CST [chaincodeCmd] ClientWait -> INFO 001 txid [36b0d1b307ff094803049502fb37b4fde5ba194ab3d374889c3f0fde5b4e19c0] committed with status (VALID) at localhost:9051
Chaincode definition approved on peer0.org2 on channel 'mychannel'

Using organization 1
Checking the commit readiness of the chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org1, Retry after 3 seconds.
# 命令:查看通道成员是否同意了相同的链码定义
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
# 结果:组织1与组织2都同意了链码定义
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org1 on channel 'mychannel'

Using organization 2
Checking the commit readiness of the chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to check the commit readiness of the chaincode definition on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name basic --version 1.0 --sequence 1 --output json
+ res=0
{
	"approvals": {
		"Org1MSP": true,
		"Org2MSP": true
	}
}
Checking the commit readiness of the chaincode definition successful on peer0.org2 on channel 'mychannel'

Using organization 1
Using organization 2
# 命令:提交链码到通道 
+ peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --name basic --peerAddresses localhost:7051 --tlsRootCertFiles /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --version 1.0 --sequence 1
+ res=0
2021-10-31 07:53:14.562 CST [chaincodeCmd] ClientWait -> INFO 001 txid [b1849ec13ff3720f867351115988134fd36a01fac113950a6889112d9f67b688] committed with status (VALID) at localhost:7051
2021-10-31 07:53:14.566 CST [chaincodeCmd] ClientWait -> INFO 002 txid [b1849ec13ff3720f867351115988134fd36a01fac113950a6889112d9f67b688] committed with status (VALID) at localhost:9051
Chaincode definition committed on channel 'mychannel'

Using organization 1
Querying chaincode definition on peer0.org1 on channel 'mychannel'...
Attempting to Query committed status on peer0.org1, Retry after 3 seconds.
# 命令:查看已提交到通道的链码
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org1 on channel 'mychannel'

Using organization 2
Querying chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
# 命令:查看已提交到通道的链码
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org2 on channel 'mychannel'
Chaincode initialization is not required

在测试网络中一条命令可以将链码部署到通道中,可以查看官网 Deploying a smart contract to a channel 能看到详细步骤,与以上输出的内容类似

参考文档:

官网:使用Fabric的测试网络 — hyperledger-fabricdocs master 文档

在fabric2.2.1环境下部署智能合约_永慕无一的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值