fabric链码查询
peer chaincode query
常用参数
-n --name chaincode的名字
-C --channelID 当前命令运行的通道,默认testchainid
-c --ctor JSON格式的构造参数,默认"{}"
执行一下
peer chaincode query -n abccc -C abcchannel -c '{"Args":["query", "a"]}'
peer chaincode query
-n abccc
-C abcchannel
-c '{"Args":["query", "a"]}'
我们查询一下然后看下结果
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -n abccc -C abcchannel -c '{"Args":["query", "a"]}'
100
然后我们再查询一下b
peer chaincode query -n abccc -C abcchannel -c '{"Args":["query", "b"]}'
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -n abccc -C abcchannel -c '{"Args":["query", "b"]}'
200
然后我们要通过客户端切换peer节点
```shell
$ docker exec -it cli bash
# 客户端默认会连接某一个节点
CORE_PEER_ADDRESS=peer0.orggo.abc.com:7051
# 对客户端进行操作, 操作的是默认连接的节点
```
```shell
看docker-compose 配置文件中关于 客户端容器的设置 -> 环境变量
CORE_PEER_ADDRESS=peer0.orggo.abc.com:7051 # 客户端连接的peer节点
CORE_PEER_LOCALMSPID=OrgGoMSP
CORE_PEER_TLS_ENABLED=true
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer0.orggo.abc.com/tls/server.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer0.orggo.abc.com/tls/server.key
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer0.orggo.abc.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/users/[email protected]/msp
`
go组织的peer0
```shell
CORE_PEER_ADDRESS=peer0.orggo.abc.com:7051
CORE_PEER_LOCALMSPID=OrgGoMSP
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/users/[email protected]/msp
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer0.orggo.abc.com/tls/ca.crt
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer0.orggo.abc.com/tls/server.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer0.orggo.abc.com/tls/server.key
```
go组织的peer1
```shell
CORE_PEER_ADDRESS=peer1.orggo.abc.com:7051
CORE_PEER_LOCALMSPID=OrgGoMSP
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/users/[email protected]/msp
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer1.orggo.abc.com/tls/ca.crt
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer1.orggo.abc.com/tls/server.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer1.orggo.abc.com/tls/server.key
```
cpp组织的peer0
```shell
CORE_PEER_ADDRESS=peer0.orgcpp.abc.com:7051
CORE_PEER_LOCALMSPID=OrgCppMSP
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/users/[email protected]/msp
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/peers/peer0.orgcpp.abc.com/tls/ca.crt
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/peers/peer0.orgcpp.abc.com/tls/server.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/peers/peer0.orgcpp.abc.com/tls/server.key
```
cpp组织的peer1
```shell
CORE_PEER_ADDRESS=peer1.orgcpp.abc.com:7051
CORE_PEER_LOCALMSPID=OrgCppMSP
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/users/[email protected]/msp
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/peers/peer1.orgcpp.abc.com/tls/ca.crt
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/peers/peer1.orgcpp.abc.com/tls/server.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orgcpp.abc.com/peers/peer1.orgcpp.abc.com/tls/server.key
```
打包一下
peer chaincode package -n abccc -v 1.0 -p github.com/chaincode mycc.out
1.peer channel list
2.peer channel join -b abcchannel.block
3.peer chaincode install mycc.out
4.
看下流程和结果
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# ls
channel-artifacts crypto abcchannel.block
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode package -n abccc -v 1.0 -p github.com/chaincode mycc.out
2019-04-15 04:30:21.659 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-04-15 04:30:21.659 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# ls
channel-artifacts crypto abcchannel.block mycc.out
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_ADDRESS=peer1.orggo.abc.com:7051
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_LOCALMSPID=OrgGoMSP
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/users/[email protected]/msp
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer1.orggo.abc.com/tls/ca.crt
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer1.orggo.abc.com/tls/server.crt
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/orggo.abc.com/peers/peer1.orggo.abc.com/tls/server.key
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel join -b abcchannel.block
2019-04-15 04:31:06.586 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Error: proposal failed (err: bad proposal response 500: Cannot create ledger from genesis block, due to LedgerID already exists)
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer channel list
2019-04-15 04:31:14.517 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Channels peers has joined:
abcchannel
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# ls
channel-artifacts crypto abcchannel.block mycc.out
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install mycc.out
2019-04-15 04:31:23.986 UTC [chaincodeCmd] install -> INFO 001 Installed remotely response:
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer#
然后查询一下
root@44e649277a71:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -n abccc -C abcchannel -c '{"Args":["query", "b"]}'
200