github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/abci/types/types.go (about)

     1  package types
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  
     7  	"github.com/cosmos/gogoproto/jsonpb"
     8  )
     9  
    10  const (
    11  	CodeTypeOK uint32 = 0
    12  )
    13  
    14  // IsOK returns true if Code is OK.
    15  func (r ResponseCheckTx) IsOK() bool {
    16  	return r.Code == CodeTypeOK
    17  }
    18  
    19  // IsErr returns true if Code is something other than OK.
    20  func (r ResponseCheckTx) IsErr() bool {
    21  	return r.Code != CodeTypeOK
    22  }
    23  
    24  // IsOK returns true if Code is OK.
    25  func (r ResponseDeliverTx) IsOK() bool {
    26  	return r.Code == CodeTypeOK
    27  }
    28  
    29  // IsErr returns true if Code is something other than OK.
    30  func (r ResponseDeliverTx) IsErr() bool {
    31  	return r.Code != CodeTypeOK
    32  }
    33  
    34  // IsOK returns true if Code is OK.
    35  func (r ResponseQuery) IsOK() bool {
    36  	return r.Code == CodeTypeOK
    37  }
    38  
    39  // IsErr returns true if Code is something other than OK.
    40  func (r ResponseQuery) IsErr() bool {
    41  	return r.Code != CodeTypeOK
    42  }
    43  
    44  // IsAccepted returns true if Code is ACCEPT
    45  func (r ResponseProcessProposal) IsAccepted() bool {
    46  	return r.Status == ResponseProcessProposal_ACCEPT
    47  }
    48  
    49  // IsStatusUnknown returns true if Code is UNKNOWN
    50  func (r ResponseProcessProposal) IsStatusUnknown() bool {
    51  	return r.Status == ResponseProcessProposal_UNKNOWN
    52  }
    53  
    54  //---------------------------------------------------------------------------
    55  // override JSON marshaling so we emit defaults (ie. disable omitempty)
    56  
    57  var (
    58  	jsonpbMarshaller = jsonpb.Marshaler{
    59  		EnumsAsInts:  true,
    60  		EmitDefaults: true,
    61  	}
    62  	jsonpbUnmarshaller = jsonpb.Unmarshaler{}
    63  )
    64  
    65  func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) {
    66  	s, err := jsonpbMarshaller.MarshalToString(r)
    67  	return []byte(s), err
    68  }
    69  
    70  func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error {
    71  	reader := bytes.NewBuffer(b)
    72  	return jsonpbUnmarshaller.Unmarshal(reader, r)
    73  }
    74  
    75  func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) {
    76  	s, err := jsonpbMarshaller.MarshalToString(r)
    77  	return []byte(s), err
    78  }
    79  
    80  func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error {
    81  	reader := bytes.NewBuffer(b)
    82  	return jsonpbUnmarshaller.Unmarshal(reader, r)
    83  }
    84  
    85  func (r *ResponseQuery) MarshalJSON() ([]byte, error) {
    86  	s, err := jsonpbMarshaller.MarshalToString(r)
    87  	return []byte(s), err
    88  }
    89  
    90  func (r *ResponseQuery) UnmarshalJSON(b []byte) error {
    91  	reader := bytes.NewBuffer(b)
    92  	return jsonpbUnmarshaller.Unmarshal(reader, r)
    93  }
    94  
    95  func (r *ResponseCommit) MarshalJSON() ([]byte, error) {
    96  	s, err := jsonpbMarshaller.MarshalToString(r)
    97  	return []byte(s), err
    98  }
    99  
   100  func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
   101  	reader := bytes.NewBuffer(b)
   102  	return jsonpbUnmarshaller.Unmarshal(reader, r)
   103  }
   104  
   105  func (r *EventAttribute) MarshalJSON() ([]byte, error) {
   106  	s, err := jsonpbMarshaller.MarshalToString(r)
   107  	return []byte(s), err
   108  }
   109  
   110  func (r *EventAttribute) UnmarshalJSON(b []byte) error {
   111  	reader := bytes.NewBuffer(b)
   112  	return jsonpbUnmarshaller.Unmarshal(reader, r)
   113  }
   114  
   115  // Some compile time assertions to ensure we don't
   116  // have accidental runtime surprises later on.
   117  
   118  // jsonEncodingRoundTripper ensures that asserted
   119  // interfaces implement both MarshalJSON and UnmarshalJSON
   120  type jsonRoundTripper interface {
   121  	json.Marshaler
   122  	json.Unmarshaler
   123  }
   124  
   125  var _ jsonRoundTripper = (*ResponseCommit)(nil)
   126  var _ jsonRoundTripper = (*ResponseQuery)(nil)
   127  var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
   128  var _ jsonRoundTripper = (*ResponseCheckTx)(nil)
   129  
   130  var _ jsonRoundTripper = (*EventAttribute)(nil)