Skip to content

Commit

Permalink
ts: fix fetching all accounts when using a custom coder (coral-xyz#2107)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored and yf-castel committed Aug 15, 2022
1 parent 857de83 commit 9cd76c8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ts/src/program/namespace/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,28 @@ export class AccountClient<
async all(
filters?: Buffer | GetProgramAccountsFilter[]
): Promise<ProgramAccount<T>[]> {
const filter: { offset?: number; bytes?: string; dataSize?: number } =
this.coder.accounts.memcmp(
this._idlAccount.name,
filters instanceof Buffer ? filters : undefined
);
const coderFilters: GetProgramAccountsFilter[] = [];
if (filter?.offset != undefined && filter?.bytes != undefined) {
coderFilters.push({
memcmp: { offset: filter.offset, bytes: filter.bytes },
});
}
if (filter?.dataSize != undefined) {
coderFilters.push({ dataSize: filter.dataSize });
}
let resp = await this._provider.connection.getProgramAccounts(
this._programId,
{
commitment: this._provider.connection.commitment,
filters: [
{
memcmp: this.coder.accounts.memcmp(
this._idlAccount.name,
filters instanceof Buffer ? filters : undefined
),
},
...(Array.isArray(filters) ? filters : []),
],
filters: [...coderFilters, ...(Array.isArray(filters) ? filters : [])],
}
);

return resp.map(({ pubkey, account }) => {
return {
publicKey: pubkey,
Expand Down

0 comments on commit 9cd76c8

Please sign in to comment.