Skip to content

Commit

Permalink
sdk: catch decoding error in polling drift client account subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Aug 25, 2023
1 parent 908732e commit 36e0f0f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions sdk/src/accounts/pollingDriftClientAccountSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NotSubscribedError,
OraclesToPoll,
} from './types';
import { Program } from '@coral-xyz/anchor';
import { BorshAccountsCoder, Program } from '@coral-xyz/anchor';
import StrictEventEmitter from 'strict-event-emitter-types';
import { EventEmitter } from 'events';
import {
Expand Down Expand Up @@ -225,9 +225,27 @@ export class PollingDriftClientAccountSubscriber
(buffer: Buffer, slot: number) => {
if (!buffer) return;

const account = this.program.account[
accountToPoll.key
].coder.accounts.decode(capitalize(accountToPoll.key), buffer);
let account;
try {
account = this.program.account[
accountToPoll.key
].coder.accounts.decode(capitalize(accountToPoll.key), buffer);
} catch (e) {
console.error(e);
console.log('account key', accountToPoll.key);
console.log(
'accountToPoll.publicKey',
accountToPoll.publicKey.toString()
);
console.log('buffer', buffer.toString('base64'));
console.log(
'discriminator',
BorshAccountsCoder.accountDiscriminator(
capitalize(accountToPoll.key)
).toString('base64')
);
return;
}
const dataAndSlot = {
data: account,
slot,
Expand Down

0 comments on commit 36e0f0f

Please sign in to comment.