当前位置: 代码迷 >> 综合 >> hyperledger fabric 测试(五)1.15私有数据
  详细解决方案

hyperledger fabric 测试(五)1.15私有数据

热度:20   发布时间:2023-12-10 18:15:36.0

进入first-network文件夹:cd fabric-samples/first-network

删除启动网络的容器和镜像:./byfn.sh down

设置启动网络名称,启动数据库:./byfn.sh up -c mychannel -s couchdb

进入cli环境:docker exec -it cli bash

Peer0.Org1安装链码:peer chaincode install -n marblesp -v 1.0 -p github.com/chaincode/marbles02_private/go/

进入peer1.org1环境export CORE_PEER_ADDRESS=peer1.org1.example.com:7051:

Peer1.org1安装链码:peer chaincode install -n marblesp -v 1.0 -p github.com/chaincode/marbles02_private/go/

进入org2环境:export CORE_PEER_LOCALMSPID=Org2MSP

export PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt

export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp

进入peer0.org2环境:export CORE_PEER_ADDRESS=peer0.org2.example.com:7051

安装链码:peer chaincode install -n marblesp -v 1.0 -p github.com/chaincode/marbles02_private/go/

进入peer1.org2环境:export CORE_PEER_ADDRESS=peer1.org2.example.com:7051

安装链码:peer chaincode install -n marblesp -v 1.0 -p github.com/chaincode/marbles02_private/go/

引入联盟根证书: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

在通道实例化链码:peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n marblesp -v 1.0 -c '{"Args":["init"]}' -P "OR('Org1MSP.member','Org2MSP.member')" --collections-config  $GOPATH/src/github.com/chaincode/marbles02_private/collections_config.json

进入peer0.org1环境:

export CORE_PEER_ADDRESS=peer0.org1.example.com:7051

export CORE_PEER_LOCALMSPID=Org1MSP

export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

export PEER0_ORG1_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

初始化链码:peer chaincode invoke -o orderer.example.com:7050 --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 -C mychannel -n marblesp -c '{"Args":["initMarble","marble1","blue","35","tom","99"]}'

简单大理石存储函数:peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarble","marble1"]}'

查询大理石价格函数:peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarblePrivateDetails","marble1"]}

通过不断的交易来增加区块:peer chaincode invoke -o orderer.example.com:7050 --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 -C mychannel -n marblesp -c '{"Args":["transferMarble","marble2","joe"]}'

peer chaincode invoke -o orderer.example.com:7050 --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 -C mychannel -n marblesp -c '{"Args":["transferMarble","marble2","tom"]}

peer chaincode invoke -o orderer.example.com:7050 --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 -C mychannel -n marblesp -c '{"Args":["transferMarble","marble2","jerry"]}'

其blockToLive设置为3,其在第4个区块生成后查询即消失:

peer chaincode query -C mychannel -n marblesp -c '{"Args":["readMarblePrivateDetails","marble1"]}'

  相关解决方案