@bigmi/core
Version:
TypeScript library for Bitcoin apps.
57 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTransactions = void 0;
const url_js_1 = require("../../utils/url.js");
const mempoolTransactionTransformer = (txn) => ({
hash: txn.txid,
txid: txn.txid,
vout: txn.vout.map((vout, index) => ({
n: index,
scriptPubKey: {
address: vout.scriptpubkey_address,
asm: vout.scriptpubkey_asm,
type: vout.scriptpubkey_type,
desc: vout.scriptpubkey,
hex: vout.scriptpubkey,
},
value: vout.value,
})),
vin: txn.vin.map((vin) => ({
scriptSig: {
asm: vin.scriptsig_asm,
hex: vin.scriptsig,
},
sequence: vin.sequence,
txinwitness: vin.witness,
txid: vin.txid,
vout: vin.vout,
})),
});
const getTransactions = async (client, { baseUrl }, { address, limit = 50, offset = 0, afterTxId }) => {
const apiUrlAddress = `${baseUrl}/address/${address}`;
const balanceResponse = (await client.request({
url: apiUrlAddress,
fetchOptions: { method: 'GET' },
}));
const totalTxns = balanceResponse.chain_stats.tx_count +
balanceResponse.mempool_stats.tx_count;
const apiUrl = (0, url_js_1.urlWithParams)(`${baseUrl}/address/${address}/txs`, {
after_txid: afterTxId,
});
const response = (await client.request({
url: apiUrl,
fetchOptions: { method: 'GET' },
}));
const transactions = response.map(mempoolTransactionTransformer);
const result = {
transactions,
total: totalTxns,
itemsPerPage: limit,
hasMore: offset + transactions.length < totalTxns,
};
return {
result,
};
};
exports.getTransactions = getTransactions;
//# sourceMappingURL=getTransactions.js.map