diff --git a/src/utils/tokens/index.js b/src/utils/tokens/index.js index 11acd61..7c254d0 100644 --- a/src/utils/tokens/index.js +++ b/src/utils/tokens/index.js @@ -17,52 +17,25 @@ import { transferChecked, } from './instructions'; import { ACCOUNT_LAYOUT, getOwnedAccountsFilters, MINT_LAYOUT } from './data'; -import bs58 from 'bs58'; export async function getOwnedTokenAccounts(connection, publicKey) { let filters = getOwnedAccountsFilters(publicKey); - let resp = await connection._rpcRequest('getProgramAccounts', [ - TOKEN_PROGRAM_ID.toBase58(), + let resp = await connection.getProgramAccounts( + TOKEN_PROGRAM_ID, { - commitment: connection.commitment, filters, }, - ]); - if (resp.error) { - throw new Error( - 'failed to get token accounts owned by ' + - publicKey.toBase58() + - ': ' + - resp.error.message, - ); - } - return resp.result + ); + return resp .map(({ pubkey, account: { data, executable, owner, lamports } }) => ({ publicKey: new PublicKey(pubkey), accountInfo: { - data: bs58.decode(data), + data, executable, owner: new PublicKey(owner), lamports, }, })) - .filter(({ accountInfo }) => { - // TODO: remove this check once mainnet is updated - return filters.every((filter) => { - if (filter.dataSize) { - return accountInfo.data.length === filter.dataSize; - } else if (filter.memcmp) { - let filterBytes = bs58.decode(filter.memcmp.bytes); - return accountInfo.data - .slice( - filter.memcmp.offset, - filter.memcmp.offset + filterBytes.length, - ) - .equals(filterBytes); - } - return false; - }); - }); } export async function signAndSendTransaction(