-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
88 lines (69 loc) · 2.04 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
package params
import (
"github.com/gogo/protobuf/proto"
"github.com/xpladev/xpla.go/core"
"github.com/xpladev/xpla.go/types"
"github.com/xpladev/xpla.go/types/errors"
"github.com/xpladev/xpla.go/util"
paramsv1beta1 "cosmossdk.io/api/cosmos/params/v1beta1"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
)
var out []byte
var res proto.Message
var err error
// Query client for params module.
func QueryParams(i core.QueryClient) (string, error) {
if i.QueryType == types.QueryGrpc {
return queryByGrpcParams(i)
} else {
return queryByLcdParams(i)
}
}
func queryByGrpcParams(i core.QueryClient) (string, error) {
queryClient := proposal.NewQueryClient(i.Ixplac.GetGrpcClient())
switch {
// Params subspace
case i.Ixplac.GetMsgType() == ParamsQuerySubpsaceMsgType:
convertMsg := i.Ixplac.GetMsg().(proposal.QueryParamsRequest)
res, err = queryClient.Params(
i.Ixplac.GetContext(),
&convertMsg,
)
if err != nil {
return "", util.LogErr(errors.ErrGrpcRequest, err)
}
default:
return "", util.LogErr(errors.ErrInvalidMsgType, i.Ixplac.GetMsgType())
}
out, err = core.PrintProto(i, res)
if err != nil {
return "", err
}
return string(out), nil
}
const (
paramsParamsLabel = "params"
)
func queryByLcdParams(i core.QueryClient) (string, error) {
url := util.MakeQueryLcdUrl(paramsv1beta1.Query_ServiceDesc.Metadata.(string))
switch {
// Params subspace
case i.Ixplac.GetMsgType() == ParamsQuerySubpsaceMsgType:
convertMsg := i.Ixplac.GetMsg().(proposal.QueryParamsRequest)
parsedSubspace := convertMsg.Subspace
parsedKey := convertMsg.Key
subspace := "?subspace=" + parsedSubspace
key := "&key=" + parsedKey
url = url + paramsParamsLabel + subspace + key
default:
return "", util.LogErr(errors.ErrInvalidMsgType, i.Ixplac.GetMsgType())
}
i.Ixplac.GetHttpMutex().Lock()
out, err := util.CtxHttpClient("GET", i.Ixplac.GetLcdURL()+url, nil, i.Ixplac.GetContext())
if err != nil {
i.Ixplac.GetHttpMutex().Unlock()
return "", err
}
i.Ixplac.GetHttpMutex().Unlock()
return string(out), nil
}