Skip to content

Commit e32ddca

Browse files
authored
feat(blocktime): Implement query for SynchronyParams (#2686)
1 parent 949b46c commit e32ddca

File tree

10 files changed

+685
-39
lines changed

10 files changed

+685
-39
lines changed

indexer/packages/v4-protos/src/codegen/dydxprotocol/blocktime/query.lcd.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LCDClient } from "@osmonauts/lcd";
2-
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponseSDKType, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponseSDKType } from "./query";
2+
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponseSDKType, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponseSDKType, QuerySynchronyParamsRequest, QuerySynchronyParamsResponseSDKType } from "./query";
33
export class LCDQueryClient {
44
req: LCDClient;
55

@@ -11,6 +11,7 @@ export class LCDQueryClient {
1111
this.req = requestClient;
1212
this.downtimeParams = this.downtimeParams.bind(this);
1313
this.allDowntimeInfo = this.allDowntimeInfo.bind(this);
14+
this.synchronyParams = this.synchronyParams.bind(this);
1415
}
1516
/* Queries the DowntimeParams. */
1617

@@ -26,5 +27,12 @@ export class LCDQueryClient {
2627
const endpoint = `dydxprotocol/v4/blocktime/all_downtime_info`;
2728
return await this.req.get<QueryAllDowntimeInfoResponseSDKType>(endpoint);
2829
}
30+
/* Queries the SynchronyParams. */
31+
32+
33+
async synchronyParams(_params: QuerySynchronyParamsRequest = {}): Promise<QuerySynchronyParamsResponseSDKType> {
34+
const endpoint = `dydxprotocol/v4/blocktime/synchrony_params`;
35+
return await this.req.get<QuerySynchronyParamsResponseSDKType>(endpoint);
36+
}
2937

3038
}

indexer/packages/v4-protos/src/codegen/dydxprotocol/blocktime/query.rpc.Query.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Rpc } from "../../helpers";
22
import * as _m0 from "protobufjs/minimal";
33
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate";
4-
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponse, QueryPreviousBlockInfoRequest, QueryPreviousBlockInfoResponse, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponse } from "./query";
4+
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponse, QueryPreviousBlockInfoRequest, QueryPreviousBlockInfoResponse, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponse, QuerySynchronyParamsRequest, QuerySynchronyParamsResponse } from "./query";
55
/** Query defines the gRPC querier service. */
66

77
export interface Query {
@@ -13,6 +13,9 @@ export interface Query {
1313
/** Queries all recorded downtime info. */
1414

1515
allDowntimeInfo(request?: QueryAllDowntimeInfoRequest): Promise<QueryAllDowntimeInfoResponse>;
16+
/** Queries the SynchronyParams. */
17+
18+
synchronyParams(request?: QuerySynchronyParamsRequest): Promise<QuerySynchronyParamsResponse>;
1619
}
1720
export class QueryClientImpl implements Query {
1821
private readonly rpc: Rpc;
@@ -22,6 +25,7 @@ export class QueryClientImpl implements Query {
2225
this.downtimeParams = this.downtimeParams.bind(this);
2326
this.previousBlockInfo = this.previousBlockInfo.bind(this);
2427
this.allDowntimeInfo = this.allDowntimeInfo.bind(this);
28+
this.synchronyParams = this.synchronyParams.bind(this);
2529
}
2630

2731
downtimeParams(request: QueryDowntimeParamsRequest = {}): Promise<QueryDowntimeParamsResponse> {
@@ -42,6 +46,12 @@ export class QueryClientImpl implements Query {
4246
return promise.then(data => QueryAllDowntimeInfoResponse.decode(new _m0.Reader(data)));
4347
}
4448

49+
synchronyParams(request: QuerySynchronyParamsRequest = {}): Promise<QuerySynchronyParamsResponse> {
50+
const data = QuerySynchronyParamsRequest.encode(request).finish();
51+
const promise = this.rpc.request("dydxprotocol.blocktime.Query", "SynchronyParams", data);
52+
return promise.then(data => QuerySynchronyParamsResponse.decode(new _m0.Reader(data)));
53+
}
54+
4555
}
4656
export const createRpcQueryExtension = (base: QueryClient) => {
4757
const rpc = createProtobufRpcClient(base);
@@ -57,6 +67,10 @@ export const createRpcQueryExtension = (base: QueryClient) => {
5767

5868
allDowntimeInfo(request?: QueryAllDowntimeInfoRequest): Promise<QueryAllDowntimeInfoResponse> {
5969
return queryService.allDowntimeInfo(request);
70+
},
71+
72+
synchronyParams(request?: QuerySynchronyParamsRequest): Promise<QuerySynchronyParamsResponse> {
73+
return queryService.synchronyParams(request);
6074
}
6175

6276
};

indexer/packages/v4-protos/src/codegen/dydxprotocol/blocktime/query.ts

+96-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
import { DowntimeParams, DowntimeParamsSDKType } from "./params";
1+
import { SynchronyParams, SynchronyParamsSDKType, DowntimeParams, DowntimeParamsSDKType } from "./params";
22
import { BlockInfo, BlockInfoSDKType, AllDowntimeInfo, AllDowntimeInfoSDKType } from "./blocktime";
33
import * as _m0 from "protobufjs/minimal";
44
import { DeepPartial } from "../../helpers";
5+
/** QuerySynchronyParamsRequest is a request type for the SynchronyParams */
6+
7+
export interface QuerySynchronyParamsRequest {}
8+
/** QuerySynchronyParamsRequest is a request type for the SynchronyParams */
9+
10+
export interface QuerySynchronyParamsRequestSDKType {}
11+
/** QuerySynchronyParamsResponse is a response type for the SynchronyParams */
12+
13+
export interface QuerySynchronyParamsResponse {
14+
params?: SynchronyParams;
15+
}
16+
/** QuerySynchronyParamsResponse is a response type for the SynchronyParams */
17+
18+
export interface QuerySynchronyParamsResponseSDKType {
19+
params?: SynchronyParamsSDKType;
20+
}
521
/**
622
* QueryDowntimeParamsRequest is a request type for the DowntimeParams
723
* RPC method.
@@ -103,6 +119,85 @@ export interface QueryAllDowntimeInfoResponseSDKType {
103119
info?: AllDowntimeInfoSDKType;
104120
}
105121

122+
function createBaseQuerySynchronyParamsRequest(): QuerySynchronyParamsRequest {
123+
return {};
124+
}
125+
126+
export const QuerySynchronyParamsRequest = {
127+
encode(_: QuerySynchronyParamsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
128+
return writer;
129+
},
130+
131+
decode(input: _m0.Reader | Uint8Array, length?: number): QuerySynchronyParamsRequest {
132+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
133+
let end = length === undefined ? reader.len : reader.pos + length;
134+
const message = createBaseQuerySynchronyParamsRequest();
135+
136+
while (reader.pos < end) {
137+
const tag = reader.uint32();
138+
139+
switch (tag >>> 3) {
140+
default:
141+
reader.skipType(tag & 7);
142+
break;
143+
}
144+
}
145+
146+
return message;
147+
},
148+
149+
fromPartial(_: DeepPartial<QuerySynchronyParamsRequest>): QuerySynchronyParamsRequest {
150+
const message = createBaseQuerySynchronyParamsRequest();
151+
return message;
152+
}
153+
154+
};
155+
156+
function createBaseQuerySynchronyParamsResponse(): QuerySynchronyParamsResponse {
157+
return {
158+
params: undefined
159+
};
160+
}
161+
162+
export const QuerySynchronyParamsResponse = {
163+
encode(message: QuerySynchronyParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
164+
if (message.params !== undefined) {
165+
SynchronyParams.encode(message.params, writer.uint32(10).fork()).ldelim();
166+
}
167+
168+
return writer;
169+
},
170+
171+
decode(input: _m0.Reader | Uint8Array, length?: number): QuerySynchronyParamsResponse {
172+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
173+
let end = length === undefined ? reader.len : reader.pos + length;
174+
const message = createBaseQuerySynchronyParamsResponse();
175+
176+
while (reader.pos < end) {
177+
const tag = reader.uint32();
178+
179+
switch (tag >>> 3) {
180+
case 1:
181+
message.params = SynchronyParams.decode(reader, reader.uint32());
182+
break;
183+
184+
default:
185+
reader.skipType(tag & 7);
186+
break;
187+
}
188+
}
189+
190+
return message;
191+
},
192+
193+
fromPartial(object: DeepPartial<QuerySynchronyParamsResponse>): QuerySynchronyParamsResponse {
194+
const message = createBaseQuerySynchronyParamsResponse();
195+
message.params = object.params !== undefined && object.params !== null ? SynchronyParams.fromPartial(object.params) : undefined;
196+
return message;
197+
}
198+
199+
};
200+
106201
function createBaseQueryDowntimeParamsRequest(): QueryDowntimeParamsRequest {
107202
return {};
108203
}

proto/dydxprotocol/blocktime/query.proto

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ service Query {
2626
option (google.api.http).get =
2727
"/dydxprotocol/v4/blocktime/all_downtime_info";
2828
}
29+
30+
// Queries the SynchronyParams.
31+
rpc SynchronyParams(QuerySynchronyParamsRequest)
32+
returns (QuerySynchronyParamsResponse) {
33+
option (google.api.http).get =
34+
"/dydxprotocol/v4/blocktime/synchrony_params";
35+
}
36+
}
37+
38+
// QuerySynchronyParamsRequest is a request type for the SynchronyParams
39+
message QuerySynchronyParamsRequest {}
40+
41+
// QuerySynchronyParamsResponse is a response type for the SynchronyParams
42+
message QuerySynchronyParamsResponse {
43+
SynchronyParams params = 1 [ (gogoproto.nullable) = false ];
2944
}
3045

3146
// QueryDowntimeParamsRequest is a request type for the DowntimeParams

protocol/mocks/QueryClient.go

+38-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/x/blocktime/client/cli/query.go

+24
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
2424
cmd.AddCommand(CmdQueryDowntimeParams())
2525
cmd.AddCommand(CmdQueryAllDowntimeInfo())
2626
cmd.AddCommand(CmdQueryPreviousBlockInfo())
27+
cmd.AddCommand(CmdQuerySynchronyParams())
2728

2829
return cmd
2930
}
@@ -96,3 +97,26 @@ func CmdQueryPreviousBlockInfo() *cobra.Command {
9697

9798
return cmd
9899
}
100+
101+
func CmdQuerySynchronyParams() *cobra.Command {
102+
cmd := &cobra.Command{
103+
Use: "sychrony-params",
104+
Short: "get synchrony params",
105+
RunE: func(cmd *cobra.Command, args []string) (err error) {
106+
clientCtx := client.GetClientContextFromCmd(cmd)
107+
queryClient := types.NewQueryClient(clientCtx)
108+
res, err := queryClient.SynchronyParams(
109+
context.Background(),
110+
&types.QuerySynchronyParamsRequest{},
111+
)
112+
if err != nil {
113+
return err
114+
}
115+
return clientCtx.PrintProto(res)
116+
},
117+
}
118+
119+
flags.AddQueryFlagsToCmd(cmd)
120+
121+
return cmd
122+
}

protocol/x/blocktime/keeper/grpc_query.go

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ import (
1111

1212
var _ types.QueryServer = Keeper{}
1313

14+
func (k Keeper) SynchronyParams(
15+
c context.Context,
16+
req *types.QuerySynchronyParamsRequest,
17+
) (
18+
*types.QuerySynchronyParamsResponse,
19+
error,
20+
) {
21+
if req == nil {
22+
return nil, status.Error(codes.InvalidArgument, "invalid request")
23+
}
24+
25+
ctx := lib.UnwrapSDKContext(c, types.ModuleName)
26+
params := k.GetSynchronyParams(ctx)
27+
return &types.QuerySynchronyParamsResponse{
28+
Params: params,
29+
}, nil
30+
}
31+
1432
func (k Keeper) DowntimeParams(
1533
c context.Context,
1634
req *types.QueryDowntimeParamsRequest,

protocol/x/blocktime/keeper/grpc_query_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ import (
1212
"github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types"
1313
)
1414

15+
func TestSynchronyParams(t *testing.T) {
16+
tApp := testapp.NewTestAppBuilder(t).Build()
17+
ctx := tApp.InitChain()
18+
k := tApp.App.BlockTimeKeeper
19+
20+
for name, tc := range map[string]struct {
21+
req *types.QuerySynchronyParamsRequest
22+
res *types.QuerySynchronyParamsResponse
23+
err error
24+
}{
25+
"Default": {
26+
req: &types.QuerySynchronyParamsRequest{},
27+
res: &types.QuerySynchronyParamsResponse{
28+
Params: types.DefaultSynchronyParams(),
29+
},
30+
err: nil,
31+
},
32+
"Nil": {
33+
req: nil,
34+
res: nil,
35+
err: status.Error(codes.InvalidArgument, "invalid request"),
36+
},
37+
} {
38+
t.Run(name, func(t *testing.T) {
39+
res, err := k.SynchronyParams(ctx, tc.req)
40+
if tc.err != nil {
41+
require.ErrorIs(t, err, tc.err)
42+
} else {
43+
require.NoError(t, err)
44+
require.Equal(t, tc.res, res)
45+
}
46+
})
47+
}
48+
}
49+
1550
func TestDowntimeParams(t *testing.T) {
1651
tApp := testapp.NewTestAppBuilder(t).Build()
1752
ctx := tApp.InitChain()

0 commit comments

Comments
 (0)