findTransactionPlanResult

function findTransactionPlanResult<TContext>(
    transactionPlanResult,
    predicate,
):
    | TransactionPlanResult<
          TContext,
          Readonly<{
              kind: 'single';
              message: TransactionMessage &
                  TransactionMessageWithFeePayer<string>;
              status: TransactionPlanResultStatus<TContext>;
          }>
      >
    | undefined;

Finds the first transaction plan result in the tree that matches the given predicate.

This function performs a depth-first search through the transaction plan result tree, returning the first result that satisfies the predicate. It checks the root result first, then recursively searches through nested results.

Type Parameters

Type ParameterDefault type
TContext extends TransactionPlanResultContextTransactionPlanResultContext

Parameters

ParameterTypeDescription
transactionPlanResultTransactionPlanResult<TContext>The transaction plan result tree to search.
predicate(result) => booleanA function that returns true for the result to find.

Returns

| TransactionPlanResult<TContext, Readonly<{ kind: "single"; message: TransactionMessage & TransactionMessageWithFeePayer<string>; status: TransactionPlanResultStatus<TContext>; }>> | undefined

The first matching transaction plan result, or undefined if no match is found.

Example

Finding a failed transaction result.

const result = parallelTransactionPlanResult([
  successfulSingleTransactionPlanResult(messageA, transactionA),
  failedSingleTransactionPlanResult(messageB, error),
]);
 
const failed = findTransactionPlanResult(
  result,
  (r) => r.kind === 'single' && r.status.kind === 'failed',
);
// Returns the failed single transaction plan result for messageB.

See

On this page