mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-17 05:58:11 -07:00
website_next: part 12
This commit is contained in:
@@ -1,23 +1,27 @@
|
||||
import { createFeeRateRange } from "../../fee-rates.js";
|
||||
import { FEE_RATE_PERCENTILES } from "../../fee-rates.js";
|
||||
|
||||
/**
|
||||
* @param {BlockPreviewTransaction[]} transactions
|
||||
* @param {number[]} feeRates
|
||||
* @param {Uint32Array} order
|
||||
*/
|
||||
export function createPreviewFeeRange(transactions) {
|
||||
const feeRates = new Array(transactions.length);
|
||||
export function createPreviewFeeRange(feeRates, order) {
|
||||
return FEE_RATE_PERCENTILES.map((percentile) => {
|
||||
const index = Math.round(((100 - percentile) / 100) * (order.length - 1));
|
||||
|
||||
for (let index = 0; index < transactions.length; index += 1) {
|
||||
feeRates[index] = transactions[index].feeRate;
|
||||
return feeRates[order[index]];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number[]} weights
|
||||
* @param {number[]} feeRates
|
||||
*/
|
||||
export function orderTransactions(weights, feeRates) {
|
||||
const order = new Uint32Array(feeRates.length);
|
||||
|
||||
for (let index = 0; index < order.length; index += 1) {
|
||||
order[index] = index;
|
||||
}
|
||||
|
||||
return createFeeRateRange(feeRates);
|
||||
return order.sort((a, b) => feeRates[b] - feeRates[a] || weights[b] - weights[a]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {BlockPreviewTransaction[]} transactions
|
||||
*/
|
||||
export function orderTransactions(transactions) {
|
||||
return transactions.sort((a, b) => b.feeRate - a.feeRate || b.weight - a.weight);
|
||||
}
|
||||
|
||||
/** @typedef {import("../data.js").BlockPreviewTransaction} BlockPreviewTransaction */
|
||||
|
||||
Reference in New Issue
Block a user