Skip to content

Commit

Permalink
sdk: use decodeUnchecked in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Aug 26, 2023
1 parent b37c074 commit f11a3b0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions sdk/src/accounts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function fetchUserAccountsUsingKeys(
if (!accountInfo) {
return undefined;
}
return program.account.user.coder.accounts.decode(
return program.account.user.coder.accounts.decodeUnchecked(
'User',
accountInfo.data
) as UserAccount;
Expand All @@ -58,7 +58,7 @@ export async function fetchUserStatsAccount(
);

return accountInfo
? (program.account.user.coder.accounts.decode(
? (program.account.user.coder.accounts.decodeUnchecked(
'UserStats',
accountInfo.data
) as UserStatsAccount)
Expand Down
11 changes: 6 additions & 5 deletions sdk/src/accounts/pollingUserAccountSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
return;
}

const account = this.program.account.user.coder.accounts.decode(
'User',
buffer
);
const account =
this.program.account.user.coder.accounts.decodeUnchecked(
'User',
buffer
);
this.user = { data: account, slot };
this.eventEmitter.emit('userAccountUpdate', account);
this.eventEmitter.emit('update');
Expand All @@ -99,7 +100,7 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
);
const currentSlot = this.user?.slot ?? 0;
if (buffer && slot > currentSlot) {
const account = this.program.account.user.coder.accounts.decode(
const account = this.program.account.user.coder.accounts.decodeUnchecked(
'User',
buffer
);
Expand Down
18 changes: 10 additions & 8 deletions sdk/src/accounts/pollingUserStatsAccountSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ export class PollingUserStatsAccountSubscriber
return;
}

const account = this.program.account.userStats.coder.accounts.decode(
'UserStats',
buffer
);
const account =
this.program.account.userStats.coder.accounts.decodeUnchecked(
'UserStats',
buffer
);
this.userStats = { data: account, slot };
this.eventEmitter.emit('userStatsAccountUpdate', account);
this.eventEmitter.emit('update');
Expand All @@ -102,10 +103,11 @@ export class PollingUserStatsAccountSubscriber
);
const currentSlot = this.userStats?.slot ?? 0;
if (buffer && slot > currentSlot) {
const account = this.program.account.userStats.coder.accounts.decode(
'UserStats',
buffer
);
const account =
this.program.account.userStats.coder.accounts.decodeUnchecked(
'UserStats',
buffer
);
this.userStats = { data: account, slot };
}
}
Expand Down
7 changes: 3 additions & 4 deletions sdk/src/accounts/webSocketAccountSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
if (this.decodeBufferFn) {
return this.decodeBufferFn(buffer);
} else {
return this.program.account[this.accountName].coder.accounts.decode(
capitalize(this.accountName),
buffer
);
return this.program.account[
this.accountName
].coder.accounts.decodeUnchecked(capitalize(this.accountName), buffer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/orderSubscriber/OrderSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class OrderSubscriber {
const slotAndUserAccount = this.usersAccounts.get(key);
if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
const userAccount =
this.driftClient.program.account.user.coder.accounts.decode(
this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
'User',
buffer
) as UserAccount;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/userMap/userMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class UserMap implements UserMapInterface {
for (const [key, buffer] of programAccountBufferMap.entries()) {
if (!this.has(key)) {
const userAccount =
this.driftClient.program.account.user.coder.accounts.decode(
this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
'User',
buffer
);
Expand All @@ -249,7 +249,7 @@ export class UserMap implements UserMapInterface {
this.userMap.delete(key);
} else {
const userAccount =
this.driftClient.program.account.user.coder.accounts.decode(
this.driftClient.program.account.user.coder.accounts.decodeUnchecked(
'User',
programAccountBufferMap.get(key)
);
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/userMap/userStatsMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class UserStatsMap {
for (const key of programAccountMap.keys()) {
if (!this.has(key)) {
const userStatsAccount =
this.driftClient.program.account.userStats.coder.accounts.decode(
this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked(
'UserStats',
programAccountMap.get(key).data
);
Expand Down

0 comments on commit f11a3b0

Please sign in to comment.