Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 73 additions & 41 deletions packages/rpc-api/src/simulateTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type WithInnerInstructionsConfig = Readonly<{
innerInstructions: true;
}>;

type SimulateTransactionApiResponseBase = SolanaRpcResponse<{
type SimulateTransactionApiResponseBase = Readonly<{
/** Error if transaction failed, null if transaction succeeded. */
err: TransactionError | null;
/** 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) */
Expand All @@ -108,12 +108,12 @@ type SimulateTransactionApiResponseBase = SolanaRpcResponse<{
unitsConsumed?: U64UnsafeBeyond2Pow53Minus1;
}>;

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

type SimulateTransactionApiResponseWithInnerInstructions = SolanaRpcResponse<
type SimulateTransactionApiResponseWithInnerInstructions = Readonly<
TransactionForFullMetaInnerInstructionsParsed | TransactionForFullMetaInnerInstructionsUnparsed
>;

Expand All @@ -125,18 +125,22 @@ export interface SimulateTransactionApi extends RpcApiMethods {
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
SimulateTransactionApiResponseWithInnerInstructions;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config: AccountsConfigWithBase64Encoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>
>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
Expand All @@ -145,18 +149,24 @@ export interface SimulateTransactionApi extends RpcApiMethods {
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData> &
SimulateTransactionApiResponseWithInnerInstructions;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<
AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData
> &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config: AccountsConfigWithBase64EncodingZstdCompression &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>
>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
Expand All @@ -165,32 +175,38 @@ export interface SimulateTransactionApi extends RpcApiMethods {
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
SimulateTransactionApiResponseWithInnerInstructions;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config: AccountsConfigWithJsonParsedEncoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>
>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config?: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase & WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithInnerInstructions &
SolanaRpcResponse<{ readonly accounts: null }>;
): SolanaRpcResponse<
Readonly<{ readonly accounts: null }> &
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithInnerInstructions
>;

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

/** Simulate sending a transaction */
simulateTransaction(
Expand All @@ -199,18 +215,22 @@ export interface SimulateTransactionApi extends RpcApiMethods {
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
SimulateTransactionApiResponseWithInnerInstructions;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: AccountsConfigWithBase64Encoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>
>;

/** Simulate sending a transaction */
simulateTransaction(
Expand All @@ -219,18 +239,24 @@ export interface SimulateTransactionApi extends RpcApiMethods {
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData> &
SimulateTransactionApiResponseWithInnerInstructions;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<
AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData
> &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: AccountsConfigWithBase64EncodingZstdCompression &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>
>;

/** Simulate sending a transaction */
simulateTransaction(
Expand All @@ -239,32 +265,38 @@ export interface SimulateTransactionApi extends RpcApiMethods {
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
SimulateTransactionApiResponseWithInnerInstructions;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: AccountsConfigWithJsonParsedEncoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>;
): SolanaRpcResponse<
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>
>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithInnerInstructions &
SolanaRpcResponse<{ readonly accounts: null }>;
): SolanaRpcResponse<
Readonly<{ readonly accounts: null }> &
SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithInnerInstructions
>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase & { encoding: 'base64' },
): SimulateTransactionApiResponseBase & SolanaRpcResponse<{ readonly accounts: null }>;
): SolanaRpcResponse<Readonly<{ readonly accounts: null }> & SimulateTransactionApiResponseBase>;
}