return type of chaincode functions using EvaluateTransaction


Nikos Karamolegkos
 

As I can see this functions returns car which is type *Car after unmarshal. Given that the EvaluateTransaction returns bytes can I bypass unmarshal and return carAsBytes from QueryCar  (i.e return type []byte) to the client and let the client do whatever needs? (unmarshal or no).

I am asking because I have tried that and it hadn't worked.

-- 
Nikos Karamolegkos
R & D engineer at ICS-FORTH
Telecommunications and Networks Lab (TNL)


Matthew White
 

Hello – you can return bytes if you wish;

 

What errors did you encounter?

 

Thanks Matthew

 

From: fabric@... <fabric@...> On Behalf Of Nikos Karamolegkos
Sent: 27 September 2022 11:51
To: fabric <fabric@...>
Subject: [EXTERNAL] [Hyperledger Fabric] return type of chaincode functions using EvaluateTransaction

 

As I can see this functions returns car which is type *Car after unmarshal. Given that the EvaluateTransaction returns bytes can I bypass unmarshal and return carAsBytes from QueryCar  (i. e return type ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍

ZjQcmQRYFpfptBannerStart

This Message Is From an External Sender

This message came from outside your organization.

ZjQcmQRYFpfptBannerEnd

As I can see this functions returns car which is type *Car after unmarshal. Given that the EvaluateTransaction returns bytes can I bypass unmarshal and return carAsBytes from QueryCar  (i.e return type []byte) to the client and let the client do whatever needs? (unmarshal or no).

I am asking because I have tried that and it hadn't worked.

-- 
Nikos Karamolegkos
R & D engineer at ICS-FORTH
Telecommunications and Networks Lab (TNL)

Unless otherwise stated above:

IBM United Kingdom Limited
Registered in England and Wales with number 741598
Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU


Nikos Karamolegkos
 

the
evaluateResult, err := contract.EvaluateTransaction("GetAirQNomVals")
returns Invalid type. Expected: array, given: string - Transaction processing for endorser


func (s *smartContract) GetAirQNomVals(ctx contractapi.TransactionContextInterface) ([]byte, error) {
resultsIterator, err := ctx.GetStub().GetState("NominalValuesState")

if err != nil {
return nil, fmt.Errorf("failed to read from world state. %s", err.Error())
}

if resultsIterator == nil {
return nil, fmt.Errorf("%s does not exist", "NominalValuesState")
}


return resultsIterator, nil
}


Nikos Karamolegkos
 

based on this I have to
func (s *smartContract) GetAirQNomVals(ctx contractapi.TransactionContextInterface) (string, error) {
resultsIterator, err := ctx.GetStub().GetState("NominalValuesState")

if err != nil {
return "", fmt.Errorf("failed to read from world state. %s", err.Error())
}

if resultsIterator == nil {
return "", fmt.Errorf("%s does not exist", "NominalValuesState")
}

return string(resultsIterator), nil
}