Fabric命令手册

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

peer lifecycle chaincode approveformyorg

管理员可以使用peer lifecycle chaincode approveformyorg子命令 代表所在机构审批链码。

peer lifecycle chaincode approveformyorg是Hyperledger Fabric 2.0新增的命令。

使用方法

peer lifecycle chaincode approveformyorg [flags]

参数说明:

  • flags:可用标志,包括局部标志和全局标志

局部标志

peer lifecycle chaincode approveformyorg命令的可用局部标志如下:

    --channel-config-policy string   链码背书策略
-C, --channelID string               通道ID
    --collections-config string      collection文件路径
    --connectionProfile string       Fabric网络连接配置文件路径
-E, --endorsement-plugin string      用于此链码的背书插件名称
-h, --help                           命令的帮助信息
    --init-required                  是否需要调用链码的init方法
-n, --name string                    链码名称
    --package-id string              链码安装包标识ID
    --peerAddresses stringArray      要连接的peer节点
    --sequence int                   通道链码定义序列号,默认值:1
    --signature-policy string        签名策略
    --tlsRootCertFiles stringArray   如果启用了TLS,该标志用来声明所连接peer节点的TLS根证书    
-V, --validation-plugin string       用于此链码的验证插件名称
-v, --version string                 链码版本
    --waitForEvent                   是否等待peer节点交易提交成功,默认值:true
    --waitForEventTimeout duration   等待超时设置,默认值:30s

全局标志

peer lifecycle chaincode approveformyorg命令的可用全局标志如下:

    --cafile string                       PEM编码的CA证书文件路径
    --certfile string                     双向TLS通讯所需的PEM编码的X509证书文件路径
    --clientauth                          与排序节点的通讯是否启用双向TLS
    --connTimeout duration                客户端连接超时,默认值:3秒
-h, --help                                帮助信息
    --keyfile string                      双向TLS通讯所需的PEM编码的私钥文件
-o, --orderer string                      排序节点地址
    --ordererTLSHostnameOverride string   验证TLS连接时使用的排序节点主机名
    --tls                                 与排序节点通信时是否启用TLS

示例代码

一旦链码包在peer节点上安装后,就可以代表机构审批链码定义。 在链码定义中包含了链码治理的重要参数,包括链码名称、版本和 背书策略等 。

下面的命令使用peer lifecycle chaincode approveformyorg命令 在通道mychannel上审批名为mycc、版本1.0的链码定义,使用--package-id 标志传入链码包ID,使用--signature-policy标志声明链码的背书策略, 使用--init-required标志请求调用链码的Init方法:

export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

peer lifecycle chaincode approveformyorg  -o orderer.example.com:7050 \
  --tls --cafile $ORDERER_CA --channelID mychannel --name mycc \
  --version 1.0 --init-required \
  --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 \
  --sequence 1 --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')"

输出如下:

2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051

也可以使用--channel-config-policy标志引用通道配置中的策略作为链码背书策略。 默认的背书策略是Channel/Application/Endorsement

export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 \
  --tls --cafile $ORDERER_CA --channelID mychannel --name mycc \
  --version 1.0 --init-required \
  --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 \
  --sequence 1 --channel-config-policy Channel/Application/Admins

输出如下:

2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051