UNPKG

@signumjs/core

Version:

Principal package with functions and models for building Signum Network applications.

67 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountTransactions = void 0; const constants_1 = require("../../../constants"); const transaction_1 = require("../transaction"); /** * Use with {@link ApiComposer} and belongs to {@link AccountApi}. * * See details at {@link AccountApi.getAccountTransactions} * * @category factories */ const getAccountTransactions = (service) => async (args) => { if (args.senderId || args.recipientId) { if (args.accountId) { throw new Error("Using accountId with recipientId and/or senderId is not allowed"); } if (args.resolveDistributions) { throw new Error("Using resolveDistributions with recipientId and/or senderId is not allowed"); } } const parameters = { ...args, account: args.accountId || undefined, sender: args.senderId, recipient: args.recipientId, bidirectional: args.bidirectional, }; if (args.resolveDistributions) { parameters.includeIndirect = true; } delete parameters.senderId; delete parameters.recipientId; delete parameters.accountId; delete parameters.resolveDistributions; const result = await service.query('getAccountTransactions', parameters); if (!args.resolveDistributions || !parameters.includeIndirect) { return result; } const distributions = result .transactions .filter(({ type, subtype, sender, }) => (type === constants_1.TransactionType.Asset && subtype === constants_1.TransactionAssetSubtype.AssetDistributeToHolders && args.accountId !== sender)) .map(tx => (0, transaction_1.getDistributionAmountsFromTransaction)(service)(tx.transaction, args.accountId)); try { const resolvedDistributions = await Promise.all(distributions); for (const dtx of resolvedDistributions) { const tx = result.transactions.find(({ transaction }) => transaction === dtx.transaction); const { asset, assetToDistribute } = tx.attachment; tx.distribution = { assetId: asset, distributedAssetId: assetToDistribute && assetToDistribute !== '0' ? assetToDistribute : null, ...dtx }; if (tx.sender !== args.accountId) { tx.amountNQT = dtx.amountNQT; } } } catch (_) { // ignore silently } return result; }; exports.getAccountTransactions = getAccountTransactions; //# sourceMappingURL=getAccountTransactions.js.map