12.Fabric对Peer操作

版权声明:忠于祖国,忠于人民 https://blog.csdn.net/boss2967/article/details/84205088

陈述

主要讲Peer操作命令

创建通道

$ peer channel create [flags], 常用参数为:
	`-o, --orderer: orderer节点的地址
	`-c, --channelID: 要创建的通道的ID, 必须小写, 在250个字符以内
	`-f, --file: 由configtxgen 生成的通道文件, 用于提交给orderer
	-t, --timeout: 创建通道的超时时长, 默认为5s
	`--tls: 通信时是否使用tls加密
	`--cafile: 当前orderer节点pem格式的tls证书文件, 要使用绝对路径.
# orderer节点pem格式的tls证书文件路径参考: 
crypto-config/ordererOrganizations/ydqy.com/orderers/orderer.ydqy.com/msp/tlscacerts/tlsca.ydqy.com-cert.pem
# example
$ peer channel create -o orderer节点地址:端口 -c 通道名 -f 通道文件 --tls true --cafile orderer节点pem格式的证书文件
	- orderer节点地址: 可以是IP地址或者域名
	- orderer节点监听的是7050端口
$ peer channel create -o orderer.ydqy.com:7050 -c ydqychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/ydqy.com/msp/tlscacerts/tlsca.ydqy.com-cert.pem
# 在当前工作目录下生成一个文件: 通道名.block, 本例: ydqychannel.block
$ ls
channel-artifacts  crypto  `ydqychannel.block` --> 生成的文件

加入通道

$ peer channel join[flags], 常用参数为:
	`-b, --blockpath: 通过 peer channel create 命令生成的通道文件 
# example
$ peer channel join -b 生成的通道block文件
$ peer channel join -b ydqychannel.block 

更新锚节点

$ peer channel update [flags], 常用参数为:
	`-o, --orderer: orderer节点的地址
	`-c, --channelID: 要创建的通道的ID, 必须小写, 在250个字符以内
	`-f, --file: 由configtxgen 生成的组织锚节点文件, 用于提交给orderer
	`--tls: 通信时是否使用tls加密
	`--cafile: 当前orderer节点pem格式的tls证书文件, 要使用绝对路径.
# orderer节点pem格式的tls证书文件路径参考: 
crypto-config/ordererOrganizations/ydqy.com/orderers/orderer.ydqy.com/msp/tlscacerts/tlsca.ydqy.com-cert.pem
# example
$ peer channel update -o orderer节点地址:端口 -c 通道名 -f 锚节点更新文件 --tls true --cafile orderer节点pem格式的证书文件

安装链码

$ peer chaincode install [flags], 常用参数为:
	-c, --ctor: JSON格式的构造参数, 默认是"{}"
	`-l, --lang: 编写chaincode的编程语言, 默认值是 golang
	`-n, --name: chaincode的名字
	`-p, --path: chaincode源代码的目录, 从 $GOPATH/src 路径后开始写
	`-v, --version: 当前操作的chaincode的版本, 适用这些命令install/instantiate/upgrade
# example
$ peer chaincode install -n 链码的名字 -v 链码的版本 -l 链码的语言 -p 链码的位置
	- 链码名字自己起
	- 链码的版本, 自己根据实际情况指定
$ peer chaincode install -n testcc -v 1.0 -l golang -p github.com/chaincode

链码初始化

$ peer chaincode instantiate [flags], 常用参数为:
	`-C,--channelID:当前命令运行的通道,默认值是“testchainid"。
	`-c, --ctor:JSON格式的构造参数,默认值是“{}"
	`-l,--lang:编写Chaincode的编程语言,默认值是golang
	`-n,--name:Chaincode的名字。
	`-P,--policy:当前Chaincode的背书策略。
	`-v,--version:当前操作的Chaincode的版本,适用于install/instantiate/upgrade等命令
	`--tls: 通信时是否使用tls加密
	`--cafile: 当前orderer节点pem格式的tls证书文件, 要使用绝对路径.
# example
# -c '{"Args":["init","a","100","b","200"]}' 
# -P "AND ('OrgGoMSP.member', 'OrgCppMSP.member')"
$ peer chaincode instantiate -o orderer节点地址:端口 --tls true --cafile orderer节点pem格式的证书文件 -C 通道名称 -n 链码名称 -l 链码语言 -v 链码版本 -c 链码Init函数调用 -P 背书策略
$ peer chaincode instantiate -o orderer.ydqy.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/ydqy.com/msp/tlscacerts/tlsca.ydqy.com-cert.pem -C ydqychannel -n testcc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('OrgGoMSP.member', 'OrgCppMSP.member')"

查询

$ peer chaincode query [flags], 常用参数为:
	`-n,--name:Chaincode的名字。
	`-C,--channelID:当前命令运行的通道,默认值是“testchainid"
	`-c, --ctor:JSON格式的构造参数,默认值是“{}"
	-x,--hex:是否对输出的内容进行编码处理
	-r,--raw:是否输出二进制内容
	-t, --tid: 指定当前查询的编号
# example
# '{"Args":["query","a"]}'
$ peer chaincode query -C 通道名称 -n 链码名称 -c 链码调用

交易

$ peer chaincode invoke [flags], 常用参数为:
	`-o, --orderer: orderer节点的地址
	`-C,--channelID:当前命令运行的通道,默认值是“testchainid"
	`-c, --ctor:JSON格式的构造参数,默认值是“{}"
	`-n,--name:Chaincode的名字
	`--tls: 通信时是否使用tls加密
	`--cafile: 当前orderer节点pem格式的tls证书文件, 要使用绝对路径.
	`--peerAddresses: 指定要连接的peer节点的地址
	`--tlsRootCertFiles: 连接的peer节点的TLS根证书
# 连接的peer节点的TLS根证书查找路径参考:
/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.ydqy.com/peers/peer0.orggo.ydqy.com/tls/ca.crt
# example
# -c '{"Args":["invoke","a","b","10"]}'
$ peer chaincode invoke -o orderer节点地址:端口 --tls true --cafile orderer节点pem格式的证书文件 -C 通道名称 -n 链码名称 --peerAddresses 背书节点1:端口 --tlsRootCertFiles 背书节点1的TLS根证书    --peerAddresses 背书节点2:端口 --tlsRootCertFiles 背书节点2的TLS根证书 -c 交易链码调用

猜你喜欢

转载自blog.csdn.net/boss2967/article/details/84205088
今日推荐