diff --git a/app/handler/batchTransferNftHandler.js b/app/handler/batchTransferNftHandler.js index 07d7221..89a9ed6 100644 --- a/app/handler/batchTransferNftHandler.js +++ b/app/handler/batchTransferNftHandler.js @@ -18,7 +18,9 @@ async function BatchTransferNftHandler(req, res) { } const { hashgraphClient } = req.context - const sendResponse = await hashgraphClient.batchTransferNft(batchTransferPayload) + const sendResponse = await hashgraphClient.batchTransferNft( + batchTransferPayload + ) if (sendResponse.error) { return Response.unprocessibleEntity(res, sendResponse.error) diff --git a/app/hashgraph/client.js b/app/hashgraph/client.js index 1b52287..3c92ad9 100644 --- a/app/hashgraph/client.js +++ b/app/hashgraph/client.js @@ -694,12 +694,7 @@ class HashgraphClient extends HashgraphClientContract { * @param ser * @returns {Promise} */ - multipleNftTransfer = async ({ - token_id, - receiver_id, - serials - }) => { - + multipleNftTransfer = async ({ token_id, receiver_id, serials }) => { const client = this.#client const transfer = await new TransferTransaction() @@ -755,7 +750,11 @@ class HashgraphClient extends HashgraphClientContract { // Required recur fn needed for pagination const sendNftTransaction = async (limit, paginationLink) => { - const nfts = await Mirror.fetchNftIdsForBatchTransfer(token_id, limit, paginationLink) + const nfts = await Mirror.fetchNftIdsForBatchTransfer( + token_id, + limit, + paginationLink + ) const transfer = await this.multipleNftTransfer({ token_id, @@ -770,7 +769,6 @@ class HashgraphClient extends HashgraphClientContract { } const cycleBatchTransfers = async (cycle, results = [], paginationLink) => { - if (!cycle.length) { return results } diff --git a/app/utils/batchable.js b/app/utils/batchable.js index eee2b2d..a3c4360 100644 --- a/app/utils/batchable.js +++ b/app/utils/batchable.js @@ -1,4 +1,3 @@ - const BATCH_LIMITS = { nftTransfers: 10 } @@ -10,15 +9,17 @@ const BATCH_LIMITS = { * @returns {any[]} */ function nftTransfer(amount) { - // mod rem diff const rem = amount % BATCH_LIMITS.nftTransfers // Basal cycle for batch, as a whole number const max = (amount - rem) / BATCH_LIMITS.nftTransfers - // When rem is falsely, remove -- more simple then if - const cycle = Array(max).fill(BATCH_LIMITS.nftTransfers).concat(rem).filter(e => e) + // When rem is falsely, remove -- more simple then if + const cycle = Array(max) + .fill(BATCH_LIMITS.nftTransfers) + .concat(rem) + .filter(e => e) // For readability return cycle diff --git a/app/utils/mirrornode.js b/app/utils/mirrornode.js index 37b1af4..b840516 100644 --- a/app/utils/mirrornode.js +++ b/app/utils/mirrornode.js @@ -10,9 +10,11 @@ const queryNftAccountOwner = (token_id, serial) => `${mirrornode}/api/v1/tokens/${token_id}/nfts/${serial}` const queryNftForOwner = (token_id, account_id) => `${mirrornode}/api/v1/tokens/${token_id}/nfts/?account.id=${account_id}` -const queryTreasuryTokenBalance = (token_id, account_id) => `${mirrornode}/api/v1/tokens/${token_id}/balances/?account.id=${account_id}` -const getNftByLimit = (token_id, account_id, limit = 20) => `${mirrornode}/api/v1/tokens/${token_id}/nfts?account.id=${account_id}&order=asc&limit=${limit}` -const queryReq = (next) => `${mirrornode}${next}` +const queryTreasuryTokenBalance = (token_id, account_id) => + `${mirrornode}/api/v1/tokens/${token_id}/balances/?account.id=${account_id}` +const getNftByLimit = (token_id, account_id, limit = 20) => + `${mirrornode}/api/v1/tokens/${token_id}/nfts?account.id=${account_id}&order=asc&limit=${limit}` +const queryReq = next => `${mirrornode}${next}` const MIRRORNODE_WAIT_MS = 500 const MIRRORNODE_TRIES = 5 @@ -99,9 +101,7 @@ async function checkTreasuryHasNftAmount( queryTreasuryTokenBalance(nft_id, expected) ) - const { - balances - } = result.data + const { balances } = result.data if (!balances.length) { return false @@ -110,7 +110,6 @@ async function checkTreasuryHasNftAmount( return balances[0].balance >= amount } - /** * Fetch the nft ids for a particular NFT tx, include the "next" id * @@ -130,10 +129,7 @@ async function fetchNftIdsForBatchTransfer( link ? queryReq(link) : getNftByLimit(nft_id, expected, limit) ) - const { - nfts, - links - } = result.data + const { nfts, links } = result.data const serials = nfts.splice(0, limit)