transformTransactionPlan

function transformTransactionPlan(transactionPlan, fn): TransactionPlan;

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

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

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

Parameters

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

Returns

TransactionPlan

A new transformed transaction plan tree.

Examples

Removing parallelism by converting parallel plans to sequential.

const plan = parallelTransactionPlan([messageA, messageB, messageC]);
 
const transformed = transformTransactionPlan(plan, (p) => {
  if (p.kind === 'parallel') {
    return sequentialTransactionPlan(p.plans);
  }
  return p;
});

Updating the fee payer on all transaction messages.

const plan = parallelTransactionPlan([messageA, messageB]);
 
const transformed = transformTransactionPlan(plan, (p) => {
  if (p.kind === 'single') {
    return singleTransactionPlan({ ...p.message, feePayer: newFeePayer });
  }
  return p;
});

See

On this page