configtxgen
configtxgen
命令用来创建或查看通道配置相关的构件。生成的构件内容取决于
configtx.yaml文件。
命令语法
configtxgen
工具没有子命令,使用标志来完成不同的任务:
~$ configtxgen [flag]
可用标志如下:
-asOrg string
Performs the config generation as a particular organization (by name), only including values in the write set that org (likely) has privilege to set
-channelID string
The channel ID to use in the configtx
-configPath string
The path containing the configuration to use (if set)
-inspectBlock string
Prints the configuration contained in the block at the specified path
-inspectChannelCreateTx string
Prints the configuration contained in the transaction at the specified path
-outputAnchorPeersUpdate string
Creates an config update to update an anchor peer (works only with the default channel creation, and only for the first update)
-outputBlock string
The path to write the genesis block to (if set)
-outputCreateChannelTx string
The path to write a channel creation configtx to (if set)
-printOrg string
Prints the definition of an organization as JSON. (useful for adding an org to a channel manually)
-profile string
The profile from configtx.yaml to use for generation. (default "SampleInsecureSolo")
-version
Show version information
示例代码
下面的示例依据配置SampleSingleMSPSoloV1_1将通道orderer-system-channel的创世块写入文件genesis_block.pb:
~$ configtxgen -outputBlock genesis_block.pb -profile SampleSingleMSPSoloV1_1 -channelID orderer-system-channel
下面的示例依据配置Sam跑了Sin过了MSPChannelV1_1将通道创建交易写入文件create_chan_tx.pb:
~$ configtxgen -outputCreateChannelTx create_chan_tx.pb -profile SampleSingleMSPChannelV1_1 -channelID application-channel-1
下面的示例在屏幕以JSON格式显示名为genesis_block.pb的创世块的内容:
~$ configtxgen -inspectBlock genesis_block.pb
下面的示例在屏幕以JSON格式显示通道创建交易文件create_chan_tx.pb的内容:
~$ configtxgen -inspectChannelCreateTx create_chan_tx.pb
下面的示例基于configtx.yaml中的参数(例如MSPDir)构造一个组织定义,并在屏幕以 JSON格式显示:
~$ configtxgen -printOrg Org1
上述命令的输出对于通道重新配置任务(例如添加新的成员)非常有帮助。
下面的示例将配置更新交易写入文件anchor_peer_tx.pb,该交易为配置SampleSingleMSPChannelV1_1 中的组织Org1设置锚节点:
~$ configtxgen -outputAnchorPeersUpdate anchor_peer_tx.pb -profile SampleSingleMSPChannelV1_1 -asOrg Org1
配置文件
configtxgen的输出很大程度上受控于配置文件configtx.yaml的内容,该文件的搜索路径由 环境变量FABRIC_CFG_PATH指定。
配置文件configtx.yaml中的单个属性值可以使用环境变量覆盖,例如CONFIGTX_ORDERER_ORDERERTYPE=kafka。
对于很多configtxgen的操作,必须提供一个配置集(profile)名称。配置集是在单一配置文件中 表示多个类似的配置的一个方法。例如,其中一个配置集可能定义了一个包含3个组织的通道, 而另一个则可能定义包含了4个组织的通道。为了避免某些配置项重复地出现,configtx.yaml 依赖于标准YAML特性中的锚点和引用。配置中的基准部分被标记为锚点例如&OrdererDefault, 然后这部分可以使用<<: *OrdererDefaults这样的引用合并入一个配置集。
注意,当configtxgen运作于一个配置集时,环境变量不需要包含配置集前缀。例如不需要 指定CONFIGTX_PROFILE_SAMPLEINSECURESOLO_ORDERER_ORDERERTYPE,只要简单的省略配置集 部分,直接使用CONFIGTX_ORDERER_ORDERERTYPE即可。