hyperledger中configtxlator工具使用

configtxlator 主要功能:

1、将系统所需要的配置文件在二进制格式和方便阅读编辑的JSON格式之间进行转换,方便用户更新通道的配置。
2、configtxlator工具自身是个比较简单的RESTful服务程序,启动后默认监听在7059端口。
    2.1 解码:(接口地址为)/protolator/decode/{msgName},支持POST操作,将二进制格式数据解码为Json格式,其中{msgName}需要指定Fabric中定义的对应Protobuf消息结构的名称。
    2.2 编码:(接口地址为)/protolator/encode/{msgName},支持POST操作,将Json格式的数据编码为二进制格式,其中{msgName}需要指定Protobuf消息类型名称
    2.3 计算配置更新量:/configtxlator/compute/update-from-configs,支持POST操作,计算两个配置(common.Config消息结构)之间的二进制格式更新量。

configtxlator 命令详解:

编码为Json格式:
# 将本地使用configtxgen生成的Orderer系统通道初始区块,转换为Json格式。
curl -X POST --data-binary @orderer_genesis.block http://127.0.0.1:7059/protolator/decode/common.Block > ./orderer_genesis.json
# 将channel.tx转换为channel.json
curl -X POST --data-binary @channel.tx http://127.0.0.1:7059/protolator/decode/common.Envelope > channel.json
编码为二进制格式:
curl -X POST --data-binary @./orderer_genesis.json http://127.0.0.1:7059/protolator/encode/common.Block > orderer_genesis_new.block
计算配置更新量:对于给定的两个配置(common.config结构),configtxlater还可以比对他们的不同,计算出跟新到配置时的更新量(common.ConfigUpdate结构)。
1、获取已创建的应用通道bussinesschannel的配置区块
    peer channel fetch config bussinesschannel.block -c bussinesschannel -o orderer:7050
2、将其转化为json格式
    curl -X POST --data-binary @bussinesschannel.block http://127.0.0.1:7059/protolator/decode/common.Block > ./bussinesschannel.json
3、取出config域(该文件中包括了common.Config结构相关数据)
    jq .data.data[0].payload.data.config bussinesschannel.json > bussinesschannel_config.json
4、对bussinesschannel_config.json文件中的配置项(如区块最大交易消息数Ordeer.values.Batch-Size.value.max_message_count或调整通道中组织等)进行修改,另存为bussinesschannel_config_new.json。并将源文件和修改后的文件转成二进制文件
    curl -X POST --data-binary @bussinesschannel_config.json http://127.0.0.1:7059/protolator/encode/common.Config > bussinesschannel_config.config
curl -X POST --data-binary @bussinesschannel_config_new.json http://127.0.0.1:7059/protolator/encode/common.Config > bussinesschannel_config_new.config
5、利用这两个文件,通过configtxlator提供的接口,计算出更新配置时的更新量信息,为common.ConfigUpdate结构的二进制文件。并根据二进制文件生成更新量的Json格式。
    curl -X POST -F original=@bussinesschannel_config.config -F updated=@bussinesschannel_config_new.config http://127.0.0.1:7059/configtxlator/compute/update-form-configs -F channel=bussinesschannel > config_update.config
    curl -X POST --data-binary @config_update.config http://127.0.0.1:7059/protolator/decode/common.ConfitUpdate > config_update.json
更新通道配置
通过计算更新量,可以得到common.ConfigUpdate结构的更新信息。而对通道配置进行更新时,还需要封装为common.Envelope结构的配置更新交易。因此需要将common.ConfigUpdate结构数据进行补全,补全后的文件命名为config_update_envelope.json。
补全命令:
    echo '{"payload":{"header":{"channel_header":{"channel_id":"bussinesschannel", "type":2}}, "data":{"config_update":'$(cat config_update.json)'}}}' > config_update_envelope.json
利用common.Envelope结构编码为二进制交易配置文件,利用它对应用通道进行更新。(注意:更新配置需要指定相应的权限(OderMSP的Admin身份)
    curl -X POST --data-binary @config_update_envelope.json http://127.0.0.1:7059/protolator/encode/common.Envelope > config_update_envelope.tx
    CORE_PEER_LOCALMSPID=OrdererMSP
    CORE_PEER_MSPCONFIGPATH=crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp
    peer channel update -o 127.0.0.1:7050 -f config_update_envelope.tx -c bussinesschannel
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值