1

I have a simple Invoke function that calls 2 methods depending upon arguments as shown below:

func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
fmt.Println("chaincode_custom Invoke")
function, args := stub.GetFunctionAndParameters()
if function == "addProduct"{
    return t.addProduct(stub, args)
} else if function == "addProccesingInput"{
    return t.addProccesingInput(stub, args)


return shim.Error("Invalid invoke function name.")

}

I am able to call addProduct method but when I call addProccesingInput method it gives me below error:

error: [client-utils.js]: sendPeersProposal - Promise is rejected: Error: chaincode error (status: 500, message: Invalid invoke function name.) at /home/test/Desktop/blockchain/xyz/node_modules/grpc/src/node/src/client.js:554:15 [2018-02-28 07:41:39.987] [ERROR] invoke-chaincode - invoke chaincode proposal was bad [2018-02-28 07:41:39.988] [DEBUG] invoke-chaincode - Failed to send Proposal and receive all good ProposalResponse [2018-02-28 07:41:39.991] [ERROR] invoke-chaincode - Failed to invoke chaincode. cause:Failed to send Proposal and receive all good ProposalResponse (node:114605) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 7): Error: Failed to invoke chaincode. cause:Failed to send Proposal and receive all good ProposalResponse

Also see my below addProccesingInput method

func (t *SimpleChaincode) addProccesingInput(stub shim.ChaincodeStubInterface, args []string) pb.Response {

var err error

//Update Batch data
bAsBytes, err := stub.GetState(args[0])

var bch MilkProduct
err = json.Unmarshal(bAsBytes, &bch)
if err != nil {
    return shim.Error(err.Error())
}

bch.BatchStatus="In Process"
var tx Transaction

tx.Pasturization=args[1]
tx.Adulteration=args[2]
tx.Status="In Process"
tx.TransTime=time.Now().UTC().String()
tx.Temprature=args[3]
bch.Transactions = append(bch.Transactions, tx)

//Commit updates batch to ledger
btAsBytes, _ := json.Marshal(bch)
err = stub.PutState(bch.BatchId, btAsBytes) 
if err != nil {
    return shim.Error(err.Error())
}   

return shim.Success(nil)

}

I am using Fabric 1.1 Alfa With Node SDK

Atif
  • 226
  • 3
  • 15

0 Answers0