diff --git a/proto/chan_config.go b/proto/chan_config.go index a29481bc..dba199cc 100644 --- a/proto/chan_config.go +++ b/proto/chan_config.go @@ -472,7 +472,7 @@ func (c ChannelConfig) GetAllCertificates() ([]Certificate, error) { } for mspID := range c.Orderers { - cs, err := c.Applications[mspID].MSP.GetAllCertificates() + cs, err := c.Orderers[mspID].MSP.GetAllCertificates() if err != nil { return nil, fmt.Errorf("get all orderers certificates: %w", err) } diff --git a/proto/envelope.go b/proto/envelope.go index 15e25826..0a43853f 100644 --- a/proto/envelope.go +++ b/proto/envelope.go @@ -53,6 +53,14 @@ func ParseEnvelope(envelopeData []byte, validationCode peer.TxValidationCode) (* return nil, fmt.Errorf(`channel header from envelope payload: %w`, err) } + if channelHeader.TxId == "" { + sigHeader, err := protoutil.UnmarshalSignatureHeader(payload.Header.SignatureHeader) + if err != nil { + return nil, fmt.Errorf("signature header: %w", err) + } + protoutil.SetTxID(channelHeader, sigHeader) + } + parsedEnvelope := &Envelope{ Signature: envelope.Signature, ChannelHeader: channelHeader, @@ -61,7 +69,7 @@ func ParseEnvelope(envelopeData []byte, validationCode peer.TxValidationCode) (* switch common.HeaderType(channelHeader.Type) { case common.HeaderType_ENDORSER_TRANSACTION: - parsedEnvelope.Transaction, err = ParseEndorserTx(payload.Data) + parsedEnvelope.Transaction, err = ParseTransaction(payload, common.HeaderType(channelHeader.Type)) if err != nil { return nil, fmt.Errorf(`endorser transaction from envelope: %w`, err) } @@ -75,6 +83,11 @@ func ParseEnvelope(envelopeData []byte, validationCode peer.TxValidationCode) (* if err != nil { return nil, fmt.Errorf(`parse channel config: %w`, err) } + + parsedEnvelope.Transaction, err = ParseTransaction(payload, common.HeaderType(channelHeader.Type)) + if err != nil { + return nil, fmt.Errorf(`endorser transaction from envelope: %w`, err) + } } return parsedEnvelope, nil diff --git a/proto/tx.go b/proto/tx.go index 66782c53..a21928e9 100644 --- a/proto/tx.go +++ b/proto/tx.go @@ -3,61 +3,52 @@ package proto import ( "fmt" + "github.com/hyperledger/fabric-protos-go/common" "github.com/hyperledger/fabric-protos-go/msp" "github.com/hyperledger/fabric-protos-go/peer" "github.com/hyperledger/fabric/protoutil" - "github.com/pkg/errors" ) type ( Transaction struct { Actions TransactionsActions `json:"transaction_actions"` CreatorIdentity msp.SerializedIdentity `json:"creator_identity"` - Signature []byte `json:"signature"` } Transactions []*Transaction ) -func ParseEndorserTx(envelopePayloadBytes []byte) (*Transaction, error) { - tx, err := protoutil.UnmarshalTransaction(envelopePayloadBytes) +func ParseTransaction(payload *common.Payload, transactionType common.HeaderType) (*Transaction, error) { + sigHeader, err := protoutil.UnmarshalSignatureHeader(payload.Header.SignatureHeader) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to get signature header: %w", err) } - parsedTx := &Transaction{} - parsedTx.Actions, err = ParseTxActions(tx.Actions) + si, err := protoutil.UnmarshalSerializedIdentity(sigHeader.Creator) if err != nil { - return nil, err + return nil, fmt.Errorf("parse transaction creator: %w", err) } - payload, err := protoutil.UnmarshalPayload(envelopePayloadBytes) - if err != nil { - return nil, errors.Wrap(err, `failed to get payload from envelope`) - } + var actions []*TransactionAction + if transactionType == common.HeaderType_ENDORSER_TRANSACTION { + tx, err := protoutil.UnmarshalTransaction(payload.Data) + if err != nil { + return nil, err + } - sigHeader, err := protoutil.UnmarshalSignatureHeader(payload.Header.SignatureHeader) - if err != nil { - return nil, fmt.Errorf("failed to get signature header: %w", err) + actions, err = ParseTxActions(tx.Actions) + if err != nil { + return nil, err + } } - si, err := protoutil.UnmarshalSerializedIdentity(sigHeader.Creator) - if err != nil { - // in some transactions we get some unknown proto message with chaincodes(!?), dont know how to deal with it now - // ---- example - // � - // �  - // _lifecycle� - // "ApproveChaincodeDefinitionForMyOrg - // ^basic1.0JNL - // Jbasic_1.0:770d76a4369f9121d4945c6782dd42c4db7c130c3c7b77b73d9894414b5a3da9 - // log.Println("[hlf.ptoto.tx-parser] got error, skipping it. transaction creator is not 'msp.SerializedIdentity': ", string(sigHeader.Creator)) - err = nil - //return nil, fmt.Errorf("parse transaction creator: %w", err) + parsedTx := &Transaction{ + Actions: actions, + CreatorIdentity: *si, } - parsedTx.CreatorIdentity = *si - return parsedTx, err + return parsedTx, nil + } func (t *Transaction) Events() []*peer.ChaincodeEvent {