-
Notifications
You must be signed in to change notification settings - Fork 233
/
validator_redelegations_from.go
48 lines (40 loc) · 1.61 KB
/
validator_redelegations_from.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
package handlers
import (
"fmt"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
actionstypes "github.com/forbole/bdjuno/v2/cmd/actions/types"
)
func ValidatorRedelegationsFromHandler(ctx *actionstypes.Context, payload *actionstypes.Payload) (interface{}, error) {
height, err := ctx.GetHeight(payload)
if err != nil {
return nil, err
}
// Get redelegations from a source validator address
redelegations, err := ctx.Sources.StakingSource.GetRedelegations(height, &stakingtypes.QueryRedelegationsRequest{
SrcValidatorAddr: payload.GetAddress(),
Pagination: payload.GetPagination(),
})
if err != nil {
return nil, fmt.Errorf("error while getting redelegations from validator: %s", err)
}
redelegationsList := make([]actionstypes.Redelegation, len(redelegations.RedelegationResponses))
for index, del := range redelegations.RedelegationResponses {
redelegationsList[index] = actionstypes.Redelegation{
DelegatorAddress: del.Redelegation.DelegatorAddress,
ValidatorSrcAddress: del.Redelegation.ValidatorSrcAddress,
ValidatorDstAddress: del.Redelegation.ValidatorDstAddress,
}
RedelegationEntriesList := make([]actionstypes.RedelegationEntry, len(del.Entries))
for indexEntry, entry := range del.Entries {
RedelegationEntriesList[indexEntry] = actionstypes.RedelegationEntry{
CompletionTime: entry.RedelegationEntry.CompletionTime,
Balance: entry.Balance,
}
}
redelegationsList[index].RedelegationEntries = RedelegationEntriesList
}
return actionstypes.RedelegationResponse{
Redelegations: redelegationsList,
Pagination: redelegations.Pagination,
}, nil
}