I need to fetch transaction fields from a transaction in the ledger. I'm able to successfully query the transaction from ledger by invoking qscc chaincode but unable to parse the fetched transaction to retrieve transaction fields. I want to unmarshal the transaction content into a structure with all the fields. With the below code, I'm getting error "failed to unmarshal channel header". Appreciate your help.
chainCodeArgs := toChaincodeArgs("GetTransactionByID", "myc", tid)
response := stub.InvokeChaincode("qscc", chainCodeArgs, "myc")
fmt.Printf("****************")
if response.Status != shim.OK {
errStr := fmt.Sprintf("Failed to query chaincode. Got error: %s", response.Payload)
fmt.Printf(errStr)
return "", fmt.Errorf(errStr)
}
respStr := fmt.Sprintf("successfully queried qscc chaincode. Got response: %s", response.Payload)
fmt.Printf(respStr)
payload, err := utils.UnmarshalPayload(response.Payload)
if err != nil {
return "", fmt.Errorf("Error when unmarshalling transaction payload response")
}
fmt.Printf("++++++++++++++++++++++")
fmt.Println(payload)
if payload.Header == nil {
return "", fmt.Errorf("error getting txID from header: payload header is nil")
}
chdr, err := utils.UnmarshalChannelHeader(payload.GetHeader().ChannelHeader)
if err != nil {
return "", fmt.Errorf("failed to unmarshal channel header")
}
fmt.Printf("++++++++++++++++++++++")
fmt.Printf(chdr.TxId)
Error screenshot: