/
grpc_query_withdrawal.go
39 lines (32 loc) · 1.25 KB
/
grpc_query_withdrawal.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
package keeper
import (
"context"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/merlin-network/fury/consts"
"github.com/merlin-network/fury/x/house/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// DepositorWithdrawals queries all withdrawals of a give depositor address
func (k Keeper) DepositorWithdrawals(c context.Context, req *types.QueryDepositorWithdrawalsRequest) (*types.QueryDepositorWithdrawalsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}
var withdrawals []types.Withdrawal
ctx := sdk.UnwrapSDKContext(c)
store := prefix.NewStore(k.getWithdrawalsStore(ctx), types.GetWithdrawalListPrefix(req.DepositorAddress))
pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
var withdrawal types.Withdrawal
if err := k.cdc.Unmarshal(value, &withdrawal); err != nil {
return err
}
withdrawals = append(withdrawals, withdrawal)
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryDepositorWithdrawalsResponse{Withdrawals: withdrawals, Pagination: pageRes}, nil
}