diff --git a/ts/src/program/context.ts b/ts/src/program/context.ts index 9003514924..01d4283af0 100644 --- a/ts/src/program/context.ts +++ b/ts/src/program/context.ts @@ -28,14 +28,21 @@ export type Context = { signers?: Array; /** + * @deprecated use preInstructions instead * Instructions to run *before* a given method. Often this is used, for * example to create accounts prior to executing a method. */ - instructions?: TransactionInstruction[]; + instructions?: TransactionInstruction[]; + + /** + * Instructions to run *before* a given method. Often this is used, for + * example to create accounts prior to executing a method. + */ + preInstructions?: TransactionInstruction[]; /** * Instructions to run *after* a given method. Often this is used, for - * example to close accounts after to executing a method. + * example to close accounts after executing a method. */ postInstructions?: TransactionInstruction[]; diff --git a/ts/src/program/namespace/transaction.ts b/ts/src/program/namespace/transaction.ts index 72eccabf73..df9ed698f3 100644 --- a/ts/src/program/namespace/transaction.ts +++ b/ts/src/program/namespace/transaction.ts @@ -16,6 +16,10 @@ export default class TransactionFactory { const txFn: TransactionFn = (...args): Transaction => { const [, ctx] = splitArgsAndCtx(idlIx, [...args]); const tx = new Transaction(); + if(ctx.preInstructions && ctx.preInstructions.length && ctx.instructions && ctx.instructions.length){ + throw new Error("instructions is deprecated, use preInstructions") + } + ctx.preInstructions?.forEach((ix) => tx.add(ix)); ctx.instructions?.forEach((ix) => tx.add(ix)); tx.add(ixFn(...args)); ctx.postInstructions?.forEach((ix) => tx.add(ix));