accounts.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // @ts-nocheck
  2. import * as B from "@native-to-anchor/buffer-layout";
  3. import { AccountsCoder, Idl } from "@coral-xyz/anchor";
  4. import { IdlTypeDef } from "@coral-xyz/anchor/dist/cjs/idl";
  5. export class SplStatelessAsksAccountsCoder<A extends string = string>
  6. implements AccountsCoder
  7. {
  8. constructor(_idl: Idl) {}
  9. public async encode<T = any>(accountName: A, account: T): Promise<Buffer> {
  10. switch (accountName) {
  11. default: {
  12. throw new Error(`Invalid account name: ${accountName}`);
  13. }
  14. }
  15. }
  16. public decode<T = any>(accountName: A, ix: Buffer): T {
  17. return this.decodeUnchecked(accountName, ix);
  18. }
  19. public decodeUnchecked<T = any>(accountName: A, ix: Buffer): T {
  20. switch (accountName) {
  21. default: {
  22. throw new Error(`Invalid account name: ${accountName}`);
  23. }
  24. }
  25. }
  26. public memcmp(
  27. accountName: A,
  28. _appendData?: Buffer
  29. ): { dataSize?: number; offset?: number; bytes?: string } {
  30. switch (accountName) {
  31. default: {
  32. throw new Error(`Invalid account name: ${accountName}`);
  33. }
  34. }
  35. }
  36. public size(idlAccount: IdlTypeDef): number {
  37. switch (idlAccount.name) {
  38. default: {
  39. throw new Error(`Invalid account name: ${idlAccount.name}`);
  40. }
  41. }
  42. }
  43. }