transformTransactionPlanResult

function transformTransactionPlanResult(
    transactionPlanResult,
    fn,
): TransactionPlanResult;

Transforms a transaction plan result tree using a bottom-up approach.

This function recursively traverses the transaction plan result tree, applying the transformation function to each result. The transformation is applied bottom-up, meaning nested results are transformed first, then the parent results receive the already-transformed children before being transformed themselves.

All transformed results are frozen using Object.freeze to ensure immutability.

Parameters

ParameterTypeDescription
transactionPlanResultTransactionPlanResultThe transaction plan result tree to transform.
fn(plan) => TransactionPlanResultA function that transforms each result and returns a new result.

Returns

TransactionPlanResult

A new transformed transaction plan result tree.

Example

Converting all canceled results to failed results.

const result = parallelTransactionPlanResult([
  successfulSingleTransactionPlanResultFromTransaction(messageA, transactionA),
  canceledSingleTransactionPlanResult(messageB),
]);
 
const transformed = transformTransactionPlanResult(result, (r) => {
  if (r.kind === 'single' && r.status === 'canceled') {
    return failedSingleTransactionPlanResult(r.plannedMessage, new Error('Execution canceled'));
  }
  return r;
});

See

On this page