1. 程式人生 > >hyperledger fabric 測試(五)1.15私有資料

hyperledger fabric 測試(五)1.15私有資料

進入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/[email protected]/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/[email protected]/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"]}'