Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperledger Fabric altering fabcar example

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/[email protected]/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: ['']
};
like image 883
Chris Fricke Avatar asked Jan 04 '23 15:01

Chris Fricke


1 Answers

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
like image 143
Artem Barger Avatar answered Jan 16 '23 20:01

Artem Barger