github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/client/lcd/root_ibc.go (about)

     1  package lcd
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
     7  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
     8  	"github.com/gogo/gateway"
     9  	"github.com/grpc-ecosystem/grpc-gateway/runtime"
    10  )
    11  
    12  var (
    13  	_ runtime.Marshaler = (*JSONMarshalAdapter)(nil)
    14  )
    15  
    16  type JSONMarshalAdapter struct {
    17  	jsonPb *gateway.JSONPb
    18  	codec  *codec.CodecProxy
    19  }
    20  
    21  func NewJSONMarshalAdapter(jsonPb *gateway.JSONPb, codec *codec.CodecProxy) *JSONMarshalAdapter {
    22  	return &JSONMarshalAdapter{jsonPb: jsonPb, codec: codec}
    23  }
    24  
    25  func (m *JSONMarshalAdapter) Marshal(v interface{}) ([]byte, error) {
    26  	if resp, ok := v.(context.CodecSensitive); ok {
    27  		ret, err := resp.MarshalSensitive(m.codec)
    28  		if nil == err {
    29  			return ret, err
    30  		}
    31  	}
    32  	return m.jsonPb.Marshal(v)
    33  }
    34  
    35  func (m *JSONMarshalAdapter) Unmarshal(data []byte, v interface{}) error {
    36  	return m.jsonPb.Unmarshal(data, v)
    37  }
    38  
    39  func (m *JSONMarshalAdapter) NewDecoder(r io.Reader) runtime.Decoder {
    40  	return m.jsonPb.NewDecoder(r)
    41  }
    42  
    43  func (m *JSONMarshalAdapter) NewEncoder(w io.Writer) runtime.Encoder {
    44  	return m.jsonPb.NewEncoder(w)
    45  }
    46  
    47  func (m *JSONMarshalAdapter) ContentType() string {
    48  	return m.jsonPb.ContentType()
    49  }