-
Notifications
You must be signed in to change notification settings - Fork 45
/
query.go
170 lines (139 loc) · 5.52 KB
/
query.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
package bindings
import (
"encoding/json"
contractmanagertypes "github.com/neutron-org/neutron/x/contractmanager/types"
feerefundertypes "github.com/neutron-org/neutron/x/feerefunder/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/neutron-org/neutron/x/interchainqueries/types"
)
// NeutronQuery contains neutron custom queries.
type NeutronQuery struct {
// Registered Interchain Query Result for specified QueryID
InterchainQueryResult *QueryRegisteredQueryResultRequest `json:"interchain_query_result,omitempty"`
// Interchain account address for specified ConnectionID and OwnerAddress
InterchainAccountAddress *QueryInterchainAccountAddressRequest `json:"interchain_account_address,omitempty"`
// RegisteredInterchainQueries
RegisteredInterchainQueries *QueryRegisteredQueriesRequest `json:"registered_interchain_queries,omitempty"`
// RegisteredInterchainQuery
RegisteredInterchainQuery *QueryRegisteredQueryRequest `json:"registered_interchain_query,omitempty"`
// MinIbcFee
MinIbcFee *QueryMinIbcFeeRequest `json:"min_ibc_fee,omitempty"`
// Contractmanager queries
// Query all failures for address
Failures *Failures `json:"failures,omitempty"`
}
/* Requests */
type QueryRegisteredQueryResultRequest struct {
QueryID uint64 `json:"query_id,omitempty"`
}
type QueryInterchainAccountAddressRequest struct {
// owner_address is the owner of the interchain account on the controller chain
OwnerAddress string `json:"owner_address,omitempty"`
// interchain_account_id is an identifier of your interchain account from which you want to execute msgs
InterchainAccountID string `json:"interchain_account_id,omitempty"`
// connection_id is an IBC connection identifier between Neutron and remote chain
ConnectionID string `json:"connection_id,omitempty"`
}
type QueryRegisteredQueriesRequest struct {
Owners []string `json:"owners,omitempty"`
ConnectionID string `json:"connection_id,omitempty"`
Pagination *query.PageRequest `json:"pagination,omitempty"`
}
type QueryRegisteredQueryRequest struct {
QueryID uint64 `json:"query_id,omitempty"`
}
/* Responses */
type QueryRegisteredQueryResponse struct {
RegisteredQuery *RegisteredQuery `json:"registered_query,omitempty"`
}
type QueryRegisteredQueriesResponse struct {
RegisteredQueries []RegisteredQuery `json:"registered_queries"`
}
type RegisteredQuery struct {
// The unique id of the registered query.
ID uint64 `json:"id"`
// The address that registered the query.
Owner string `json:"owner"`
// The KV-storage keys for which we want to get values from remote chain
Keys []*types.KVKey `json:"keys"`
// The filter for transaction search ICQ
TransactionsFilter string `json:"transactions_filter"`
// The query type identifier (i.e. 'kv' or 'tx' for now).
QueryType string `json:"query_type"`
// The IBC connection ID for getting ConsensusState to verify proofs.
ConnectionID string `json:"connection_id"`
// Parameter that defines how often the query must be updated.
UpdatePeriod uint64 `json:"update_period"`
// The local chain last block height when the query result was updated.
LastSubmittedResultLocalHeight uint64 `json:"last_submitted_result_local_height"`
// The remote chain last block height when the query result was updated.
LastSubmittedResultRemoteHeight *ibcclienttypes.Height `json:"last_submitted_result_remote_height,omitempty"`
// Amount of coins deposited for the query.
Deposit sdktypes.Coins `json:"deposit"`
// Timeout before query becomes available for everybody to remove.
SubmitTimeout uint64 `json:"submit_timeout"`
// The local chain height when the query was registered.
RegisteredAtHeight uint64 `json:"registered_at_height"`
}
type QueryMinIbcFeeRequest struct{}
type QueryMinIbcFeeResponse struct {
MinFee feerefundertypes.Fee `json:"min_fee"`
}
func (rq RegisteredQuery) MarshalJSON() ([]byte, error) {
type AliasRQ RegisteredQuery
a := struct {
AliasRQ
}{
AliasRQ: (AliasRQ)(rq),
}
// We want keys be as empty array in Json ('[]'), not 'null'
// It's easier to work with on smart-contracts side
if a.Keys == nil {
a.Keys = make([]*types.KVKey, 0)
}
return json.Marshal(a)
}
// Query response for an interchain account address.
type QueryInterchainAccountAddressResponse struct {
// The corresponding interchain account address on the host chain
InterchainAccountAddress string `json:"interchain_account_address,omitempty"`
}
type QueryRegisteredQueryResultResponse struct {
Result *QueryResult `json:"result,omitempty"`
}
type QueryResult struct {
KvResults []*StorageValue `json:"kv_results,omitempty"`
Height uint64 `json:"height,omitempty"`
Revision uint64 `json:"revision,omitempty"`
}
type StorageValue struct {
StoragePrefix string `json:"storage_prefix,omitempty"`
Key []byte `json:"key"`
Value []byte `json:"value"`
}
func (sv StorageValue) MarshalJSON() ([]byte, error) {
type AliasSV StorageValue
a := struct {
AliasSV
}{
AliasSV: (AliasSV)(sv),
}
// We want Key and Value be as empty arrays in Json ('[]'), not 'null'
// It's easier to work with on smart-contracts side
if a.Key == nil {
a.Key = make([]byte, 0)
}
if a.Value == nil {
a.Value = make([]byte, 0)
}
return json.Marshal(a)
}
type Failures struct {
Address string `json:"address"`
Pagination *query.PageRequest `json:"pagination,omitempty"`
}
type FailuresResponse struct {
Failures []contractmanagertypes.Failure `json:"failures"`
}