findTransactionPlanResult

function findTransactionPlanResult<
    TContext,
    TTransactionMessage,
    TSingle,
>(
    transactionPlanResult,
    predicate,
):
    | TransactionPlanResult<TContext, TTransactionMessage, TSingle>
    | 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 typeDescription
TContext extends TransactionPlanResultContextTransactionPlanResultContextThe type of the context object that may be passed along with results
TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer<string>TransactionMessage & TransactionMessageWithFeePayer<string>The type of the transaction message
TSingle extends SingleTransactionPlanResult<TContext, TTransactionMessage>SingleTransactionPlanResult<TContext, TTransactionMessage>The type of single transaction plan results in this tree

Parameters

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

Returns

| TransactionPlanResult<TContext, TTransactionMessage, TSingle> | undefined

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

Example

Finding a failed transaction result.

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

See

On this page