本文接着上次创建第一个 Fabric 应用,简单介绍一下流程中各个文件的作用.
./startFabric.sh脚本中做的事情:
1.清除keystore
`rm -rf ./hfc-key-store`
2.启动 Fabric; 创建一个channel,并把peer添加到channel
- 在 ../basic-network中执行./start.sh
- 启动 Fabric: 在start.sh中
1 | docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb |
- 创建 channel:
1 | docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx |
- 把 peer 加入到刚刚创建的 channel 中:
1 | docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block |
3.启动CLI container,安装并实例化 chaincode
1 | docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n fabcar -v 1.0 -p "$CC_SRC_PATH" -l "$LANGUAGE" |
1 | docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$LANGUAGE" -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')" |
4.调用initLedger函数在 ledger 上生成10个cars
initLedger 函数定义在fabric-samples/chaincode/fabcar/go/fabcar.go 中
1 | docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[""]}' |
enrollAdmin.js做的事情:
注册 admin 用户
registerUser.js做的事情:
使用 admin 用户注册和登记用户 user1
query.js 做的事情:
查询 ledger
invoke.js做的事情:
更新 ledger