/
grpc_query.go
137 lines (121 loc) · 3.65 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/x/bridge/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var _ types.QueryServer = Keeper{}
// EventParams processes a query request/response for the EventParams from state.
func (k Keeper) EventParams(
c context.Context,
req *types.QueryEventParamsRequest,
) (
*types.QueryEventParamsResponse,
error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
params := k.GetEventParams(ctx)
return &types.QueryEventParamsResponse{
Params: params,
}, nil
}
// ProposeParams processes a query request/response for the ProposeParams from state.
func (k Keeper) ProposeParams(
c context.Context,
req *types.QueryProposeParamsRequest,
) (
*types.QueryProposeParamsResponse,
error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
params := k.GetProposeParams(ctx)
return &types.QueryProposeParamsResponse{
Params: params,
}, nil
}
// SafetyParams processes a query request/response for the SafetyParams from state.
func (k Keeper) SafetyParams(
c context.Context,
req *types.QuerySafetyParamsRequest,
) (
*types.QuerySafetyParamsResponse,
error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
params := k.GetSafetyParams(ctx)
return &types.QuerySafetyParamsResponse{
Params: params,
}, nil
}
// AcknowledgedEventInfo processes a query request/response for `AcknowledgedEventInfo` from state.
func (k Keeper) AcknowledgedEventInfo(
c context.Context,
req *types.QueryAcknowledgedEventInfoRequest,
) (
*types.QueryAcknowledgedEventInfoResponse,
error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
acknowledgedEventInfo := k.GetAcknowledgedEventInfo(ctx)
return &types.QueryAcknowledgedEventInfoResponse{
Info: acknowledgedEventInfo,
}, nil
}
// RecognizedEventInfo processes a query request/response for the following
// that has a greater `NextId`:
// - the `AcknowledgedEventInfo` from state
// - the `RecognizedEventInfo` from memory
// Since RecognizedEventInfo is from memory, the value is not deterministic based on state
// and therefore may be different between nodes.
func (k Keeper) RecognizedEventInfo(
c context.Context,
req *types.QueryRecognizedEventInfoRequest,
) (
*types.QueryRecognizedEventInfoResponse,
error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
acknowledgedEventInfo := k.GetAcknowledgedEventInfo(ctx)
recognizedEventInfo := k.bridgeEventManager.GetRecognizedEventInfo()
// If `AcknowledgedEventInfo` from state has a greater `NextId`, use that in response.
// This implies that the EventInfo that has a greater `NextId` also has a equal-or-higher
// value of `EthBlockHeight`.
if acknowledgedEventInfo.NextId > recognizedEventInfo.NextId {
recognizedEventInfo = acknowledgedEventInfo
}
return &types.QueryRecognizedEventInfoResponse{
Info: recognizedEventInfo,
}, nil
}
func (k Keeper) DelayedCompleteBridgeMessages(
c context.Context,
req *types.QueryDelayedCompleteBridgeMessagesRequest,
) (
*types.QueryDelayedCompleteBridgeMessagesResponse,
error,
) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)
return &types.QueryDelayedCompleteBridgeMessagesResponse{
Messages: k.GetDelayedCompleteBridgeMessages(ctx, req.Address),
}, nil
}