@solana/spl-token#TokenAccountNotFoundError TypeScript Examples

The following examples show how to use @solana/spl-token#TokenAccountNotFoundError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: accountParser.ts    From jet-engine with GNU Affero General Public License v3.0 6 votes vote down vote up
parseTokenAccount = (info: AccountInfo<Buffer>, address: PublicKey): Account => {
  if (!info) throw new TokenAccountNotFoundError()
  if (!info.owner.equals(TOKEN_PROGRAM_ID)) throw new TokenInvalidAccountOwnerError()
  if (info.data.length != ACCOUNT_SIZE) throw new TokenInvalidAccountSizeError()

  const rawAccount = AccountLayout.decode(info.data)

  return {
    address,
    mint: rawAccount.mint,
    owner: rawAccount.owner,
    amount: rawAccount.amount,
    delegate: rawAccount.delegateOption ? rawAccount.delegate : null,
    delegatedAmount: rawAccount.delegatedAmount,
    isInitialized: rawAccount.state !== AccountState.Uninitialized,
    isFrozen: rawAccount.state === AccountState.Frozen,
    isNative: !!rawAccount.isNativeOption,
    rentExemptReserve: rawAccount.isNativeOption ? rawAccount.isNative : null,
    closeAuthority: rawAccount.closeAuthorityOption ? rawAccount.closeAuthority : null
  }
}
Example #2
Source File: accountParser.ts    From jet-engine with GNU Affero General Public License v3.0 6 votes vote down vote up
parseMintAccount = (info: AccountInfo<Buffer>, address: PublicKey): Mint => {
  if (!info) throw new TokenAccountNotFoundError()
  if (!info.owner.equals(TOKEN_PROGRAM_ID)) throw new TokenInvalidAccountOwnerError()
  if (info.data.length != MINT_SIZE) throw new TokenInvalidAccountSizeError()

  const rawMint = MintLayout.decode(info.data)

  return {
    address,
    mintAuthority: rawMint.mintAuthorityOption ? rawMint.mintAuthority : null,
    supply: rawMint.supply,
    decimals: rawMint.decimals,
    isInitialized: rawMint.isInitialized,
    freezeAuthority: rawMint.freezeAuthorityOption ? rawMint.freezeAuthority : null
  }
}