Skip to content

Commit

Permalink
fix: improve MessageV0.getAccountKeys API ergonomics (#28042)
Browse files Browse the repository at this point in the history
fix: improve MessageV0.getAccountKeys API flexibility
  • Loading branch information
jstarry authored Sep 24, 2022
1 parent e85900e commit 7810387
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions web3.js/src/message/v0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export type CompileV0Args = {

export type GetAccountKeysArgs =
| {
accountKeysFromLookups: AccountKeysFromLookups;
accountKeysFromLookups?: AccountKeysFromLookups | null;
}
| {
addressLookupTableAccounts: AddressLookupTableAccount[];
addressLookupTableAccounts?: AddressLookupTableAccount[] | null;
};

export class MessageV0 {
Expand Down Expand Up @@ -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 +
Expand All @@ -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,
);
Expand Down

0 comments on commit 7810387

Please sign in to comment.