Skip to content

Commit

Permalink
Add preInstructions
Browse files Browse the repository at this point in the history
  • Loading branch information
SolanaMonkeyBusiness committed Nov 13, 2021
1 parent ab7180f commit 4624572
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ts/src/program/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ export type Context<A extends Accounts = Accounts> = {
signers?: Array<Signer>;

/**
* @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[];

Expand Down
4 changes: 4 additions & 0 deletions ts/src/program/namespace/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class TransactionFactory {
const txFn: TransactionFn<IDL, I> = (...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));
Expand Down

0 comments on commit 4624572

Please sign in to comment.