11. Hyperledger Fabric 专题 - 获取区块
2020-03-09 本文已影响0人
furnace
获取区块并解码成 JSON 文件。先进入 Docker 容器 cli,获取区块并解码成 JSON 文件。然后在 linux 系统中把 Docker 容器中区块解码后的 JSON 文件拷贝出来。
Step 1. 进入 Docker 容器 cli
sudo docker exec -it cli bash
Step 2. 获取区块并解码成 JSON 文件
在 Docker 容器 cli 中执行下列命令,获取区块并解码成 JSON 文件。
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 && export CHANNEL_NAME=mychannel
echo $ORDERER_CA && echo $CHANNEL_NAME
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch oldest oldest.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch newest newest.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 0 block0.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 1 block1.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 2 block2.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 3 block3.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 4 block4.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 5 block5.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 6 block6.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 7 block7.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 8 block8.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel fetch 9 block9.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
configtxlator proto_decode --input channel-artifacts/genesis.block --type common.Block --output orderer_genesis_block.json
configtxlator proto_decode --input channel-artifacts/channel.tx --type common.Config --output channel_tx.json
configtxlator proto_decode --input channel-artifacts/Org1MSPanchors.tx --type common.Config --output Org1MSPanchors_tx.json
configtxlator proto_decode --input channel-artifacts/Org2MSPanchors.tx --type common.Config --output Org2MSPanchors_tx.json
configtxlator proto_decode --input mychannel.block --type common.Block --output mychannel.json
configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
configtxlator proto_decode --input oldest.pb --type common.Block --output oldest.json
configtxlator proto_decode --input newest.pb --type common.Block --output newest.json
configtxlator proto_decode --input block0.pb --type common.Block --output block0.json
configtxlator proto_decode --input block1.pb --type common.Block --output block1.json
configtxlator proto_decode --input block2.pb --type common.Block --output block2.json
configtxlator proto_decode --input block3.pb --type common.Block --output block3.json
configtxlator proto_decode --input block4.pb --type common.Block --output block4.json
configtxlator proto_decode --input block5.pb --type common.Block --output block5.json
configtxlator proto_decode --input block6.pb --type common.Block --output block6.json
configtxlator proto_decode --input block7.pb --type common.Block --output block7.json
configtxlator proto_decode --input block8.pb --type common.Block --output block8.json
configtxlator proto_decode --input block9.pb --type common.Block --output block9.json
Step 3. 将 Docker 容器 cli 中 JSON 文件拷贝到本地系统
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/orderer_genesis_block.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel_tx.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/Org1MSPanchors_tx.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/Org2MSPanchors_tx.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/orderer_genesis_block.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/config_block.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/oldest.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/newest.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block0.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block1.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block2.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block3.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block4.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block5.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block6.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block7.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block8.json .
sudo docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/block9.json .
项目源代码
项目源代码会逐步上传到 Github,地址为 https://github.com/windstamp。
Contributor
- Windstamp, https://github.com/windstamp