1. 程式人生 > >Fabric智慧合約編譯與測試環境搭建

Fabric智慧合約編譯與測試環境搭建

1.建立docker-compose-dev.yaml
membersrvc:
  image: hyperledger/fabric-membersrvc
  ports:
    - "7054:7054"
  command: membersrvc
vp0:
  image: hyperledger/fabric-peer
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp0
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=false
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
  links:
    - membersrvc
  command: sh -c "sleep 5; peer node start --peer-chaincodedev"
  
  
2.啟動節點
docker-compose -f docker-compose-dev.yaml up




3.進入節點
docker exec -it pbft_vp0_1 bash


4.進入需要編譯的智慧合約檔案目錄,如下示例
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02


5.進行編譯
go build   //編譯程式碼,生成chaincode_example02可執行程式。編譯成功將不顯示任何資訊,失敗會顯示失敗資訊


6.釋出合約
CORE_CHAINCODE_ID_NAME=mycc01 CORE_PEER_ADDRESS=172.17.0.3:7051 ./chaincode_example02   //釋出chaincode,併為其註冊一個名稱CORE_CHAINCODE_ID_NAME。如果釋出成功會在列印資訊中顯示[shim] DEBU : Received REGISTERED, ready for invocations




7.進行正常合約的init,invoke,query操作
peer chaincode deploy -u jim -n mycc -c '{"Args": ["init", "a","100", "b", "200"]}'