Skip to content

Commit a1b42e8

Browse files
committed
Add query for accountplus state
1 parent 7117942 commit a1b42e8

File tree

8 files changed

+748
-40
lines changed

8 files changed

+748
-40
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LCDClient } from "@osmonauts/lcd";
2-
import { QueryParamsRequest, QueryParamsResponseSDKType, GetAuthenticatorRequest, GetAuthenticatorResponseSDKType, GetAuthenticatorsRequest, GetAuthenticatorsResponseSDKType } from "./query";
2+
import { QueryParamsRequest, QueryParamsResponseSDKType, GetAuthenticatorRequest, GetAuthenticatorResponseSDKType, GetAuthenticatorsRequest, GetAuthenticatorsResponseSDKType, AccountStateRequest, AccountStateResponseSDKType } from "./query";
33
export class LCDQueryClient {
44
req: LCDClient;
55

@@ -12,6 +12,7 @@ export class LCDQueryClient {
1212
this.params = this.params.bind(this);
1313
this.getAuthenticator = this.getAuthenticator.bind(this);
1414
this.getAuthenticators = this.getAuthenticators.bind(this);
15+
this.accountState = this.accountState.bind(this);
1516
}
1617
/* Parameters queries the parameters of the module. */
1718

@@ -34,5 +35,12 @@ export class LCDQueryClient {
3435
const endpoint = `dydxprotocol/accountplus/authenticators/${params.account}`;
3536
return await this.req.get<GetAuthenticatorsResponseSDKType>(endpoint);
3637
}
38+
/* Queries for an account state (timestamp nonce). */
39+
40+
41+
async accountState(params: AccountStateRequest): Promise<AccountStateResponseSDKType> {
42+
const endpoint = `dydxprotocol/accountplus/account_state/${params.address}`;
43+
return await this.req.get<AccountStateResponseSDKType>(endpoint);
44+
}
3745

3846
}

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

Lines changed: 15 additions & 1 deletion
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 { QueryParamsRequest, QueryParamsResponse, GetAuthenticatorRequest, GetAuthenticatorResponse, GetAuthenticatorsRequest, GetAuthenticatorsResponse } from "./query";
4+
import { QueryParamsRequest, QueryParamsResponse, GetAuthenticatorRequest, GetAuthenticatorResponse, GetAuthenticatorsRequest, GetAuthenticatorsResponse, AccountStateRequest, AccountStateResponse } from "./query";
55
/** Query defines the gRPC querier service. */
66

77
export interface Query {
@@ -13,6 +13,9 @@ export interface Query {
1313
/** Queries all authenticators for a given account. */
1414

1515
getAuthenticators(request: GetAuthenticatorsRequest): Promise<GetAuthenticatorsResponse>;
16+
/** Queries for an account state (timestamp nonce). */
17+
18+
accountState(request: AccountStateRequest): Promise<AccountStateResponse>;
1619
}
1720
export class QueryClientImpl implements Query {
1821
private readonly rpc: Rpc;
@@ -22,6 +25,7 @@ export class QueryClientImpl implements Query {
2225
this.params = this.params.bind(this);
2326
this.getAuthenticator = this.getAuthenticator.bind(this);
2427
this.getAuthenticators = this.getAuthenticators.bind(this);
28+
this.accountState = this.accountState.bind(this);
2529
}
2630

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

49+
accountState(request: AccountStateRequest): Promise<AccountStateResponse> {
50+
const data = AccountStateRequest.encode(request).finish();
51+
const promise = this.rpc.request("dydxprotocol.accountplus.Query", "AccountState", data);
52+
return promise.then(data => AccountStateResponse.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
getAuthenticators(request: GetAuthenticatorsRequest): Promise<GetAuthenticatorsResponse> {
5969
return queryService.getAuthenticators(request);
70+
},
71+
72+
accountState(request: AccountStateRequest): Promise<AccountStateResponse> {
73+
return queryService.accountState(request);
6074
}
6175

6276
};

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1+
import { AccountState, AccountStateSDKType } from "./accountplus";
12
import { Params, ParamsSDKType } from "./params";
23
import { AccountAuthenticator, AccountAuthenticatorSDKType } from "./models";
34
import * as _m0 from "protobufjs/minimal";
45
import { DeepPartial, Long } from "../../helpers";
6+
/** AccountStateResponse is request type for the Query/AccountState RPC method. */
7+
8+
export interface AccountStateRequest {
9+
/** AccountStateResponse is request type for the Query/AccountState RPC method. */
10+
address: string;
11+
}
12+
/** AccountStateResponse is request type for the Query/AccountState RPC method. */
13+
14+
export interface AccountStateRequestSDKType {
15+
/** AccountStateResponse is request type for the Query/AccountState RPC method. */
16+
address: string;
17+
}
18+
/**
19+
* GetAccountStateResponse is response type for the Query/GetAccountState RPC
20+
* method.
21+
*/
22+
23+
export interface AccountStateResponse {
24+
/**
25+
* GetAccountStateResponse is response type for the Query/GetAccountState RPC
26+
* method.
27+
*/
28+
accountState?: AccountState;
29+
}
30+
/**
31+
* GetAccountStateResponse is response type for the Query/GetAccountState RPC
32+
* method.
33+
*/
34+
35+
export interface AccountStateResponseSDKType {
36+
/**
37+
* GetAccountStateResponse is response type for the Query/GetAccountState RPC
38+
* method.
39+
*/
40+
account_state?: AccountStateSDKType;
41+
}
542
/** QueryParamsRequest is request type for the Query/Params RPC method. */
643

744
export interface QueryParamsRequest {}
@@ -65,6 +102,96 @@ export interface GetAuthenticatorResponseSDKType {
65102
account_authenticator?: AccountAuthenticatorSDKType;
66103
}
67104

105+
function createBaseAccountStateRequest(): AccountStateRequest {
106+
return {
107+
address: ""
108+
};
109+
}
110+
111+
export const AccountStateRequest = {
112+
encode(message: AccountStateRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
113+
if (message.address !== "") {
114+
writer.uint32(10).string(message.address);
115+
}
116+
117+
return writer;
118+
},
119+
120+
decode(input: _m0.Reader | Uint8Array, length?: number): AccountStateRequest {
121+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
122+
let end = length === undefined ? reader.len : reader.pos + length;
123+
const message = createBaseAccountStateRequest();
124+
125+
while (reader.pos < end) {
126+
const tag = reader.uint32();
127+
128+
switch (tag >>> 3) {
129+
case 1:
130+
message.address = reader.string();
131+
break;
132+
133+
default:
134+
reader.skipType(tag & 7);
135+
break;
136+
}
137+
}
138+
139+
return message;
140+
},
141+
142+
fromPartial(object: DeepPartial<AccountStateRequest>): AccountStateRequest {
143+
const message = createBaseAccountStateRequest();
144+
message.address = object.address ?? "";
145+
return message;
146+
}
147+
148+
};
149+
150+
function createBaseAccountStateResponse(): AccountStateResponse {
151+
return {
152+
accountState: undefined
153+
};
154+
}
155+
156+
export const AccountStateResponse = {
157+
encode(message: AccountStateResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
158+
if (message.accountState !== undefined) {
159+
AccountState.encode(message.accountState, writer.uint32(10).fork()).ldelim();
160+
}
161+
162+
return writer;
163+
},
164+
165+
decode(input: _m0.Reader | Uint8Array, length?: number): AccountStateResponse {
166+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
167+
let end = length === undefined ? reader.len : reader.pos + length;
168+
const message = createBaseAccountStateResponse();
169+
170+
while (reader.pos < end) {
171+
const tag = reader.uint32();
172+
173+
switch (tag >>> 3) {
174+
case 1:
175+
message.accountState = AccountState.decode(reader, reader.uint32());
176+
break;
177+
178+
default:
179+
reader.skipType(tag & 7);
180+
break;
181+
}
182+
}
183+
184+
return message;
185+
},
186+
187+
fromPartial(object: DeepPartial<AccountStateResponse>): AccountStateResponse {
188+
const message = createBaseAccountStateResponse();
189+
message.accountState = object.accountState !== undefined && object.accountState !== null ? AccountState.fromPartial(object.accountState) : undefined;
190+
return message;
191+
}
192+
193+
};
194+
68195
function createBaseQueryParamsRequest(): QueryParamsRequest {
69196
return {};
70197
}

proto/dydxprotocol/accountplus/query.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dydxprotocol.accountplus;
33

44
import "gogoproto/gogo.proto";
55
import "google/api/annotations.proto";
6+
import "dydxprotocol/accountplus/accountplus.proto";
67
import "dydxprotocol/accountplus/models.proto";
78
import "dydxprotocol/accountplus/params.proto";
89

@@ -28,8 +29,21 @@ service Query {
2829
option (google.api.http).get =
2930
"/dydxprotocol/accountplus/authenticators/{account}";
3031
}
32+
33+
// Queries for an account state (timestamp nonce).
34+
rpc AccountState(AccountStateRequest) returns (AccountStateResponse) {
35+
option (google.api.http).get =
36+
"/dydxprotocol/accountplus/account_state/{address}";
37+
}
3138
}
3239

40+
// AccountStateResponse is request type for the Query/AccountState RPC method.
41+
message AccountStateRequest { string address = 1; }
42+
43+
// GetAccountStateResponse is response type for the Query/GetAccountState RPC
44+
// method.
45+
message AccountStateResponse { AccountState account_state = 1; }
46+
3347
// QueryParamsRequest is request type for the Query/Params RPC method.
3448
message QueryParamsRequest {}
3549

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,30 @@ func CmdQueryGetAllAuthenticators() *cobra.Command {
114114
flags.AddQueryFlagsToCmd(cmd)
115115
return cmd
116116
}
117+
118+
func CmdQueryAccountState() *cobra.Command {
119+
cmd := &cobra.Command{
120+
Use: "account-state [address]",
121+
Short: "Geta account state for an address",
122+
Args: cobra.ExactArgs(1),
123+
RunE: func(cmd *cobra.Command, args []string) error {
124+
clientCtx, err := client.GetClientQueryContext(cmd)
125+
if err != nil {
126+
return err
127+
}
128+
queryClient := types.NewQueryClient(clientCtx)
129+
res, err := queryClient.AccountState(
130+
context.Background(),
131+
&types.AccountStateRequest{
132+
Address: args[0],
133+
},
134+
)
135+
if err != nil {
136+
return err
137+
}
138+
return clientCtx.PrintProto(res)
139+
},
140+
}
141+
flags.AddQueryFlagsToCmd(cmd)
142+
return cmd
143+
}

protocol/x/accountplus/keeper/query.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,26 @@ func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*t
6767

6868
return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
6969
}
70+
71+
// GetAccountState returns the x/accountplus account state for an address
72+
func (k Keeper) AccountState(
73+
ctx context.Context,
74+
request *types.AccountStateRequest,
75+
) (*types.AccountStateResponse, error) {
76+
if request == nil {
77+
return nil, status.Error(codes.InvalidArgument, "empty request")
78+
}
79+
80+
addr, err := sdk.AccAddressFromBech32(request.Address)
81+
if err != nil {
82+
return nil, status.Error(codes.InvalidArgument, "not valid bech32 address")
83+
}
84+
85+
sdkCtx := sdk.UnwrapSDKContext(ctx)
86+
// GetAccountState returns `empty, false` AccountState if the account does not exist.
87+
accountState, _ := k.GetAccountState(sdkCtx, addr)
88+
89+
return &types.AccountStateResponse{
90+
AccountState: &accountState,
91+
}, nil
92+
}

0 commit comments

Comments
 (0)