// Query callback representing the query of a chaincode func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) { if function == "uuid" { return t.getUUID(stub, args) } else if function != "query" { return nil, errors.New("Invalid query function name. Expecting \"query\"") } var A string // Entities var uuid string // Under which chaincode the state is stored var err error if len(args) != 2 { return nil, errors.New("Incorrect number of arguments. Expecting UUID and key to query") } uuid = args[0] A = args[1] // Get the state from the ledger Avalbytes, err := stub.GetStateUUID(A, uuid) if err != nil { jsonResp := "{\"Error\":\"Failed to get state for " + A + " from uuid " + uuid + "\"}" return nil, errors.New(jsonResp) } // If the amout is nil, shouldn't the query still be returned? /* if Avalbytes == nil { jsonResp := "{\"Error\":\"Nil amount for " + A + "\"}" return nil, errors.New(jsonResp) } */ jsonResp := "{\"Name\":\"" + A + "\",\"Amount\":\"" + string(Avalbytes) + "\"}" fmt.Printf("Query Response:%s\n", jsonResp) return Avalbytes, nil }