forked from dymensionxyz/dymint
/
types.go
174 lines (155 loc) · 3.52 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package json
import (
"encoding/json"
"reflect"
"strconv"
"github.com/gorilla/rpc/v2/json2"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/types"
)
type subscribeArgs struct {
Query string `json:"query"`
}
type unsubscribeArgs struct {
Query string `json:"query"`
}
type unsubscribeAllArgs struct {
}
// info API
type healthArgs struct {
}
type statusArgs struct {
}
type netInfoArgs struct {
}
type blockchainInfoArgs struct {
MinHeight StrInt64 `json:"minHeight"`
MaxHeight StrInt64 `json:"maxHeight"`
}
type genesisArgs struct {
}
type genesisChunkedArgs struct {
ID StrInt `json:"chunk"`
}
type blockArgs struct {
Height StrInt64 `json:"height"`
}
type blockByHashArgs struct {
Hash []byte `json:"hash"`
}
type blockResultsArgs struct {
Height StrInt64 `json:"height"`
}
type commitArgs struct {
Height StrInt64 `json:"height,omitempty"`
}
type checkTxArgs struct {
Tx types.Tx `json:"tx"`
}
type txArgs struct {
Hash []byte `json:"hash"`
Prove bool `json:"prove"`
}
type txSearchArgs struct {
Query string `json:"query"`
Prove bool `json:"prove"`
Page StrInt `json:"page"`
PerPage StrInt `json:"per_page"`
OrderBy string `json:"order_by"`
}
type blockSearchArgs struct {
Query string `json:"query"`
Page StrInt `json:"page"`
PerPage StrInt `json:"per_page"`
OrderBy string `json:"order_by"`
}
type validatorsArgs struct {
Height StrInt64 `json:"height"`
Page StrInt `json:"page"`
PerPage StrInt `json:"per_page"`
}
type dumpConsensusStateArgs struct {
}
type getConsensusStateArgs struct {
}
type consensusParamsArgs struct {
Height StrInt64 `json:"height"`
}
type unconfirmedTxsArgs struct {
Limit StrInt `json:"limit"`
}
type numUnconfirmedTxsArgs struct {
}
// tx broadcast API
type broadcastTxCommitArgs struct {
Tx types.Tx `json:"tx"`
}
type broadcastTxSyncArgs struct {
Tx types.Tx `json:"tx"`
}
type broadcastTxAsyncArgs struct {
Tx types.Tx `json:"tx"`
}
// abci API
// ABCIQueryArgs defines args for ABCI Query method.
type ABCIQueryArgs struct {
Path string `json:"path"`
Data bytes.HexBytes `json:"data"`
Height StrInt64 `json:"height"`
Prove bool `json:"prove"`
}
// ABCIInfoArgs defines args for ABCI Info method.
type ABCIInfoArgs struct {
}
// evidence API
type broadcastEvidenceArgs struct {
Evidence types.Evidence `json:"evidence"`
}
type emptyResult struct{}
// JSON-deserialization specific types
// StrInt is an proper int or quoted "int"
type StrInt int
// StrInt64 is an proper int64 or quoted "int64"
type StrInt64 int64
// UnmarshalJSON parses JSON (int or int qouted as string) into StrInt64
func (s *StrInt64) UnmarshalJSON(b []byte) error {
return unmarshalStrInt64(b, s)
}
// UnmarshalJSON parses JSON (int or int qouted as string) into StrInt
func (s *StrInt) UnmarshalJSON(b []byte) error {
var val StrInt64
err := unmarshalStrInt64(b, &val)
*s = StrInt(val)
return err
}
func unmarshalStrInt64(b []byte, s *StrInt64) error {
var i interface{}
err := json.Unmarshal(b, &i)
if err != nil {
return err
}
switch v := i.(type) {
case int:
*s = StrInt64(v)
case int64:
*s = StrInt64(v)
case string:
iv, err := strconv.Atoi(v)
if err != nil {
return err
}
*s = StrInt64(iv)
default:
return &json.UnsupportedValueError{
Value: reflect.ValueOf(i),
Str: string(b),
}
}
return nil
}
type response struct {
Version string `json:"jsonrpc"`
Result json.RawMessage `json:"result,omitempty"`
Error *json2.Error `json:"error,omitempty"`
ID json.RawMessage `json:"id"`
}