MCPcopy
hub / github.com/canopy-network/canopy / MarshalJSON

Method MarshalJSON

lib/event.go:91–155  ·  view source on GitHub ↗

MarshalJSON implements custom JSON marshalling for Event, converting []byte fields to HexBytes

()

Source from the content-addressed store, hash-verified

89
90// MarshalJSON implements custom JSON marshalling for Event, converting []byte fields to HexBytes
91func (e *Event) MarshalJSON() ([]byte, error) {
92 if e == nil {
93 return json.Marshal(nil)
94 }
95
96 // Marshal the Msg field separately
97 var msgBytes []byte
98 var msgTypeURL string
99 var msgHex HexBytes
100 var err error
101 if e.Msg != nil {
102 switch msg := e.Msg.(type) {
103 case *Event_Reward:
104 msgBytes, err = json.Marshal(msg.Reward)
105 case *Event_Slash:
106 msgBytes, err = json.Marshal(msg.Slash)
107 case *Event_DexLiquidityDeposit:
108 msgBytes, err = json.Marshal(msg.DexLiquidityDeposit)
109 case *Event_DexLiquidityWithdrawal:
110 msgBytes, err = json.Marshal(msg.DexLiquidityWithdrawal)
111 case *Event_DexSwap:
112 msgBytes, err = json.Marshal(msg.DexSwap)
113 case *Event_OrderBookSwap:
114 msgBytes, err = json.Marshal(msg.OrderBookSwap)
115 case *Event_OrderBookLock:
116 msgBytes, err = json.Marshal(msg.OrderBookLock)
117 case *Event_OrderBookReset:
118 msgBytes, err = json.Marshal(msg.OrderBookReset)
119 case *Event_AutoPause:
120 msgBytes, err = json.Marshal(msg.AutoPause)
121 case *Event_AutoBeginUnstaking:
122 msgBytes, err = json.Marshal(msg.AutoBeginUnstaking)
123 case *Event_FinishUnstaking:
124 msgBytes, err = json.Marshal(msg.FinishUnstaking)
125 case *Event_Custom:
126 if msg.Custom != nil && msg.Custom.Msg != nil {
127 msgBytes, err = MarshalAnypbJSON(msg.Custom.Msg)
128 if err != nil {
129 msgTypeURL = msg.Custom.Msg.TypeUrl
130 msgHex = HexBytes(msg.Custom.Msg.Value)
131 msgBytes = nil
132 err = nil
133 }
134 }
135 }
136 if err != nil {
137 return nil, err
138 }
139 }
140
141 temp := eventJSON{
142 EventType: e.EventType,
143 Msg: msgBytes,
144 MsgTypeURL: msgTypeURL,
145 MsgBytes: msgHex,
146 Height: e.Height,
147 Reference: e.Reference,
148 ChainId: e.ChainId,

Callers

nothing calls this directly

Calls 3

MarshalAnypbJSONFunction · 0.85
HexBytesTypeAlias · 0.85
MarshalMethod · 0.65

Tested by

no test coverage detected