This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_slashing.go
109 lines (90 loc) · 3.04 KB
/
query_slashing.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
package slashing
import (
"github.com/Moonyongjung/xpla.go/client/queries"
mslashing "github.com/Moonyongjung/xpla.go/core/slashing"
"github.com/Moonyongjung/xpla.go/types"
"github.com/Moonyongjung/xpla.go/types/errors"
"github.com/Moonyongjung/xpla.go/util"
"github.com/gogo/protobuf/proto"
slashingv1beta1 "cosmossdk.io/api/cosmos/slashing/v1beta1"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
)
var out []byte
var res proto.Message
var err error
// Query client for slashing module.
func QuerySlashing(i queries.IXplaClient) (string, error) {
if i.QueryType == types.QueryGrpc {
return queryByGrpcSlashing(i)
} else {
return queryByLcdSlashing(i)
}
}
func queryByGrpcSlashing(i queries.IXplaClient) (string, error) {
queryClient := slashingtypes.NewQueryClient(i.Ixplac.GetGrpcClient())
switch {
// Slashing parameters
case i.Ixplac.GetMsgType() == mslashing.SlashingQuerySlashingParamsMsgType:
convertMsg, _ := i.Ixplac.GetMsg().(slashingtypes.QueryParamsRequest)
res, err = queryClient.Params(
i.Ixplac.GetContext(),
&convertMsg,
)
if err != nil {
return "", util.LogErr(errors.ErrGrpcRequest, err)
}
// Slashing signing information
case i.Ixplac.GetMsgType() == mslashing.SlashingQuerySigningInfosMsgType:
convertMsg, _ := i.Ixplac.GetMsg().(slashingtypes.QuerySigningInfosRequest)
res, err = queryClient.SigningInfos(
i.Ixplac.GetContext(),
&convertMsg,
)
if err != nil {
return "", util.LogErr(errors.ErrGrpcRequest, err)
}
// Slashing signing information
case i.Ixplac.GetMsgType() == mslashing.SlashingQuerySigningInfoMsgType:
convertMsg, _ := i.Ixplac.GetMsg().(slashingtypes.QuerySigningInfoRequest)
res, err = queryClient.SigningInfo(
i.Ixplac.GetContext(),
&convertMsg,
)
if err != nil {
return "", util.LogErr(errors.ErrGrpcRequest, err)
}
default:
return "", util.LogErr(errors.ErrInvalidMsgType, i.Ixplac.GetMsgType())
}
out, err = queries.PrintProto(i, res)
if err != nil {
return "", err
}
return string(out), nil
}
const (
slashingParamsLabel = "params"
slashingSigningInfosLabel = "signing_infos"
)
func queryByLcdSlashing(i queries.IXplaClient) (string, error) {
url := util.MakeQueryLcdUrl(slashingv1beta1.Query_ServiceDesc.Metadata.(string))
switch {
// Slashing parameters
case i.Ixplac.GetMsgType() == mslashing.SlashingQuerySlashingParamsMsgType:
url = url + slashingParamsLabel
// Slashing signing information
case i.Ixplac.GetMsgType() == mslashing.SlashingQuerySigningInfosMsgType:
url = url + slashingSigningInfosLabel
// Slashing signing information
case i.Ixplac.GetMsgType() == mslashing.SlashingQuerySigningInfoMsgType:
convertMsg, _ := i.Ixplac.GetMsg().(slashingtypes.QuerySigningInfoRequest)
url = url + util.MakeQueryLabels(slashingSigningInfosLabel, convertMsg.ConsAddress)
default:
return "", util.LogErr(errors.ErrInvalidMsgType, i.Ixplac.GetMsgType())
}
out, err := util.CtxHttpClient("GET", i.Ixplac.GetLcdURL()+url, nil, i.Ixplac.GetContext())
if err != nil {
return "", err
}
return string(out), nil
}