且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Hyperledger Fabric更改fabcar示例

更新时间:2022-10-15 08:17:26

我建议两种可能的方法:


  1. 使用新名称或版本增加的链代码安装

相同名称,但已更新版本:

 对等链代码安装-n fabcar -v 2.0 -p github.com/fabcar 

或相同版本,但新名称:

 对等链代码安装-n票-v 1.0 -p github.com/fabcar 




  • 清理旧的链式代码容器并再次安装备用链式代码的更新版本。

  • 您可以使用以下命令删除旧的链式代码容器映像:

      docker images | grep fabcar | awk‘{print $ 2}’| docker rmi 


    I've been working through the fabcar example and have it running it perfectly when no alterations have happened. What I'm trying to do is update the fabcar.go code to add more fields and simply play around w/ the example, however my docker images aren't updating w/ the correct code.

    To install the chaincode, this command is run on the cli container:

    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 github.com/fabcar
    

    The cli container has set this volume:

    ./../chaincode/:/opt/gopath/src/github.com/
    

    however, after code/go updates (I've actually changed it from Car to a Ticket object with entirely new fields and updated all relevant chain commands to reflect), teardown, then start up again I still am seeing all the old fields.

    What am I missing here?

    Here's a snippet of the code changing to tickets on the "Invoke" function

    func (s *SmartContract) Invoke(APIstub shim.ChaincodeStubInterface) sc.Response {
    
        // Retrieve the requested Smart Contract function and arguments
        function, args := APIstub.GetFunctionAndParameters()
        // Route to the appropriate handler function to interact with the ledger appropriately
        if function == "queryTicket" {
            return s.queryTicket(APIstub, args)
        } else if function == "initLedger" {
            return s.initLedger(APIstub)
        } else if function == "createTicket" {
            return s.createTicket(APIstub, args)
        } else if function == "queryAllTickets" {
            return s.queryAllTickets(APIstub)
        } else if function == "sellTicket" {
            return s.sellTicket(APIstub, args)
        }
    
        return shim.Error("Invalid Smart Contract function name.")
    }
    

    But doing this I simply receive the message "Invalid Smart Contract function name." when calling w/ the following:

    const request = {
        chaincodeId: options.chaincode_id,
        txId: transaction_id,
        fcn: 'queryAllTickets',
        args: ['']
    };
    

    I would suggest two possible approaches:

    1. Install chaincode with new name or incremented version

    Same name, but updated version:

    peer chaincode install -n fabcar -v 2.0 -p github.com/fabcar
    

    or same version, but new name:

    peer chaincode install -n tickets -v 1.0 -p github.com/fabcar
    

    1. Cleanup old chaincode container and install updated version of alternated chaincode over again.

    You can use following command to remove old chaincode container image:

    docker images | grep fabcar | awk '{print $2}' | docker rmi