github.com/okex/exchain@v1.8.0/libs/tendermint/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 CodeTypeNonceInc uint32 = 100000 13 ) 14 15 // IsOK returns true if Code is OK. 16 func (r ResponseCheckTx) IsOK() bool { 17 return r.Code == CodeTypeOK 18 } 19 20 // IsErr returns true if Code is something other than OK. 21 func (r ResponseCheckTx) IsErr() bool { 22 return r.Code != CodeTypeOK 23 } 24 25 // IsOK returns true if Code is OK. 26 func (r ResponseDeliverTx) IsOK() bool { 27 return r.Code == CodeTypeOK 28 } 29 30 // IsErr returns true if Code is something other than OK. 31 func (r ResponseDeliverTx) IsErr() bool { 32 return r.Code != CodeTypeOK 33 } 34 35 // IsOK returns true if Code is OK. 36 func (r ResponseQuery) IsOK() bool { 37 return r.Code == CodeTypeOK 38 } 39 40 // IsErr returns true if Code is something other than OK. 41 func (r ResponseQuery) IsErr() bool { 42 return r.Code != CodeTypeOK 43 } 44 45 //--------------------------------------------------------------------------- 46 // override JSON marshalling so we emit defaults (ie. disable omitempty) 47 48 var ( 49 jsonpbMarshaller = jsonpb.Marshaler{ 50 EnumsAsInts: true, 51 EmitDefaults: true, 52 } 53 jsonpbUnmarshaller = jsonpb.Unmarshaler{} 54 ) 55 56 func (r *ResponseSetOption) MarshalJSON() ([]byte, error) { 57 s, err := jsonpbMarshaller.MarshalToString(r) 58 return []byte(s), err 59 } 60 61 func (r *ResponseSetOption) UnmarshalJSON(b []byte) error { 62 reader := bytes.NewBuffer(b) 63 return jsonpbUnmarshaller.Unmarshal(reader, r) 64 } 65 66 func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) { 67 s, err := jsonpbMarshaller.MarshalToString(r) 68 return []byte(s), err 69 } 70 71 func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error { 72 reader := bytes.NewBuffer(b) 73 return jsonpbUnmarshaller.Unmarshal(reader, r) 74 } 75 76 func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) { 77 s, err := jsonpbMarshaller.MarshalToString(r) 78 return []byte(s), err 79 } 80 81 func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error { 82 reader := bytes.NewBuffer(b) 83 return jsonpbUnmarshaller.Unmarshal(reader, r) 84 } 85 86 func (r *ResponseQuery) MarshalJSON() ([]byte, error) { 87 s, err := jsonpbMarshaller.MarshalToString(r) 88 return []byte(s), err 89 } 90 91 func (r *ResponseQuery) UnmarshalJSON(b []byte) error { 92 reader := bytes.NewBuffer(b) 93 return jsonpbUnmarshaller.Unmarshal(reader, r) 94 } 95 96 func (r *ResponseCommit) MarshalJSON() ([]byte, error) { 97 s, err := jsonpbMarshaller.MarshalToString(r) 98 return []byte(s), err 99 } 100 101 func (r *ResponseCommit) UnmarshalJSON(b []byte) error { 102 reader := bytes.NewBuffer(b) 103 return jsonpbUnmarshaller.Unmarshal(reader, r) 104 } 105 106 // Some compile time assertions to ensure we don't 107 // have accidental runtime surprises later on. 108 109 // jsonEncodingRoundTripper ensures that asserted 110 // interfaces implement both MarshalJSON and UnmarshalJSON 111 type jsonRoundTripper interface { 112 json.Marshaler 113 json.Unmarshaler 114 } 115 116 var _ jsonRoundTripper = (*ResponseCommit)(nil) 117 var _ jsonRoundTripper = (*ResponseQuery)(nil) 118 var _ jsonRoundTripper = (*ResponseDeliverTx)(nil) 119 var _ jsonRoundTripper = (*ResponseCheckTx)(nil) 120 var _ jsonRoundTripper = (*ResponseSetOption)(nil)