everyTransactionPlanResult

function everyTransactionPlanResult<
    TContext,
    TTransactionMessage,
    TSingle,
>(transactionPlanResult, predicate): boolean;

Checks if every transaction plan result in the tree satisfies the given predicate.

This function performs a depth-first traversal through the transaction plan result tree, returning true only if the predicate returns true for every result in the tree (including the root result and all 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 check.
predicate(plan) => booleanA function that returns true if the result satisfies the condition.

Returns

boolean

true if every result in the tree satisfies the predicate, false otherwise.

Examples

Checking if all transactions were successful.

const result = parallelTransactionPlanResult([
  successfulSingleTransactionPlanResultFromTransaction(messageA, transactionA),
  successfulSingleTransactionPlanResultFromTransaction(messageB, transactionB),
]);
 
const allSuccessful = everyTransactionPlanResult(
  result,
  (r) => r.kind !== 'single' || r.status === 'successful',
);
// Returns true because all single results are successful.

Checking if no transactions were canceled.

const result = sequentialTransactionPlanResult([resultA, resultB, resultC]);
 
const noCanceled = everyTransactionPlanResult(
  result,
  (r) => r.kind !== 'single' || r.status !== 'canceled',
);

See

On this page