-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.go
112 lines (91 loc) · 2.8 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
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
package local
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/forbole/juno/v4/node/local"
distrsource "github.com/rarimo/bdjuno/modules/distribution/source"
)
var (
_ distrsource.Source = &Source{}
)
// Source implements distrsource.Source reading the data from a local node
type Source struct {
*local.Source
q distrtypes.QueryServer
}
func NewSource(source *local.Source, keeper distrtypes.QueryServer) *Source {
return &Source{
Source: source,
q: keeper,
}
}
// ValidatorCommission implements distrsource.Source
func (s Source) ValidatorCommission(valOperAddr string, height int64) (sdk.DecCoins, error) {
ctx, err := s.LoadHeight(height)
if err != nil {
return nil, fmt.Errorf("error while loading height: %s", err)
}
res, err := s.q.ValidatorCommission(
sdk.WrapSDKContext(ctx),
&distrtypes.QueryValidatorCommissionRequest{ValidatorAddress: valOperAddr},
)
if err != nil {
return nil, err
}
return res.Commission.Commission, nil
}
// DelegatorTotalRewards implements distrsource.Source
func (s Source) DelegatorTotalRewards(delegator string, height int64) ([]distrtypes.DelegationDelegatorReward, error) {
ctx, err := s.LoadHeight(height)
if err != nil {
return nil, fmt.Errorf("error while loading height: %s", err)
}
res, err := s.q.DelegationTotalRewards(
sdk.WrapSDKContext(ctx),
&distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: delegator},
)
if err != nil {
return nil, err
}
return res.Rewards, nil
}
// DelegatorWithdrawAddress implements distrsource.Source
func (s Source) DelegatorWithdrawAddress(delegator string, height int64) (string, error) {
ctx, err := s.LoadHeight(height)
if err != nil {
return "", fmt.Errorf("error while loading height: %s", err)
}
res, err := s.q.DelegatorWithdrawAddress(
sdk.WrapSDKContext(ctx),
&distrtypes.QueryDelegatorWithdrawAddressRequest{DelegatorAddress: delegator},
)
if err != nil {
return "", err
}
return res.WithdrawAddress, nil
}
// CommunityPool implements distrsource.Source
func (s Source) CommunityPool(height int64) (sdk.DecCoins, error) {
ctx, err := s.LoadHeight(height)
if err != nil {
return nil, fmt.Errorf("error while loading height: %s", err)
}
res, err := s.q.CommunityPool(sdk.WrapSDKContext(ctx), &distrtypes.QueryCommunityPoolRequest{})
if err != nil {
return nil, err
}
return res.Pool, nil
}
// Params implements distrsource.Source
func (s Source) Params(height int64) (distrtypes.Params, error) {
ctx, err := s.LoadHeight(height)
if err != nil {
return distrtypes.Params{}, fmt.Errorf("error while loading height: %s", err)
}
res, err := s.q.Params(sdk.WrapSDKContext(ctx), &distrtypes.QueryParamsRequest{})
if err != nil {
return distrtypes.Params{}, err
}
return res.Params, nil
}