-
Notifications
You must be signed in to change notification settings - Fork 17
/
grpc_account_delegation_unbondings.go
48 lines (40 loc) · 1.62 KB
/
grpc_account_delegation_unbondings.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 keeper
import (
"context"
"encoding/binary"
"github.com/KYVENetwork/chain/util"
delegationtypes "github.com/KYVENetwork/chain/x/delegation/types"
"github.com/KYVENetwork/chain/x/query/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) AccountDelegationUnbondings(goCtx context.Context, req *types.QueryAccountDelegationUnbondingsRequest) (*types.QueryAccountDelegationUnbondingsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
var delegationUnbondings []types.DelegationUnbonding
store := prefix.NewStore(ctx.KVStore(k.delegationKeeper.StoreKey()), util.GetByteKey(delegationtypes.UndelegationQueueKeyPrefixIndex2, req.Address))
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) {
if accumulate {
index := binary.BigEndian.Uint64(key[0:8])
unbondingEntry, _ := k.delegationKeeper.GetUndelegationQueueEntry(ctx, index)
delegationUnbondings = append(delegationUnbondings, types.DelegationUnbonding{
Amount: unbondingEntry.Amount,
CreationTime: unbondingEntry.CreationTime,
Staker: k.GetFullStaker(ctx, unbondingEntry.Staker),
})
}
return true, nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryAccountDelegationUnbondingsResponse{
Unbondings: delegationUnbondings,
Pagination: pageRes,
}, nil
}