-
Notifications
You must be signed in to change notification settings - Fork 233
/
validator_delegation.go
37 lines (30 loc) · 1.08 KB
/
validator_delegation.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
package handlers
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
actionstypes "github.com/forbole/bdjuno/v2/cmd/actions/types"
)
func ValidatorDelegation(ctx *actionstypes.Context, payload *actionstypes.Payload) (interface{}, error) {
// Get latest node height
height, err := ctx.GetHeight(payload)
if err != nil {
return nil, err
}
// Get validator's total delegations
res, err := ctx.Sources.StakingSource.GetValidatorDelegationsWithPagination(height, payload.GetAddress(), payload.GetPagination())
if err != nil {
return nil, fmt.Errorf("error while getting validator delegations: %s", err)
}
delegations := make([]actionstypes.Delegation, len(res.DelegationResponses))
for index, del := range res.DelegationResponses {
delegations[index] = actionstypes.Delegation{
DelegatorAddress: del.Delegation.DelegatorAddress,
ValidatorAddress: del.Delegation.ValidatorAddress,
Coins: actionstypes.ConvertCoins([]sdk.Coin{del.Balance}),
}
}
return actionstypes.DelegationResponse{
Delegations: delegations,
Pagination: res.Pagination,
}, nil
}