Skip to content

Commit b87de1a

Browse files
committed
Type definition of a more complicated RPC method, getAccountInfo
1 parent b2a8a82 commit b87de1a

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
import { GetAccountInfoApi } from './rpc-methods/getAccountInfo';
12
import { GetBlockHeightApi } from './rpc-methods/getBlockHeight';
23
import { GetBlocksApi } from './rpc-methods/getBlocks';
34

4-
declare interface JsonRpcApi extends GetBlockHeightApi, GetBlocksApi {}
5+
declare interface JsonRpcApi extends GetAccountInfoApi, GetBlockHeightApi, GetBlocksApi {}

packages/rpc-core/src/types/rpc-methods/common.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
declare type DataSlice = readonly {
2+
offset: number;
3+
length: number;
4+
};
5+
16
// TODO: Eventually move this into whatever package implements transactions
27
declare type Finality = 'confirmed' | 'finalized' | 'processed';
38

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { Base58EncodedAddress } from '@solana/keys';
2+
import { IJsonRPCTransport } from '../../rpc';
3+
4+
type Base64EncodedBytes = string & { readonly __base64EncodedBytes: unique symbol };
5+
type Base64EncodedZStdCompressedBytes = string & { readonly __base64EncodedZStdCompressedBytes: unique symbol };
6+
7+
type Base64EncodedDataResponse = [Base64EncodedBytes, 'base64'];
8+
type Base64EncodedZStdCompressedDataResponse = [Base64EncodedZStdCompressedBytes, 'base64+zstd'];
9+
10+
type GetAccountInfoApiResponseBase = Readonly<{
11+
context: Readonly<{
12+
slot: Slot;
13+
}>;
14+
value: Readonly<{
15+
executable: boolean;
16+
lamports: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
17+
owner: Base64EncodedAddress;
18+
rentEpoch: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
19+
space: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
20+
}> | null;
21+
}>;
22+
23+
type GetAccountInfoApiResponseWithEncodedData = Readonly<{
24+
value: Readonly<{
25+
data: Base64EncodedDataResponse;
26+
}> | null;
27+
}>;
28+
29+
type GetAccountInfoApiResponseWithEncodedZStdCompressedData = Readonly<{
30+
value: Readonly<{
31+
data: Base64EncodedZStdCompressedDataResponse;
32+
}> | null;
33+
}>;
34+
35+
type GetAccountInfoApiResponseWithJsonData = Readonly<{
36+
value: Readonly<{
37+
data:
38+
| Readonly<{
39+
// Name of the program that owns this account.
40+
program: string;
41+
parsed: unknown;
42+
space: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
43+
}>
44+
// If `jsonParsed` encoding is requested but a parser cannot be found for the given
45+
// account the `data` field falls back to `base64`.
46+
| Base64EncodedDataResponse;
47+
}> | null;
48+
}>;
49+
50+
type GetAccountInfoApiCommonConfig = readonly {
51+
// Defaults to `finalized`
52+
commitment?: Finality;
53+
// The minimum slot that the request can be evaluated at
54+
minContextSlot?: Slot;
55+
};
56+
57+
type GetAccountInfoApiBase64EncodingCommonConfig = readonly {
58+
// Limit the returned account data using the provided "offset: <usize>" and "length: <usize>" fields.
59+
dataSlice?: DataSlice;
60+
};
61+
62+
declare interface GetAccountInfoApi {
63+
/**
64+
* Returns all information associated with the account of provided public key
65+
*/
66+
getAccountInfo(
67+
transport: IJsonRPCTransport,
68+
address: Base58EncodedAddress,
69+
config?: readonly {
70+
encoding: 'base64';
71+
} &
72+
GetAccountInfoApiCommonConfig &
73+
GetAccountInfoApiBase64EncodingCommonConfig
74+
): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithEncodedData>;
75+
getAccountInfo(
76+
transport: IJsonRPCTransport,
77+
address: Base58EncodedAddress,
78+
config?: readonly {
79+
encoding: 'base64+zstd';
80+
} &
81+
GetAccountInfoApiCommonConfig &
82+
GetAccountInfoApiBase64EncodingCommonConfig
83+
): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithEncodedZStdCompressedData>;
84+
getAccountInfo(
85+
transport: IJsonRPCTransport,
86+
address: Base58EncodedAddress,
87+
config?: readonly {
88+
encoding: 'jsonParsed';
89+
} &
90+
GetAccountInfoApiCommonConfig
91+
): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithJsonData>;
92+
}

0 commit comments

Comments
 (0)