I am writing a chaincode to run on fabric, and this is code piece of 'fabcar.go', the sample of fabric chaincode.
I notice that I can pass a []string parameters from my java application using fabric-java-sdk, but I have problems when I try to pass some []byte parameters form my application.
I ve tried other funcs like
func (stub *ChaincodeStub) GetArgs() [][]byte
func (stub *ChaincodeStub) GetArgsSlice() ([]byte, error)
func (stub *ChaincodeStub) GetBinding() ([]byte, error)
but still do not know how to do it.
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 == "queryCar" {
return s.queryCar(APIstub, args)
...
Did I miss anything or it's not supported now? help me Please!
Turns out to be that all args are passed in type of [][]byte to chaincode. In the definition is
args [][]byte
in
type ChaincodeStub struct {
TxID string
ChannelId string
chaincodeEvent *pb.ChaincodeEvent
args [][]byte
handler *Handler
signedProposal *pb.SignedProposal
proposal *pb.Proposal
// Additional fields extracted from the signedProposal
creator []byte
transient map[string][]byte
binding []byte
decorations map[string][]byte
}
It's just the function GetFunctionAndParameters() wrapper those bytes to string.
// GetFunctionAndParameters documentation can be found in interfaces.go
func (stub *ChaincodeStub) GetFunctionAndParameters() (function string, params []string) {
allargs := stub.GetStringArgs()
function = ""
params = []string{}
if len(allargs) >= 1 {
function = allargs[0]
params = allargs[1:]
}
return
}
the returned value 'function' is actually string(allargs[0]), and the rest of the args will be in allargs[1:].