ts: fix fetching all accounts when using a custom coder (#2107)

This commit is contained in:
acheron 2022-08-12 20:06:14 +02:00 committed by GitHub
parent 000e74ed48
commit 9457180a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 9 deletions

View File

@ -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,