Record common operations of peer commands in your Fabric learning

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 reference

  • 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 call
#在两个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 If you specify a channel, get the instantiated chain code in the channel, or get the installed chain code on the peer
#列出在peer节点上安装的链码(默认peer0.org1)
peer chaincode list --installed
#列出在通道上实例化的链码
peer chaincode list --instantiated -C mychannel
  • package Package the specified chain code into the deployment specification
#该命令打包了版本为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 signs the specified chaincode package
#该命令接受现有的已签名程序包,并创建一个新的程序包,并在其中附加本地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 reference

  • create creates a channel and writes the genesis block to a file
#创建一个通道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 extracts the specified block and writes it to the file.
#使用最新选项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 Get the blockchain information of the specified channel. Need to specify the channel name with'-c'
#获取有关通道mychannel的本地peer的信息
peer channel getinfo -c mychannel
#(区块的最新高度,hash值)
  • join join the peer node to the channel
#将peer加入文件./mychannel.genesis.block所标识的创世块中定义的通道,在此示例中,该通道块先前是由peer通道fetch命令检索的
peer channel join -b ./mychannel.genesis.block
  • list lists the channels joined by the current peer node
peer channel list
  • signconfigtx signs the provided configtx update file on the file system. Requires the'-f' parameter (configuration transaction file generated by tools such as configtxgen for submission to orderer)
#签署文件./updatechannel.tx中定义的频道更新事务。 该示例列出了命令前后的配置事务文件
peer channel signconfigtx -f updatechannel.tx
  • update Sign and send the provided configtx update file to the channel. Requires'-f','-o','-c' parameters (-f: configuration transaction file generated by tools such as configtxgen for submission to 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 reference

  • getlogspec returns the activity log specification
#获取peer的活动日志规范
peer logging getlogspec
  • setlogspec set log specification
#要设置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 reference

  • start starts the node that interacts with the network
peer node start --peer-chaincodedev
#在chaincode开发模式下启动peer节点。 通常,链码容器由对等方启动和维护。 但是,在链码开发模式下,链码是由用户构建和启动的。在链代码开发阶段进行迭代开发时,此模式很有用。 
  • status returns the status of the running node
peer node status
#status:STARTED
  • reset Reset all channels to genesis block. When executing this command, the peer must be offline. When a peer starts after reset, it will receive a block starting with the first block from the command program or another peer to rebuild the block storage and state database.
peer node reset
#将peer中的所有通道重置为创世块,即通道中的第一个块。该命令还记录文件系统中每个通道的预设高度。请注意,在执行此命令时应停止peer进程。如果peer进程正在运行,此命令将检测到该错误并返回错误,而不是执行重置。当peer节点在执行重置后启动时,peer节点将为每个通道获取由reset命令删除的块(从其他peer节点或orderer处),并将这些块提交到重置前的高度。 在所有通道都达到预设的高度之前,peer将不会认可任何交易。
  • rollback rolls back the channel to the specified block number. When executing this command, the peer must be offline. When the peer starts after the rollback, it will receive the blocks deleted from the rollback from the command program or another peer to rebuild the block storage and state database.
peer node rollback -c mychannel -b 150
#将通道mychannel回滚到块号150。该命令还记录了通道mychannel在文件系统中的预滚回高度。请注意,在执行此命令时应停止peer进程。如果peer进程正在运行,此命令将检测到该错误并返回错误,而不是执行回滚。在执行回滚后启动peer时,peer将获取通道mychannel的块,这些块已被rollback命令(从其他peer或orderer)删除,并将这些块提交到预滚回的高度。在通道mychannel达到预滚回高度之前,peer不会认可任何通道的任何交易。

Guess you like

Origin blog.csdn.net/qq_40169189/article/details/109169254
Recommended