fix: improve `MessageV0.getAccountKeys` API ergonomics (#28042)

fix: improve MessageV0.getAccountKeys API flexibility
This commit is contained in:
Justin Starry 2022-09-24 13:37:58 +08:00 committed by GitHub
parent e85900e094
commit 7810387b00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -42,10 +42,10 @@ export type CompileV0Args = {
export type GetAccountKeysArgs =
| {
accountKeysFromLookups: AccountKeysFromLookups;
accountKeysFromLookups?: AccountKeysFromLookups | null;
}
| {
addressLookupTableAccounts: AddressLookupTableAccount[];
addressLookupTableAccounts?: AddressLookupTableAccount[] | null;
};
export class MessageV0 {
@ -77,7 +77,11 @@ export class MessageV0 {
getAccountKeys(args?: GetAccountKeysArgs): MessageAccountKeys {
let accountKeysFromLookups: AccountKeysFromLookups | undefined;
if (args && 'accountKeysFromLookups' in args) {
if (
args &&
'accountKeysFromLookups' in args &&
args.accountKeysFromLookups
) {
if (
this.numAccountKeysFromLookups !=
args.accountKeysFromLookups.writable.length +
@ -88,7 +92,11 @@ export class MessageV0 {
);
}
accountKeysFromLookups = args.accountKeysFromLookups;
} else if (args && 'addressLookupTableAccounts' in args) {
} else if (
args &&
'addressLookupTableAccounts' in args &&
args.addressLookupTableAccounts
) {
accountKeysFromLookups = this.resolveAddressTableLookups(
args.addressLookupTableAccounts,
);