-
Notifications
You must be signed in to change notification settings - Fork 16
/
grpc_query_get_pay_data.go
41 lines (32 loc) · 1.18 KB
/
grpc_query_get_pay_data.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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/v3/x/storage/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) GetPayData(goCtx context.Context, req *types.QueryPayDataRequest) (*types.QueryPayDataResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
paid := k.GetPaidAmount(ctx, req.Address)
payInfo, found := k.GetStoragePaymentInfo(ctx, req.Address)
if !found {
return &types.QueryPayDataResponse{TimeRemaining: -1, Bytes: 0}, nil
}
left := payInfo.End.Unix() - ctx.BlockTime().Unix()
return &types.QueryPayDataResponse{TimeRemaining: left, Bytes: paid}, nil
}
// func (k Keeper) GetStoragePayementInfoList(goCtx context.Context, req *types.QueryStoragePaymentInfoRequest) (*types.QueryStoragePaymentInfoResponse, error) {
// if req == nil {
// return nil, status.Error(codes.InvalidArgument, "invalid request")
// }
//
// ctx := sdk.UnwrapSDKContext(goCtx)
//
// info := k.GetAllStoragePaymentInfo(ctx)
//
// return &types.QueryStoragePaymentInfoResponse{PaymentInfo: info}, nil
// }