UNPKG

@node-dlc/bitcoin

Version:
41 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bip69OutputSorter = exports.bip69InputSorter = void 0; const HashByteOrder_1 = require("./HashByteOrder"); /** * Compares two transaction inputs and lexicographically sorted in * ascending order using the reversed byte order (RPC) of the txids. * If the same txids are in both TxIn, then the output index is sorted * in ascending order. * @param a * @param b */ function bip69InputSorter(a, b) { const txid = a.outpoint.txid .serialize(HashByteOrder_1.HashByteOrder.RPC) .compare(b.outpoint.txid.serialize()); if (txid !== 0) return txid; if (a.outpoint.outputIndex < b.outpoint.outputIndex) return -1; if (a.outpoint.outputIndex > b.outpoint.outputIndex) return 1; return 0; } exports.bip69InputSorter = bip69InputSorter; /** * Sort transaction amounts in ascending order. Then ScriptPubKey values * will be sorted in ascending byte order next. * @param a * @param b */ function bip69OutputSorter(a, b) { // sort by amount desc first const amount = Number(a.value.sats - b.value.sats); if (amount !== 0) return amount; // then sort by script pub key return a.scriptPubKey.serializeCmds().compare(b.scriptPubKey.serializeCmds()); } exports.bip69OutputSorter = bip69OutputSorter; //# sourceMappingURL=LexicographicalSorters.js.map