How to use a chaincode that's not on github?

前端 未结 2 972
臣服心动
臣服心动 2021-01-14 12:59

I have developed a chaincode using this and now that I know that it works I want to test it in a network with multiple nodes.

Where should I put my chaincode so that

相关标签:
2条回答
  • 2021-01-14 13:44

    Usually, I put my own chaincode on github. Then:

    $ docker run -i -t hyperledger/fabric-peer /bin/bash
    
    # git clone https://github.com/xxx/myOwnChaincode.git; exit
    
    $ docker commit -m 'mm' -a 'aa'  containerId xxx/fabric-peer
    

    Finally, the docker image "xxx/fabric-peer" contains self-programmed chaincodes. For all these steps, I write a shell script and it works so fine for me.

    0 讨论(0)
  • 2021-01-14 14:04

    There are two options:

    1. If you are not using a docker image to start your nodes then you should deploy the chaincode by specifying a fully qualified path, in other words, you should set the parameter when deploying:

      -p /home/user/my/awesome/chaincode

    2. If you are running your nodes/peers in a docker image (like the instructions you are following to setup a development network) then you have two options:

      The first one is to put your chaincode inside a folder in the path $GOPATH/src/github.com/hyperledger/fabric/peer. Then you can build your image (go test -run BuildImage_Peer).

      Now the docker image will have the chaincode in its filesystem (you can check it by navigating in it by using docker run --rm -it -e CORE_VM_ENDPOINT=http://172.17.0.1:2375 -e CORE_PEER_ID=vp0 -e CORE_PEER_ADDRESSAUTODETECT=true hyperledger-peer /bin/bash).

      Finally, to deploy the chaincode you have to set the path (parameter -p) to the folder that contains your chaincode, relative to $GOPATH/src/. This path would be: github.com/hyperledger/fabric/peer/yourfolderwiththecc.

      The second option is similar (not tested yet), but it uses a shared filesystem between docker and vagrant to access the chaincode. The idea is to run the docker with something like -v local-dev:localdev, so that local-dev folder in the docker image is linked to vagrant's local-dev folder (where you should put your chaincode) and with -e GOPATH=/local-dev you set the GOPATH so that the relative path can start from the /local-dev folder.

    Observation: the path with github.com might be confusing because it seems that it is getting the chaincode from Github, but it is just the folder name.

    Important: to deploy a chaincode, only one peer needs to have available the chaincode file (the one where the deploy is sent), as the consensus is responsible of broadcasting the chaincode.

    Credits to @ghaskins for his help figuring out how to do it.

    0 讨论(0)
提交回复
热议问题