flattenTransactionPlan

function flattenTransactionPlan(transactionPlan): Readonly<{
    kind: 'single';
    message: TransactionMessage &
        TransactionMessageWithFeePayer<string>;
    planType: 'transactionPlan';
}>[];

Retrieves all individual SingleTransactionPlan instances from a transaction plan tree.

This function recursively traverses any nested structure of transaction plans and extracts all the single transaction plans they contain. It's useful when you need to access all the actual transaction messages that will be executed, regardless of their organization in the plan tree (parallel or sequential).

Parameters

ParameterTypeDescription
transactionPlanTransactionPlanThe transaction plan to extract single plans from

Returns

Readonly<{ kind: "single"; message: TransactionMessage & TransactionMessageWithFeePayer<string>; planType: "transactionPlan"; }>[]

An array of all single transaction plans contained in the tree

Example

const plan = parallelTransactionPlan([
  sequentialTransactionPlan([messageA, messageB]),
  nonDivisibleSequentialTransactionPlan([messageC, messageD]),
  messageE,
]);
 
const singlePlans = flattenTransactionPlan(plan);
// Array of `SingleTransactionPlan` containing:
// messageA, messageB, messageC and messageD.
 
@see {@link TransactionPlan}
@see {@link findTransactionPlan}
@see {@link everyTransactionPlan}
@see {@link transformTransactionPlan}

On this page