Bugfix for execute account construction

This commit is contained in:
Dummy Tester 123 2021-03-20 15:14:09 -05:00
parent eb701291d9
commit 502410e9dd
1 changed files with 13 additions and 7 deletions

View File

@ -78,18 +78,23 @@ function getAccountInfos(
The addresses that do not require signatures follow the addresses that do, The addresses that do not require signatures follow the addresses that do,
again with read-write accounts first and read-only accounts following. again with read-write accounts first and read-only accounts following.
*/ */
const accountInfosInOrder = actualMessage.instructions[0].accounts.map( const { programIdIndex, accounts } = actualMessage.instructions[0];
a => actualMessage.accountKeys[a], const accountInfosInOrder = accounts.map(a => actualMessage.accountKeys[a]);
); // If programIdIndex isnt in accountInfos, there's an off-by-one issue that happens here
// where one account that should be writable isnt, so we take care of here...
const totalSize =
accountInfosInOrder.length + (accounts.includes(programIdIndex) ? 0 : 1);
const requireSigsOnlyNotWritable = const requireSigsOnlyNotWritable =
actualMessage.header.numReadonlySignedAccounts; actualMessage.header.numReadonlySignedAccounts;
const requireNietherSigsNorWrite = const requireNietherSigsNorWrite =
actualMessage.header.numReadonlyUnsignedAccounts; actualMessage.header.numReadonlyUnsignedAccounts;
const writableOnly = const writableOnly =
accountInfosInOrder.length - totalSize - requireSigsOnlyNotWritable - requireNietherSigsNorWrite;
requireSigsOnlyNotWritable - // and adjust here...
requireNietherSigsNorWrite; const readOnly =
const readOnly = requireSigsOnlyNotWritable + requireNietherSigsNorWrite; requireSigsOnlyNotWritable +
requireNietherSigsNorWrite -
(totalSize - accountInfosInOrder.length);
let position = 0; let position = 0;
@ -125,5 +130,6 @@ function getAccountInfos(
isSigner: false, isSigner: false,
}); });
} }
return finalArray; return finalArray;
} }