{"version":3,"file":"Account.mjs","sources":["../../src/Account.ts"],"sourcesContent":["import type { PublicKey } from '@metaplex-foundation/umi-public-keys';\nimport type { Serializer } from '@metaplex-foundation/umi-serializers';\nimport type { SolAmount } from './Amount';\nimport { AccountNotFoundError, UnexpectedAccountError } from './errors';\n\n/**\n * The size of an account header in bytes.\n * @category Accounts\n */\nexport const ACCOUNT_HEADER_SIZE = 128;\n\n/**\n * Describes the header of an account.\n * @category Accounts\n */\nexport type AccountHeader = {\n  executable: boolean;\n  owner: PublicKey;\n  lamports: SolAmount;\n  rentEpoch?: bigint;\n};\n\n/**\n * Describes a raw account that has not been deserialized.\n * @category Accounts\n */\nexport type RpcAccount = AccountHeader & {\n  publicKey: PublicKey;\n  data: Uint8Array;\n};\n\n/**\n * Describes a raw account that may or may not exist.\n * @category Accounts\n */\nexport type MaybeRpcAccount =\n  | ({ exists: true } & RpcAccount)\n  | { exists: false; publicKey: PublicKey };\n\n/**\n * Describes a deserialized account.\n * @category Accounts\n */\nexport type Account<T extends object> = T & {\n  publicKey: PublicKey;\n  header: AccountHeader;\n};\n\n/**\n * Given an account data serializer,\n * returns a deserialized account from a raw account.\n * @category Accounts\n */\nexport function deserializeAccount<From extends object, To extends From = From>(\n  rawAccount: RpcAccount,\n  dataSerializer: Serializer<From, To>\n): Account<To> {\n  const { data, publicKey, ...rest } = rawAccount;\n  try {\n    const [parsedData] = dataSerializer.deserialize(data);\n    return { publicKey, header: rest, ...parsedData };\n  } catch (error: any) {\n    throw new UnexpectedAccountError(\n      publicKey,\n      dataSerializer.description,\n      error\n    );\n  }\n}\n\n/**\n * Ensures an account that may or may not exist actually exists.\n * @category Accounts\n */\nexport function assertAccountExists(\n  account: MaybeRpcAccount,\n  name?: string,\n  solution?: string\n): asserts account is MaybeRpcAccount & { exists: true } {\n  if (!account.exists) {\n    throw new AccountNotFoundError(account.publicKey, name, solution);\n  }\n}\n"],"names":["ACCOUNT_HEADER_SIZE","deserializeAccount","rawAccount","dataSerializer","data","publicKey","rest","parsedData","deserialize","header","error","UnexpectedAccountError","description","assertAccountExists","account","name","solution","exists","AccountNotFoundError"],"mappings":";;;AAKA;AACA;AACA;AACA;AACO,MAAMA,mBAAmB,GAAG,IAAG;;AAEtC;AACA;AACA;AACA;;AAkCA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkB,CAChCC,UAAsB,EACtBC,cAAoC,EACvB;EACb,MAAM;IAAEC,IAAI;IAAEC,SAAS;IAAE,GAAGC,IAAAA;AAAK,GAAC,GAAGJ,UAAU,CAAA;EAC/C,IAAI;IACF,MAAM,CAACK,UAAU,CAAC,GAAGJ,cAAc,CAACK,WAAW,CAACJ,IAAI,CAAC,CAAA;IACrD,OAAO;MAAEC,SAAS;AAAEI,MAAAA,MAAM,EAAEH,IAAI;MAAE,GAAGC,UAAAA;KAAY,CAAA;GAClD,CAAC,OAAOG,KAAU,EAAE;IACnB,MAAM,IAAIC,sBAAsB,CAC9BN,SAAS,EACTF,cAAc,CAACS,WAAW,EAC1BF,KAAK,CACN,CAAA;AACH,GAAA;AACF,CAAA;;AAEA;AACA;AACA;AACA;AACO,SAASG,mBAAmB,CACjCC,OAAwB,EACxBC,IAAa,EACbC,QAAiB,EACsC;AACvD,EAAA,IAAI,CAACF,OAAO,CAACG,MAAM,EAAE;IACnB,MAAM,IAAIC,oBAAoB,CAACJ,OAAO,CAACT,SAAS,EAAEU,IAAI,EAAEC,QAAQ,CAAC,CAAA;AACnE,GAAA;AACF;;;;"}