forked from forbole/callisto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
source.go
84 lines (70 loc) · 2.09 KB
/
source.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
package remote
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/pylons-tech/juno/node/remote"
slashingsource "github.com/pylons-tech/bdjuno/modules/slashing/source"
)
var (
_ slashingsource.Source = &Source{}
)
// Source implements slashingsource.Source using a remote node
type Source struct {
*remote.Source
querier slashingtypes.QueryClient
}
// NewSource returns a new Source implementation
func NewSource(source *remote.Source, querier slashingtypes.QueryClient) *Source {
return &Source{
Source: source,
querier: querier,
}
}
// GetSigningInfos implements slashingsource.Source
func (s Source) GetSigningInfos(height int64) ([]slashingtypes.ValidatorSigningInfo, error) {
header := remote.GetHeightRequestHeader(height)
var signingInfos []slashingtypes.ValidatorSigningInfo
var nextKey []byte
var stop = false
for !stop {
res, err := s.querier.SigningInfos(
s.Ctx,
&slashingtypes.QuerySigningInfosRequest{
Pagination: &query.PageRequest{
Key: nextKey,
Limit: 1000, // Query 1000 signing infos at a time
},
},
header,
)
if err != nil {
return nil, err
}
nextKey = res.Pagination.NextKey
stop = len(res.Pagination.NextKey) == 0
signingInfos = append(signingInfos, res.Info...)
}
return signingInfos, nil
}
// GetParams implements slashingsource.Source
func (s Source) GetParams(height int64) (slashingtypes.Params, error) {
res, err := s.querier.Params(s.Ctx, &slashingtypes.QueryParamsRequest{}, remote.GetHeightRequestHeader(height))
if err != nil {
return slashingtypes.Params{}, nil
}
return res.Params, nil
}
// GetSigningInfo implements slashingsource.GetSigningInfo
func (s Source) GetSigningInfo(height int64, consAddr sdk.ConsAddress) (slashingtypes.ValidatorSigningInfo, error) {
res, err := s.querier.SigningInfo(
s.Ctx,
&slashingtypes.QuerySigningInfoRequest{
ConsAddress: consAddr.String(),
},
)
if err != nil {
return slashingtypes.ValidatorSigningInfo{}, err
}
return res.ValSigningInfo, nil
}