|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { |
10 | | - assertAccountExists, |
11 | | - assertAccountsExist, |
12 | | - combineCodec, |
13 | | - decodeAccount, |
14 | | - fetchEncodedAccount, |
15 | | - fetchEncodedAccounts, |
16 | | - getStructDecoder, |
17 | | - getStructEncoder, |
18 | | - type Account, |
19 | | - type Address, |
20 | | - type Codec, |
21 | | - type Decoder, |
22 | | - type EncodedAccount, |
23 | | - type Encoder, |
24 | | - type FetchAccountConfig, |
25 | | - type FetchAccountsConfig, |
26 | | - type MaybeAccount, |
27 | | - type MaybeEncodedAccount, |
| 10 | + assertAccountExists, |
| 11 | + assertAccountsExist, |
| 12 | + combineCodec, |
| 13 | + decodeAccount, |
| 14 | + fetchEncodedAccount, |
| 15 | + fetchEncodedAccounts, |
| 16 | + getStructDecoder, |
| 17 | + getStructEncoder, |
| 18 | + type Account, |
| 19 | + type Address, |
| 20 | + type Codec, |
| 21 | + type Decoder, |
| 22 | + type EncodedAccount, |
| 23 | + type Encoder, |
| 24 | + type FetchAccountConfig, |
| 25 | + type FetchAccountsConfig, |
| 26 | + type MaybeAccount, |
| 27 | + type MaybeEncodedAccount, |
28 | 28 | } from '@solana/kit'; |
29 | | -import { |
30 | | - getStakeStateV2Decoder, |
31 | | - getStakeStateV2Encoder, |
32 | | - type StakeStateV2, |
33 | | - type StakeStateV2Args, |
34 | | -} from '../types'; |
| 29 | +import { getStakeStateV2Decoder, getStakeStateV2Encoder, type StakeStateV2, type StakeStateV2Args } from '../types'; |
35 | 30 |
|
36 | 31 | export type StakeStateAccount = { state: StakeStateV2 }; |
37 | 32 |
|
38 | 33 | export type StakeStateAccountArgs = { state: StakeStateV2Args }; |
39 | 34 |
|
| 35 | +/** Gets the encoder for {@link StakeStateAccountArgs} account data. */ |
40 | 36 | export function getStakeStateAccountEncoder(): Encoder<StakeStateAccountArgs> { |
41 | | - return getStructEncoder([['state', getStakeStateV2Encoder()]]); |
| 37 | + return getStructEncoder([['state', getStakeStateV2Encoder()]]); |
42 | 38 | } |
43 | 39 |
|
| 40 | +/** Gets the decoder for {@link StakeStateAccount} account data. */ |
44 | 41 | export function getStakeStateAccountDecoder(): Decoder<StakeStateAccount> { |
45 | | - return getStructDecoder([['state', getStakeStateV2Decoder()]]); |
| 42 | + return getStructDecoder([['state', getStakeStateV2Decoder()]]); |
46 | 43 | } |
47 | 44 |
|
48 | | -export function getStakeStateAccountCodec(): Codec< |
49 | | - StakeStateAccountArgs, |
50 | | - StakeStateAccount |
51 | | -> { |
52 | | - return combineCodec( |
53 | | - getStakeStateAccountEncoder(), |
54 | | - getStakeStateAccountDecoder() |
55 | | - ); |
| 45 | +/** Gets the codec for {@link StakeStateAccount} account data. */ |
| 46 | +export function getStakeStateAccountCodec(): Codec<StakeStateAccountArgs, StakeStateAccount> { |
| 47 | + return combineCodec(getStakeStateAccountEncoder(), getStakeStateAccountDecoder()); |
56 | 48 | } |
57 | 49 |
|
58 | 50 | export function decodeStakeStateAccount<TAddress extends string = string>( |
59 | | - encodedAccount: EncodedAccount<TAddress> |
| 51 | + encodedAccount: EncodedAccount<TAddress>, |
60 | 52 | ): Account<StakeStateAccount, TAddress>; |
61 | 53 | export function decodeStakeStateAccount<TAddress extends string = string>( |
62 | | - encodedAccount: MaybeEncodedAccount<TAddress> |
| 54 | + encodedAccount: MaybeEncodedAccount<TAddress>, |
63 | 55 | ): MaybeAccount<StakeStateAccount, TAddress>; |
64 | 56 | export function decodeStakeStateAccount<TAddress extends string = string>( |
65 | | - encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress> |
66 | | -): |
67 | | - | Account<StakeStateAccount, TAddress> |
68 | | - | MaybeAccount<StakeStateAccount, TAddress> { |
69 | | - return decodeAccount( |
70 | | - encodedAccount as MaybeEncodedAccount<TAddress>, |
71 | | - getStakeStateAccountDecoder() |
72 | | - ); |
| 57 | + encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>, |
| 58 | +): Account<StakeStateAccount, TAddress> | MaybeAccount<StakeStateAccount, TAddress> { |
| 59 | + return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getStakeStateAccountDecoder()); |
73 | 60 | } |
74 | 61 |
|
75 | 62 | export async function fetchStakeStateAccount<TAddress extends string = string>( |
76 | | - rpc: Parameters<typeof fetchEncodedAccount>[0], |
77 | | - address: Address<TAddress>, |
78 | | - config?: FetchAccountConfig |
| 63 | + rpc: Parameters<typeof fetchEncodedAccount>[0], |
| 64 | + address: Address<TAddress>, |
| 65 | + config?: FetchAccountConfig, |
79 | 66 | ): Promise<Account<StakeStateAccount, TAddress>> { |
80 | | - const maybeAccount = await fetchMaybeStakeStateAccount(rpc, address, config); |
81 | | - assertAccountExists(maybeAccount); |
82 | | - return maybeAccount; |
| 67 | + const maybeAccount = await fetchMaybeStakeStateAccount(rpc, address, config); |
| 68 | + assertAccountExists(maybeAccount); |
| 69 | + return maybeAccount; |
83 | 70 | } |
84 | 71 |
|
85 | | -export async function fetchMaybeStakeStateAccount< |
86 | | - TAddress extends string = string, |
87 | | ->( |
88 | | - rpc: Parameters<typeof fetchEncodedAccount>[0], |
89 | | - address: Address<TAddress>, |
90 | | - config?: FetchAccountConfig |
| 72 | +export async function fetchMaybeStakeStateAccount<TAddress extends string = string>( |
| 73 | + rpc: Parameters<typeof fetchEncodedAccount>[0], |
| 74 | + address: Address<TAddress>, |
| 75 | + config?: FetchAccountConfig, |
91 | 76 | ): Promise<MaybeAccount<StakeStateAccount, TAddress>> { |
92 | | - const maybeAccount = await fetchEncodedAccount(rpc, address, config); |
93 | | - return decodeStakeStateAccount(maybeAccount); |
| 77 | + const maybeAccount = await fetchEncodedAccount(rpc, address, config); |
| 78 | + return decodeStakeStateAccount(maybeAccount); |
94 | 79 | } |
95 | 80 |
|
96 | 81 | export async function fetchAllStakeStateAccount( |
97 | | - rpc: Parameters<typeof fetchEncodedAccounts>[0], |
98 | | - addresses: Array<Address>, |
99 | | - config?: FetchAccountsConfig |
| 82 | + rpc: Parameters<typeof fetchEncodedAccounts>[0], |
| 83 | + addresses: Array<Address>, |
| 84 | + config?: FetchAccountsConfig, |
100 | 85 | ): Promise<Account<StakeStateAccount>[]> { |
101 | | - const maybeAccounts = await fetchAllMaybeStakeStateAccount( |
102 | | - rpc, |
103 | | - addresses, |
104 | | - config |
105 | | - ); |
106 | | - assertAccountsExist(maybeAccounts); |
107 | | - return maybeAccounts; |
| 86 | + const maybeAccounts = await fetchAllMaybeStakeStateAccount(rpc, addresses, config); |
| 87 | + assertAccountsExist(maybeAccounts); |
| 88 | + return maybeAccounts; |
108 | 89 | } |
109 | 90 |
|
110 | 91 | export async function fetchAllMaybeStakeStateAccount( |
111 | | - rpc: Parameters<typeof fetchEncodedAccounts>[0], |
112 | | - addresses: Array<Address>, |
113 | | - config?: FetchAccountsConfig |
| 92 | + rpc: Parameters<typeof fetchEncodedAccounts>[0], |
| 93 | + addresses: Array<Address>, |
| 94 | + config?: FetchAccountsConfig, |
114 | 95 | ): Promise<MaybeAccount<StakeStateAccount>[]> { |
115 | | - const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); |
116 | | - return maybeAccounts.map((maybeAccount) => |
117 | | - decodeStakeStateAccount(maybeAccount) |
118 | | - ); |
| 96 | + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); |
| 97 | + return maybeAccounts.map(maybeAccount => decodeStakeStateAccount(maybeAccount)); |
119 | 98 | } |
0 commit comments