index.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * This code was GENERATED using the solita package.
  3. * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
  4. *
  5. * See: https://github.com/metaplex-foundation/solita
  6. */
  7. type ErrorWithCode = Error & { code: number };
  8. type MaybeErrorWithCode = ErrorWithCode | null | undefined;
  9. const createErrorFromCodeLookup = new Map<number, () => ErrorWithCode>();
  10. const createErrorFromNameLookup = new Map<string, () => ErrorWithCode>();
  11. /**
  12. * InvalidAuthority: 'Invalid authority for instruction'
  13. *
  14. * @category Errors
  15. * @category generated
  16. */
  17. export class InvalidAuthorityError extends Error {
  18. readonly code: number = 0x1770;
  19. readonly name: string = "InvalidAuthority";
  20. constructor() {
  21. super("Invalid authority for instruction");
  22. if (typeof Error.captureStackTrace === "function") {
  23. Error.captureStackTrace(this, InvalidAuthorityError);
  24. }
  25. }
  26. }
  27. createErrorFromCodeLookup.set(0x1770, () => new InvalidAuthorityError());
  28. createErrorFromNameLookup.set(
  29. "InvalidAuthority",
  30. () => new InvalidAuthorityError()
  31. );
  32. /**
  33. * Attempts to resolve a custom program error from the provided error code.
  34. * @category Errors
  35. * @category generated
  36. */
  37. export function errorFromCode(code: number): MaybeErrorWithCode {
  38. const createError = createErrorFromCodeLookup.get(code);
  39. return createError != null ? createError() : null;
  40. }
  41. /**
  42. * Attempts to resolve a custom program error from the provided error name, i.e. 'Unauthorized'.
  43. * @category Errors
  44. * @category generated
  45. */
  46. export function errorFromName(name: string): MaybeErrorWithCode {
  47. const createError = createErrorFromNameLookup.get(name);
  48. return createError != null ? createError() : null;
  49. }