Skip to content

Commit

Permalink
refactor(experimental): type reconciliation: simulateTransactionApi (
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec authored Jul 2, 2024
1 parent 00e5dcf commit c49f5ce
Showing 1 changed file with 73 additions and 41 deletions.
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>;
}

0 comments on commit c49f5ce

Please sign in to comment.