Skip to content

Commit c49f5ce

Browse files
authored
refactor(experimental): type reconciliation: simulateTransactionApi (#2895)
1 parent 00e5dcf commit c49f5ce

File tree

1 file changed

+73
-41
lines changed

1 file changed

+73
-41
lines changed

packages/rpc-api/src/simulateTransaction.ts

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type WithInnerInstructionsConfig = Readonly<{
8787
innerInstructions: true;
8888
}>;
8989

90-
type SimulateTransactionApiResponseBase = SolanaRpcResponse<{
90+
type SimulateTransactionApiResponseBase = Readonly<{
9191
/** Error if transaction failed, null if transaction succeeded. */
9292
err: TransactionError | null;
9393
/** Array of log messages the transaction instructions output during execution, null if simulation failed before the transaction was able to execute (for example due to an invalid blockhash or signature verification failure) */
@@ -108,12 +108,12 @@ type SimulateTransactionApiResponseBase = SolanaRpcResponse<{
108108
unitsConsumed?: U64UnsafeBeyond2Pow53Minus1;
109109
}>;
110110

111-
type SimulateTransactionApiResponseWithAccounts<T extends AccountInfoBase> = SolanaRpcResponse<{
111+
type SimulateTransactionApiResponseWithAccounts<T extends AccountInfoBase> = Readonly<{
112112
/** Array of accounts with the same length as the `accounts.addresses` array in the request */
113113
accounts: (T | null)[];
114114
}>;
115115

116-
type SimulateTransactionApiResponseWithInnerInstructions = SolanaRpcResponse<
116+
type SimulateTransactionApiResponseWithInnerInstructions = Readonly<
117117
TransactionForFullMetaInnerInstructionsParsed | TransactionForFullMetaInnerInstructionsUnparsed
118118
>;
119119

@@ -125,18 +125,22 @@ export interface SimulateTransactionApi extends RpcApiMethods {
125125
SigVerifyAndReplaceRecentBlockhashConfig &
126126
SimulateTransactionConfigBase &
127127
WithInnerInstructionsConfig,
128-
): SimulateTransactionApiResponseBase &
129-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
130-
SimulateTransactionApiResponseWithInnerInstructions;
128+
): SolanaRpcResponse<
129+
SimulateTransactionApiResponseBase &
130+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
131+
SimulateTransactionApiResponseWithInnerInstructions
132+
>;
131133

132134
/** @deprecated Set `encoding` to `'base64'` when calling this method */
133135
simulateTransaction(
134136
base58EncodedWireTransaction: Base58EncodedBytes,
135137
config: AccountsConfigWithBase64Encoding &
136138
SigVerifyAndReplaceRecentBlockhashConfig &
137139
SimulateTransactionConfigBase,
138-
): SimulateTransactionApiResponseBase &
139-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>;
140+
): SolanaRpcResponse<
141+
SimulateTransactionApiResponseBase &
142+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>
143+
>;
140144

141145
/** @deprecated Set `encoding` to `'base64'` when calling this method */
142146
simulateTransaction(
@@ -145,18 +149,24 @@ export interface SimulateTransactionApi extends RpcApiMethods {
145149
SigVerifyAndReplaceRecentBlockhashConfig &
146150
SimulateTransactionConfigBase &
147151
WithInnerInstructionsConfig,
148-
): SimulateTransactionApiResponseBase &
149-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData> &
150-
SimulateTransactionApiResponseWithInnerInstructions;
152+
): SolanaRpcResponse<
153+
SimulateTransactionApiResponseBase &
154+
SimulateTransactionApiResponseWithAccounts<
155+
AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData
156+
> &
157+
SimulateTransactionApiResponseWithInnerInstructions
158+
>;
151159

152160
/** @deprecated Set `encoding` to `'base64'` when calling this method */
153161
simulateTransaction(
154162
base58EncodedWireTransaction: Base58EncodedBytes,
155163
config: AccountsConfigWithBase64EncodingZstdCompression &
156164
SigVerifyAndReplaceRecentBlockhashConfig &
157165
SimulateTransactionConfigBase,
158-
): SimulateTransactionApiResponseBase &
159-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>;
166+
): SolanaRpcResponse<
167+
SimulateTransactionApiResponseBase &
168+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>
169+
>;
160170

161171
/** @deprecated Set `encoding` to `'base64'` when calling this method */
162172
simulateTransaction(
@@ -165,32 +175,38 @@ export interface SimulateTransactionApi extends RpcApiMethods {
165175
SigVerifyAndReplaceRecentBlockhashConfig &
166176
SimulateTransactionConfigBase &
167177
WithInnerInstructionsConfig,
168-
): SimulateTransactionApiResponseBase &
169-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
170-
SimulateTransactionApiResponseWithInnerInstructions;
178+
): SolanaRpcResponse<
179+
SimulateTransactionApiResponseBase &
180+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
181+
SimulateTransactionApiResponseWithInnerInstructions
182+
>;
171183

172184
/** @deprecated Set `encoding` to `'base64'` when calling this method */
173185
simulateTransaction(
174186
base58EncodedWireTransaction: Base58EncodedBytes,
175187
config: AccountsConfigWithJsonParsedEncoding &
176188
SigVerifyAndReplaceRecentBlockhashConfig &
177189
SimulateTransactionConfigBase,
178-
): SimulateTransactionApiResponseBase &
179-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>;
190+
): SolanaRpcResponse<
191+
SimulateTransactionApiResponseBase &
192+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>
193+
>;
180194

181195
/** @deprecated Set `encoding` to `'base64'` when calling this method */
182196
simulateTransaction(
183197
base58EncodedWireTransaction: Base58EncodedBytes,
184198
config?: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase & WithInnerInstructionsConfig,
185-
): SimulateTransactionApiResponseBase &
186-
SimulateTransactionApiResponseWithInnerInstructions &
187-
SolanaRpcResponse<{ readonly accounts: null }>;
199+
): SolanaRpcResponse<
200+
Readonly<{ readonly accounts: null }> &
201+
SimulateTransactionApiResponseBase &
202+
SimulateTransactionApiResponseWithInnerInstructions
203+
>;
188204

189205
/** @deprecated Set `encoding` to `'base64'` when calling this method */
190206
simulateTransaction(
191207
base58EncodedWireTransaction: Base58EncodedBytes,
192208
config?: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase,
193-
): SimulateTransactionApiResponseBase & SolanaRpcResponse<{ readonly accounts: null }>;
209+
): SolanaRpcResponse<Readonly<{ readonly accounts: null }> & SimulateTransactionApiResponseBase>;
194210

195211
/** Simulate sending a transaction */
196212
simulateTransaction(
@@ -199,18 +215,22 @@ export interface SimulateTransactionApi extends RpcApiMethods {
199215
SigVerifyAndReplaceRecentBlockhashConfig &
200216
SimulateTransactionConfigBase &
201217
WithInnerInstructionsConfig & { encoding: 'base64' },
202-
): SimulateTransactionApiResponseBase &
203-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
204-
SimulateTransactionApiResponseWithInnerInstructions;
218+
): SolanaRpcResponse<
219+
SimulateTransactionApiResponseBase &
220+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
221+
SimulateTransactionApiResponseWithInnerInstructions
222+
>;
205223

206224
/** Simulate sending a transaction */
207225
simulateTransaction(
208226
base64EncodedWireTransaction: Base64EncodedWireTransaction,
209227
config: AccountsConfigWithBase64Encoding &
210228
SigVerifyAndReplaceRecentBlockhashConfig &
211229
SimulateTransactionConfigBase & { encoding: 'base64' },
212-
): SimulateTransactionApiResponseBase &
213-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>;
230+
): SolanaRpcResponse<
231+
SimulateTransactionApiResponseBase &
232+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>
233+
>;
214234

215235
/** Simulate sending a transaction */
216236
simulateTransaction(
@@ -219,18 +239,24 @@ export interface SimulateTransactionApi extends RpcApiMethods {
219239
SigVerifyAndReplaceRecentBlockhashConfig &
220240
SimulateTransactionConfigBase &
221241
WithInnerInstructionsConfig & { encoding: 'base64' },
222-
): SimulateTransactionApiResponseBase &
223-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData> &
224-
SimulateTransactionApiResponseWithInnerInstructions;
242+
): SolanaRpcResponse<
243+
SimulateTransactionApiResponseBase &
244+
SimulateTransactionApiResponseWithAccounts<
245+
AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData
246+
> &
247+
SimulateTransactionApiResponseWithInnerInstructions
248+
>;
225249

226250
/** Simulate sending a transaction */
227251
simulateTransaction(
228252
base64EncodedWireTransaction: Base64EncodedWireTransaction,
229253
config: AccountsConfigWithBase64EncodingZstdCompression &
230254
SigVerifyAndReplaceRecentBlockhashConfig &
231255
SimulateTransactionConfigBase & { encoding: 'base64' },
232-
): SimulateTransactionApiResponseBase &
233-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>;
256+
): SolanaRpcResponse<
257+
SimulateTransactionApiResponseBase &
258+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>
259+
>;
234260

235261
/** Simulate sending a transaction */
236262
simulateTransaction(
@@ -239,32 +265,38 @@ export interface SimulateTransactionApi extends RpcApiMethods {
239265
SigVerifyAndReplaceRecentBlockhashConfig &
240266
SimulateTransactionConfigBase &
241267
WithInnerInstructionsConfig & { encoding: 'base64' },
242-
): SimulateTransactionApiResponseBase &
243-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
244-
SimulateTransactionApiResponseWithInnerInstructions;
268+
): SolanaRpcResponse<
269+
SimulateTransactionApiResponseBase &
270+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
271+
SimulateTransactionApiResponseWithInnerInstructions
272+
>;
245273

246274
/** Simulate sending a transaction */
247275
simulateTransaction(
248276
base64EncodedWireTransaction: Base64EncodedWireTransaction,
249277
config: AccountsConfigWithJsonParsedEncoding &
250278
SigVerifyAndReplaceRecentBlockhashConfig &
251279
SimulateTransactionConfigBase & { encoding: 'base64' },
252-
): SimulateTransactionApiResponseBase &
253-
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>;
280+
): SolanaRpcResponse<
281+
SimulateTransactionApiResponseBase &
282+
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>
283+
>;
254284

255285
/** Simulate sending a transaction */
256286
simulateTransaction(
257287
base64EncodedWireTransaction: Base64EncodedWireTransaction,
258288
config: SigVerifyAndReplaceRecentBlockhashConfig &
259289
SimulateTransactionConfigBase &
260290
WithInnerInstructionsConfig & { encoding: 'base64' },
261-
): SimulateTransactionApiResponseBase &
262-
SimulateTransactionApiResponseWithInnerInstructions &
263-
SolanaRpcResponse<{ readonly accounts: null }>;
291+
): SolanaRpcResponse<
292+
Readonly<{ readonly accounts: null }> &
293+
SimulateTransactionApiResponseBase &
294+
SimulateTransactionApiResponseWithInnerInstructions
295+
>;
264296

265297
/** Simulate sending a transaction */
266298
simulateTransaction(
267299
base64EncodedWireTransaction: Base64EncodedWireTransaction,
268300
config: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase & { encoding: 'base64' },
269-
): SimulateTransactionApiResponseBase & SolanaRpcResponse<{ readonly accounts: null }>;
301+
): SolanaRpcResponse<Readonly<{ readonly accounts: null }> & SimulateTransactionApiResponseBase>;
270302
}

0 commit comments

Comments
 (0)