github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/hyperledger/fabric-config/protolator/protoext/decorate.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package protoext
     8  
     9  import (
    10  	"github.com/golang/protobuf/proto"
    11  	commonext2 "github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/commonext"
    12  	"github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/ledger/rwsetext"
    13  	mspext2 "github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/mspext"
    14  	"github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/ordererext"
    15  	peerext2 "github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/peerext"
    16  	"github.com/hyperledger/fabric-protos-go/common"
    17  	"github.com/hyperledger/fabric-protos-go/ledger/rwset"
    18  	"github.com/hyperledger/fabric-protos-go/msp"
    19  	"github.com/hyperledger/fabric-protos-go/orderer"
    20  	"github.com/hyperledger/fabric-protos-go/peer"
    21  )
    22  
    23  // Docorate will add additional capabilities to some protobuf messages that
    24  // enable proper JSON marshalling and unmarshalling in protolator.
    25  func Decorate(msg proto.Message) proto.Message {
    26  	switch m := msg.(type) {
    27  	case *common.BlockData:
    28  		return &commonext2.BlockData{BlockData: m}
    29  	case *common.Config:
    30  		return &commonext2.Config{Config: m}
    31  	case *common.ConfigSignature:
    32  		return &commonext2.ConfigSignature{ConfigSignature: m}
    33  	case *common.ConfigUpdate:
    34  		return &commonext2.ConfigUpdate{ConfigUpdate: m}
    35  	case *common.ConfigUpdateEnvelope:
    36  		return &commonext2.ConfigUpdateEnvelope{ConfigUpdateEnvelope: m}
    37  	case *common.Envelope:
    38  		return &commonext2.Envelope{Envelope: m}
    39  	case *common.Header:
    40  		return &commonext2.Header{Header: m}
    41  	case *common.ChannelHeader:
    42  		return &commonext2.ChannelHeader{ChannelHeader: m}
    43  	case *common.SignatureHeader:
    44  		return &commonext2.SignatureHeader{SignatureHeader: m}
    45  	case *common.Payload:
    46  		return &commonext2.Payload{Payload: m}
    47  	case *common.Policy:
    48  		return &commonext2.Policy{Policy: m}
    49  
    50  	case *msp.MSPConfig:
    51  		return &mspext2.MSPConfig{MSPConfig: m}
    52  	case *msp.MSPPrincipal:
    53  		return &mspext2.MSPPrincipal{MSPPrincipal: m}
    54  
    55  	case *orderer.ConsensusType:
    56  		return &ordererext.ConsensusType{ConsensusType: m}
    57  
    58  	case *peer.ChaincodeAction:
    59  		return &peerext2.ChaincodeAction{ChaincodeAction: m}
    60  	case *peer.ChaincodeActionPayload:
    61  		return &peerext2.ChaincodeActionPayload{ChaincodeActionPayload: m}
    62  	case *peer.ChaincodeEndorsedAction:
    63  		return &peerext2.ChaincodeEndorsedAction{ChaincodeEndorsedAction: m}
    64  	case *peer.ChaincodeProposalPayload:
    65  		return &peerext2.ChaincodeProposalPayload{ChaincodeProposalPayload: m}
    66  	case *peer.ProposalResponsePayload:
    67  		return &peerext2.ProposalResponsePayload{ProposalResponsePayload: m}
    68  	case *peer.TransactionAction:
    69  		return &peerext2.TransactionAction{TransactionAction: m}
    70  
    71  	case *rwset.TxReadWriteSet:
    72  		return &rwsetext.TxReadWriteSet{TxReadWriteSet: m}
    73  
    74  	default:
    75  		return msg
    76  	}
    77  }