github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/rpc/coretypes/requests.go (about) 1 package coretypes 2 3 import ( 4 "encoding/json" 5 "strconv" 6 "time" 7 8 "github.com/ari-anchor/sei-tendermint/internal/jsontypes" 9 "github.com/ari-anchor/sei-tendermint/libs/bytes" 10 "github.com/ari-anchor/sei-tendermint/types" 11 ) 12 13 type RequestSubscribe struct { 14 Query string `json:"query"` 15 } 16 17 type RequestUnsubscribe struct { 18 Query string `json:"query"` 19 } 20 21 type RequestBlockchainInfo struct { 22 MinHeight Int64 `json:"minHeight"` 23 MaxHeight Int64 `json:"maxHeight"` 24 } 25 26 type RequestGenesisChunked struct { 27 Chunk Int64 `json:"chunk"` 28 } 29 30 type RequestBlockInfo struct { 31 Height *Int64 `json:"height"` 32 } 33 34 type RequestBlockByHash struct { 35 Hash bytes.HexBytes `json:"hash"` 36 } 37 38 type RequestCheckTx struct { 39 Tx types.Tx `json:"tx"` 40 } 41 42 type RequestRemoveTx struct { 43 TxKey types.TxKey `json:"txkey"` 44 } 45 46 type RequestTx struct { 47 Hash bytes.HexBytes `json:"hash"` 48 Prove bool `json:"prove"` 49 } 50 51 type RequestTxSearch struct { 52 Query string `json:"query"` 53 Prove bool `json:"prove"` 54 Page *Int64 `json:"page"` 55 PerPage *Int64 `json:"per_page"` 56 OrderBy string `json:"order_by"` 57 } 58 59 type RequestBlockSearch struct { 60 Query string `json:"query"` 61 Page *Int64 `json:"page"` 62 PerPage *Int64 `json:"per_page"` 63 OrderBy string `json:"order_by"` 64 } 65 66 type RequestValidators struct { 67 Height *Int64 `json:"height"` 68 Page *Int64 `json:"page"` 69 PerPage *Int64 `json:"per_page"` 70 } 71 72 type RequestConsensusParams struct { 73 Height *Int64 `json:"height"` 74 } 75 76 type RequestUnconfirmedTxs struct { 77 Page *Int64 `json:"page"` 78 PerPage *Int64 `json:"per_page"` 79 } 80 81 type RequestBroadcastTx struct { 82 Tx types.Tx `json:"tx"` 83 } 84 85 type RequestABCIQuery struct { 86 Path string `json:"path"` 87 Data bytes.HexBytes `json:"data"` 88 Height Int64 `json:"height"` 89 Prove bool `json:"prove"` 90 } 91 92 type RequestBroadcastEvidence struct { 93 Evidence types.Evidence 94 } 95 96 type requestBroadcastEvidenceJSON struct { 97 Evidence json.RawMessage `json:"evidence"` 98 } 99 100 func (r RequestBroadcastEvidence) MarshalJSON() ([]byte, error) { 101 ev, err := jsontypes.Marshal(r.Evidence) 102 if err != nil { 103 return nil, err 104 } 105 return json.Marshal(requestBroadcastEvidenceJSON{ 106 Evidence: ev, 107 }) 108 } 109 110 func (r *RequestBroadcastEvidence) UnmarshalJSON(data []byte) error { 111 var val requestBroadcastEvidenceJSON 112 if err := json.Unmarshal(data, &val); err != nil { 113 return err 114 } 115 if err := jsontypes.Unmarshal(val.Evidence, &r.Evidence); err != nil { 116 return err 117 } 118 return nil 119 } 120 121 // RequestEvents is the argument for the "/events" RPC endpoint. 122 type RequestEvents struct { 123 // Optional filter spec. If nil or empty, all items are eligible. 124 Filter *EventFilter `json:"filter"` 125 126 // The maximum number of eligible items to return. 127 // If zero or negative, the server will report a default number. 128 MaxItems int `json:"maxItems"` 129 130 // Return only items after this cursor. If empty, the limit is just 131 // before the the beginning of the event log. 132 After string `json:"after"` 133 134 // Return only items before this cursor. If empty, the limit is just 135 // after the head of the event log. 136 Before string `json:"before"` 137 138 // Wait for up to this long for events to be available. 139 WaitTime time.Duration `json:"waitTime"` 140 } 141 142 // An EventFilter specifies which events are selected by an /events request. 143 type EventFilter struct { 144 Query string `json:"query"` 145 } 146 147 // Int64 is a wrapper for int64 that encodes to JSON as a string and can be 148 // decoded from either a string or a number value. 149 type Int64 int64 150 151 func (z *Int64) UnmarshalJSON(data []byte) error { 152 var s string 153 if len(data) != 0 && data[0] == '"' { 154 if err := json.Unmarshal(data, &s); err != nil { 155 return err 156 } 157 } else { 158 s = string(data) 159 } 160 v, err := strconv.ParseInt(s, 10, 64) 161 if err != nil { 162 return err 163 } 164 *z = Int64(v) 165 return nil 166 } 167 168 func (z Int64) MarshalJSON() ([]byte, error) { 169 return []byte(strconv.FormatInt(int64(z), 10)), nil 170 } 171 172 // IntPtr returns a pointer to the value of *z as an int, or nil if z == nil. 173 func (z *Int64) IntPtr() *int { 174 if z == nil { 175 return nil 176 } 177 v := int(*z) 178 return &v 179 } 180 181 // Int64Ptr returns an *Int64 that points to the same value as v, or nil. 182 func Int64Ptr(v *int) *Int64 { 183 if v == nil { 184 return nil 185 } 186 z := Int64(*v) 187 return &z 188 }