1、查看链信息
docker exec [container] peer channel getinfo -c [channel]
2、获取区块
docker exec [container] peer channel fetch [block-number] -c [channel]
docker cp [container]:/opt/gopath/src/github.com/hyperledger/fabric/peer/[channel]_[block-number].block ./
3、解析区块
configtxgen -inspectBlock [.block file] > [.json file]
4、在线json转yaml增强可读性
5、具体操作
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a30436865e7b dev-peer1.org2.example.com-mycc_1-40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f-861731f1fb7a4568b5c4b97482e41ca66bb213f7eb7dd7215635fd371dbc2745 "chaincode -peer.add…" 3 weeks ago Up 3 weeks dev-peer1.org2.example.com-mycc_1-40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f
444b5576a274 dev-peer0.org1.example.com-mycc_1-40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f-4c20bb52326acfebc71426bf7ea2fb83967081e00ca3fe383d464a100bc1177f "chaincode -peer.add…" 3 weeks ago Up 3 weeks dev-peer0.org1.example.com-mycc_1-40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f
aa1effe75da0 dev-peer0.org2.example.com-mycc_1-40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f-667281c6b976fdf7176d974a284355bf1ff337baaab300e5129540a948115e2c "chaincode -peer.add…" 3 weeks ago Up 3 weeks dev-peer0.org2.example.com-mycc_1-40aec53f0ee0193b0bd6b63862425298d90e9c3496a840bb54366b2fd66bd18f
ced25885e71c hyperledger/fabric-tools:latest "/bin/bash" 3 weeks ago Up 3 weeks cli
ad2020aac276 hyperledger/fabric-peer:latest "peer node start" 3 weeks ago Up 3 weeks 7051/tcp, 0.0.0.0:9051->9051/tcp peer0.org2.example.com
05a130964afe hyperledger/fabric-orderer:latest "orderer" 3 weeks ago Up 3 weeks 7050/tcp, 0.0.0.0:9050->9050/tcp orderer3.example.com
2f272d37e8ed hyperledger/fabric-peer:latest "peer node start" 3 weeks ago Up 3 weeks 0.0.0.0:7051->7051/tcp peer0.org1.example.com
eb81e4c876ab hyperledger/fabric-peer:latest "peer node start" 3 weeks ago Up 3 weeks 7051/tcp, 0.0.0.0:10051->10051/tcp peer1.org2.example.com
c1d8ea193de7 hyperledger/fabric-orderer:latest "orderer" 3 weeks ago Up 3 weeks 7050/tcp, 0.0.0.0:10050->10050/tcp orderer4.example.com
67bf597a94b0 hyperledger/fabric-orderer:latest "orderer" 3 weeks ago Up 3 weeks 0.0.0.0:7050->7050/tcp orderer.example.com
a11bea88c8d7 hyperledger/fabric-peer:latest "peer node start" 3 weeks ago Up 3 weeks 7051/tcp, 0.0.0.0:8051->8051/tcp peer1.org1.example.com
344b0198a5d1 hyperledger/fabric-orderer:latest "orderer" 3 weeks ago Up 3 weeks 7050/tcp, 0.0.0.0:8050->8050/tcp orderer2.example.com
956f5442f245 hyperledger/fabric-orderer:latest "orderer" 3 weeks ago Up 3 weeks 7050/tcp, 0.0.0.0:11050->11050/tcp orderer5.example.com
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ docker exec ad2020aac276 peer channel getinfo -c mychannel
2020-07-15 01:46:27.312 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Blockchain info: {"height":8,"currentBlockHash":"aI0erNK1YBmd8Bv52HbQf8ITvmPxleJFvc08D59xOOM=","previousBlockHash":"kX5TC35VnzuEH7C5SI0yzHAZ3K8umDX7byBTXEzGfFQ="}
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ docker exec ad2020aac276 peer channel fetch 0 -c mychannel
2020-07-15 01:47:49.069 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-07-15 01:47:49.198 UTC [cli.common] readBlock -> INFO 002 Received block: 0
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ sudo docker cp ad2020aac276:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel_0.block ./myblocks/
[sudo] password for wang:
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ cd myblocks/
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network/myblocks$ ls
mychannel_0.block
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network/myblocks$ configtxgen
2020-07-15 09:54:08.894 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ sudo chown -R wang:wang myblocks/
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ ls
base ccp-template.json configtx.yaml connection-org2.json crypto-config.yaml docker-compose-couch-org3.yaml docker-compose-etcdraft2.yaml myblocks scripts
byfn.sh ccp-template.yaml connection-org1.json connection-org2.yaml docker-compose-ca.yaml docker-compose-couch.yaml docker-compose-org3.yaml org3-artifacts
ccp-generate.sh channel-artifacts connection-org1.yaml crypto-config docker-compose-cli.yaml docker-compose-e2e-template.yaml eyfn.sh README.md
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network$ cd myblocks/
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network/myblocks$ ls
mychannel_0.block
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network/myblocks$ configtxgen -inspectBlock mychannel_0.block > mychannel_0.json
2020-07-15 09:58:16.831 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-07-15 09:58:16.831 CST [common.tools.configtxgen] doInspectBlock -> INFO 002 Inspecting block
2020-07-15 09:58:16.831 CST [common.tools.configtxgen] doInspectBlock -> INFO 003 Parsing genesis block
wang@wang:~/go/src/github.com/hyperledger/fabric-samples/first-network/myblocks$ ls
mychannel_0.block mychannel_0.json
0即创世块