fabric網絡搭建指南-基礎命令

第三部分:基礎命令

  1. 生成MSP證書
cryptogen generate --config=./crypto-config.yaml
  1. 生成排序服務創世區塊
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
  1. 生成通道配置創世區塊
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}
  1. 定義組織錨節點
// 組織Org1的錨節點
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
// 組織Org2的錨節點
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
  1. 建立並加入通道
  • 建立通道
peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./channel-artifacts/channel.tx --tls ${CORE_PEER_TLS_ENABLED} --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  • 可能會遇到的錯誤(以及解決方案)
    錯誤提示以下:
cli錯誤提示:
Error: got unexpected status: FORBIDDEN -- Failed to reach implicit threshold of 1 sub-policies, required 1 remaining: permission denied

容器內部提示:
UTC [cauthdsl] deduplicate -> ERRO 014 Principal deserialization failure (the supplied identity is not valid: x509: certificate signed by unknown authority (possibly because of "x509: ECDSA verification failure" while trying to verify candidate authority certificate "ca.org1.example.com")) for identity

錯誤緣由:因爲啓動過網絡而且更新了證書,在沒有刪除乾淨的環境中啓動複用的以前的volume,因此致使證書認證失敗。git

解決方案:github

$ docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml down --volumes
Stopping cli                    ... done
Stopping peer1.org2.example.com ... done
Stopping peer0.org2.example.com ... done
Stopping orderer.example.com    ... done
Stopping peer0.org1.example.com ... done
Stopping peer1.org1.example.com ... done
Removing cli                    ... done
Removing peer1.org2.example.com ... done
Removing peer0.org2.example.com ... done
Removing orderer.example.com    ... done
Removing peer0.org1.example.com ... done
Removing peer1.org1.example.com ... done
Removing network net_byfn
Removing volume net_peer0.org2.example.com
Removing volume net_peer1.org2.example.com
Removing volume net_peer1.org1.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_orderer.example.com
  • 加入通道
peer channel join -b mychannel.block
  • 查詢當前peer加入的通道列表
peer channel list
  1. 安裝和實例化鏈碼
  • 安裝鏈碼
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
  • 查看安裝的鏈碼列表
docker exec peer0.org1.example.com ls /var/hyperledger/production/chaincodes
  • 鏈碼實例化
peer chaincode instantiate -o orderer.example.com:7050 --tls ${CORE_PEER_TLS_ENABLED} --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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR('Org1MSP.member','Org2MSP.member')"
  1. 鏈碼查詢
peer chaincode query -C $CHANNEL_NAME -nmycc -c '{"Args":["query","a"]}'
peer chaincode query -C $CHANNEL_NAME -nmycc -c '{"Args":["query","b"]}'
  1. 鏈碼調用
peer chaincode invoke -oorderer.example.com:7050  --tls ${CORE_PEER_TLS_ENABLED}--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 ${CHANNEL_NAME} -n mycc -c'{"Args":["invoke","a","b","10"]}'
相關文章
相關標籤/搜索