github.com/soomindae/tendermint@v0.0.5-0.20210528140126-84a0c70c8162/abci/types/result.go (about) 1 package types 2 3 import ( 4 "bytes" 5 "encoding/json" 6 7 "github.com/gogo/protobuf/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 //--------------------------------------------------------------------------- 45 // override JSON marshalling so we emit defaults (ie. disable omitempty) 46 47 var ( 48 jsonpbMarshaller = jsonpb.Marshaler{ 49 EnumsAsInts: true, 50 EmitDefaults: true, 51 } 52 jsonpbUnmarshaller = jsonpb.Unmarshaler{} 53 ) 54 55 func (r *ResponseSetOption) MarshalJSON() ([]byte, error) { 56 s, err := jsonpbMarshaller.MarshalToString(r) 57 return []byte(s), err 58 } 59 60 func (r *ResponseSetOption) UnmarshalJSON(b []byte) error { 61 reader := bytes.NewBuffer(b) 62 return jsonpbUnmarshaller.Unmarshal(reader, r) 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 var _ jsonRoundTripper = (*ResponseSetOption)(nil) 130 131 var _ jsonRoundTripper = (*EventAttribute)(nil)