记录自己Fabric学习中peer命令的常见操作

The peer command has five different subcommands, each of which allows administrators to perform a specific set of tasks related to a peer.

  • peer chaincode [option] [flags]
  • peer channel [option] [flags]
  • peer logging [option] [flags]
  • peer node [option] [flags]
  • peer version [option] [flags]
  1. The peer chaincode command allows administrators to perform chaincode related operations on a peer, such as installing, instantiating, invoking, packaging, querying, and upgrading chaincode.

peer chaincode command参考

  • install 安装
#安装链码,-n链码名 -v版本 -p链码路径
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/mycc/
  • instantiate 实例化
#导入环境变量
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
#使用--tls和--cafile全局标志在启用TLS的网络中实例化链码,并指定背书策略-P
peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
  • invoke 调用
#在两个peer节点上的mychannel通道上调用链码使a向b转10个单位
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 -c '{"Args":["invoke","a","b","10"]}'
  • list 如果指定通道,则在通道中获取实例化的链码,或者在peer上获取已安装的链码
#列出在peer节点上安装的链码(默认peer0.org1)
peer chaincode list --installed
#列出在通道上实例化的链码
peer chaincode list --instantiated -C mychannel
  • package 将指定的链码打包到部署规范中
#该命令打包了版本为1.1的名为mycc的链代码,-s创建了链代码部署规范,-S使用本地MSP对软件包进行签名,并将其输出为ccpack.out
peer chaincode package ccpack.out -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -v 1.1 -s -S
  • query 查询
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
  • signpackage 对指定的链码包签名
#该命令接受现有的已签名程序包,并创建一个新的程序包,并在其中附加本地MSP的签名
peer chaincode signpackage ccwith1sig.pak ccwith2sig.pak
  • upgrade 升级
#导入环境变量
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
#使用--tls和--cafile全局标志在启用TLS的网络中实例化链码
peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.2 -c '{"Args":["init","a","100","b","200","c","300"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
  1. The peer channel command allows administrators to perform channel related operations on a peer, such as joining a channel or listing the channels to which a peer is joined.

peer channel command参考

  • create 创建一个通道并将创世块写入文件
#创建一个通道mychannel1,该通道由文件./mychannel1.tx中包含的配置事务定义。 在orderer.example.com:7050上使用orderer,并使用--tls和--cafile全局标志(--cafile:当前orderer节点pem格式的tls(安全传输层协议)证书文件)
peer channel create -o orderer.example.com:7050 -c mychannel1 -f ./channel-artifacts/mychannel1.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
#返回块0,指示已成功创建通道
  • fetch 提取指定的块,将其写入文件。
#使用最新选项newest检索最新的频道块,并将其存储在文件夹channel-artifacts下的new.pb文件中
peer channel fetch newest -c mychannel channel-artifacts/new.pb --orderer orderer.example.com:7050 

#使用(块号)选项检索特定的块(在本例中为16号块)并将其存储在默认块文件中。
peer channel fetch 16  -c mychannel --orderer orderer.example.com:7050
#您可以看到检索到的块是数字16,并且该信息已写入默认文件mychannel_16.block。

#对于配置块configuration blocks,可以使用configtxlator命令对块文件进行解码。用户事务块transaction blocks也可以被解码,但是必须编写用户程序来执行此操作。

  • getinfo 获取指定通道的区块链信息。 需要’-c’指定通道名
#获取有关通道mychannel的本地peer的信息
peer channel getinfo -c mychannel
#(区块的最新高度,hash值)
  • join 将peer节点加入通道
#将peer加入文件./mychannel.genesis.block所标识的创世块中定义的通道,在此示例中,该通道块先前是由peer通道fetch命令检索的
peer channel join -b ./mychannel.genesis.block
  • list 列出当前peer节点加入的通道
peer channel list
  • signconfigtx 在文件系统上对提供的configtx更新文件进行签名。 需要’-f’参数(由诸如configtxgen之类的工具生成的配置事务文件,用于提交给orderer)
#签署文件./updatechannel.tx中定义的频道更新事务。 该示例列出了命令前后的配置事务文件
peer channel signconfigtx -f updatechannel.tx
  • update 签名并将提供的configtx更新文件发送到通道。需要’-f’,’-o’,’-c’参数(-f:由诸如configtxgen之类的工具生成的配置事务文件,用于提交给orderer)
#使用文件./updatechannel.tx中定义的配置事务更新通道mychannel。 使用IP地址orderer.example.com:7050上的orserer程序,将配置事务发送给通道中的所有peer,以更新其通道配置的副本。
peer channel update -c mychannel -f ./updatechannel.tx -o orderer.example.com:7050
  1. The peer version command displays the version information of the peer. It displays version, Commit SHA, Go version, OS/architecture, and chaincode information.
peer version

/*得到的信息如下
peer:
 Version: 1.4.0
 Commit SHA: d700b43
 Go version: go1.11.1
 OS/Arch: linux/amd64
 Chaincode:
  Base Image Version: 0.4.14
  Base Docker Namespace: hyperledger
  Base Docker Label: org.hyperledger.fabric
  Docker Namespace: hyperledger
*/
  1. The peer logging subcommand allows administrators to dynamically view and configure the log levels of a peer.

peer logging command参考

  • getlogspec 返回活动日志规范
#获取peer的活动日志规范
peer logging getlogspec
  • setlogspec 设置日志规范
#要设置peer的活动日志记录规范,其中以gossip和msp开头的记录器被设置为日志级别WARNING,而所有其他记录器的默认设置为日志级别INFO
peer logging setlogspec gossip=warning:msp=warning:info
  1. The peer node command allows an administrator to start a peer node, check the status of a peer, reset all channels in a peer to the genesis block, or rollback a channel to a given block number.

peer node command参考

  • start 启动与网络交互的节点
peer node start --peer-chaincodedev
#在chaincode开发模式下启动peer节点。 通常,链码容器由对等方启动和维护。 但是,在链码开发模式下,链码是由用户构建和启动的。在链代码开发阶段进行迭代开发时,此模式很有用。 
  • status 返回正在运行的节点的状态
peer node status
#status:STARTED
  • reset 将所有通道重置为创世块。 执行该命令时,peer必须处于脱机状态。 当peer在重置后启动时,它将从命令程序或另一peer接收以第一个块开头的块,以重建块存储和状态数据库。
peer node reset
#将peer中的所有通道重置为创世块,即通道中的第一个块。该命令还记录文件系统中每个通道的预设高度。请注意,在执行此命令时应停止peer进程。如果peer进程正在运行,此命令将检测到该错误并返回错误,而不是执行重置。当peer节点在执行重置后启动时,peer节点将为每个通道获取由reset命令删除的块(从其他peer节点或orderer处),并将这些块提交到重置前的高度。 在所有通道都达到预设的高度之前,peer将不会认可任何交易。
  • rollback 将通道回滚到指定的块号。 执行该命令时,peer必须处于脱机状态。 当peer在回滚后启动时,它将从命令程序或另一个peer接收从回滚中删除的块,以重建块存储和状态数据库。
peer node rollback -c mychannel -b 150
#将通道mychannel回滚到块号150。该命令还记录了通道mychannel在文件系统中的预滚回高度。请注意,在执行此命令时应停止peer进程。如果peer进程正在运行,此命令将检测到该错误并返回错误,而不是执行回滚。在执行回滚后启动peer时,peer将获取通道mychannel的块,这些块已被rollback命令(从其他peer或orderer)删除,并将这些块提交到预滚回的高度。在通道mychannel达到预滚回高度之前,peer不会认可任何通道的任何交易。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值