-
Notifications
You must be signed in to change notification settings - Fork 236
/
unbonding_delegations.go
40 lines (32 loc) · 1.25 KB
/
unbonding_delegations.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
package handlers
import (
"fmt"
"github.com/forbole/bdjuno/v4/modules/actions/types"
"github.com/rs/zerolog/log"
)
func UnbondingDelegationsHandler(ctx *types.Context, payload *types.Payload) (interface{}, error) {
log.Debug().Str("address", payload.GetAddress()).
Int64("height", payload.Input.Height).
Msg("executing unbonding delegations action")
height, err := ctx.GetHeight(payload)
if err != nil {
return nil, err
}
// Get all unbonding delegations for given delegator address
unbondingDelegations, err := ctx.Sources.StakingSource.GetUnbondingDelegations(height, payload.GetAddress(), payload.GetPagination())
if err != nil {
return nil, fmt.Errorf("error while getting delegator unbonding delegations: %s", err)
}
unbondingDelegationsList := make([]types.UnbondingDelegation, len(unbondingDelegations.UnbondingResponses))
for index, del := range unbondingDelegations.UnbondingResponses {
unbondingDelegationsList[index] = types.UnbondingDelegation{
DelegatorAddress: del.DelegatorAddress,
ValidatorAddress: del.ValidatorAddress,
Entries: del.Entries,
}
}
return types.UnbondingDelegationResponse{
UnbondingDelegations: unbondingDelegationsList,
Pagination: unbondingDelegations.Pagination,
}, nil
}