Executing
// retrieve the transaction we wish to execute
const transactionAccount = await squadsProgram.account.msTransaction.fetch(transaction);
// retrieve all of the attached instructions
const instructions = await Promise.all([...new Array(transactionAccount.instructionIndex)].map(async (a, i) => {
const ixIndex = new anchor.BN(i + 1);
const [ix] = await getIxPDA(transaction, ixIndex, squadsProgram.programId);
const ixAccount = await squadsProgram.account.msInstruction.fetch(ix);
return {pubkey: ix, ixAccountData};
}));
// map all of the instructions and their keys into the following pattern
// [ix, program, ...remaining_accounts]
const ixKeys = instructions.map(({pubkey, ixAccountData}) => {
const formattedKeys = ixAccount.keys.map((ixKey) => {
return {
pubkey: ixKey.pubkey,
isSigner: false,
isWritable: ixKey.isWritable
};
});
return [
{pubkey, isSigner: false, isWritable: false},
{pubkey: ixAccountData.programId, isSigner: false, isWritable: false},
...formattedKeys
];
//squash them into a single list
}).reduce((p, c) => p.concat(c), [])Last updated