-
Notifications
You must be signed in to change notification settings - Fork 41
/
querier.go
73 lines (63 loc) · 2.42 KB
/
querier.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
package types
import (
"encoding/json"
"net/http"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Query endpoints supported by the oracle Querier.
const (
QueryParams = "params"
QueryCounts = "counts"
QueryData = "data"
QueryDataSources = "data_sources"
QueryOracleScripts = "oracle_scripts"
QueryRequests = "requests"
QueryValidatorStatus = "validator_status"
QueryReporters = "reporters"
QueryActiveValidators = "active_validators"
QueryPendingRequests = "pending_requests"
)
// QueryResult wraps querier result with HTTP status to return to application.
type QueryResult struct {
Status int `json:"status"`
Result json.RawMessage `json:"result"`
}
// QueryOK creates and marshals a QueryResult instance with HTTP status OK.
func QueryOK(legacyQuerierCdc *codec.LegacyAmino, result interface{}) ([]byte, error) {
return json.MarshalIndent(QueryResult{
Status: http.StatusOK,
Result: codec.MustMarshalJSONIndent(legacyQuerierCdc, result),
}, "", " ")
}
// QueryBadRequest creates and marshals a QueryResult instance with HTTP status BadRequest.
func QueryBadRequest(legacyQuerierCdc *codec.LegacyAmino, result interface{}) ([]byte, error) {
return codec.MarshalJSONIndent(legacyQuerierCdc, QueryResult{
Status: http.StatusBadRequest,
Result: codec.MustMarshalJSONIndent(legacyQuerierCdc, result),
})
}
// QueryNotFound creates and marshals a QueryResult instance with HTTP status NotFound.
func QueryNotFound(legacyQuerierCdc *codec.LegacyAmino, result interface{}) ([]byte, error) {
return codec.MarshalJSONIndent(legacyQuerierCdc, QueryResult{
Status: http.StatusBadRequest,
Result: codec.MustMarshalJSONIndent(legacyQuerierCdc, result),
})
}
// QueryCountsResult is the struct for the result of query counts.
type QueryCountsResult struct {
DataSourceCount uint64 `json:"data_source_count"`
OracleScriptCount uint64 `json:"oracle_script_count"`
RequestCount uint64 `json:"request_count"`
}
// QueryRequestResult is the struct for the result of request query.
type QueryRequestResult struct {
Request Request `json:"request"`
Reports []Report `json:"reports"`
Result *Result `json:"result"`
}
// QueryActiveValidatorResult is the struct for the result of request active validators.
type QueryActiveValidatorResult struct {
Address sdk.ValAddress `json:"address"`
Power uint64 `json:"power"`
}