-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_query.go
61 lines (42 loc) · 2.03 KB
/
grpc_query.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
49
50
51
52
53
54
55
56
57
58
59
60
61
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/furya-official/fury-blockchain/x/payments/types"
)
var _ types.QueryServer = Keeper{}
func (k Keeper) PaymentTemplate(c context.Context, req *types.QueryPaymentTemplateRequest) (*types.QueryPaymentTemplateResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
templateId := req.PaymentTemplateId
template, err := k.GetPaymentTemplate(ctx, templateId)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest,
"payment template '%s' does not exist", templateId)
}
return &types.QueryPaymentTemplateResponse{PaymentTemplate: template}, nil
}
func (k Keeper) PaymentContract(c context.Context, req *types.QueryPaymentContractRequest) (*types.QueryPaymentContractResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
contractId := req.PaymentContractId
contract, err := k.GetPaymentContract(ctx, contractId)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "payment contract '%s' does not exist", contractId)
}
return &types.QueryPaymentContractResponse{PaymentContract: contract}, nil
}
func (k Keeper) PaymentContractsByIdPrefix(c context.Context, req *types.QueryPaymentContractsByIdPrefixRequest) (*types.QueryPaymentContractsByIdPrefixResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
contractIdPrefix := req.PaymentContractsIdPrefix
contracts := k.GetPaymentContractsByPrefix(ctx, contractIdPrefix)
return &types.QueryPaymentContractsByIdPrefixResponse{PaymentContracts: contracts}, nil
}
func (k Keeper) Subscription(c context.Context, req *types.QuerySubscriptionRequest) (*types.QuerySubscriptionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
subscriptionId := req.SubscriptionId
subscription, err := k.GetSubscription(ctx, subscriptionId)
if err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "subscription '%s' does not exist", subscriptionId)
}
return &types.QuerySubscriptionResponse{Subscription: subscription}, nil
}