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