diff --git a/src/server.tsx b/src/server.tsx index 91c8ff2..e6de4e2 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -81,6 +81,15 @@ function getValueFromFulfilledPromise(result: PromiseSettledResult) { return result && result.status === "fulfilled" && result.value ? result.value : null; } +/** + * Helper function to multiply two fixed point numbers. + */ +function multiplyFixedPoint(a: number, b: number, decimalPlaces: number): number { + const factor: number = Math.pow(10, decimalPlaces); + const product: number = Math.floor(a * factor) * Math.floor(b * factor); + return product / Math.pow(10, decimalPlaces); +} + // NOTE: fetch signal abortcontroller does not work on Bun. // See https://github.com/oven-sh/bun/issues/2489 async function fetchWithTimeout(url: string, timeout: number = TIMEOUT): Promise { @@ -228,18 +237,14 @@ async function fetchBitcoindFees() : Promise { targets.forEach((target, i) => { var feeRate = response[i].result?.feerate; if (feeRate) { - console.debug(`Raw bitcoind estimate for target ${target}: ${feeRate} BTC`); - // convert the returned value to satoshis, as it's currently returned in BTC. - const satPerKB = feeRate * 100000000; - - console.debug(`Converted bitcoind estimate for target ${target}: ${satPerKB} sat/vb`); + const satPerKB = multiplyFixedPoint(feeRate, 1e8, 8); result[target] = applyFeeMultiplier(satPerKB); } else { console.error(`Failed to fetch fee estimate from bitcoind for confirmation target ${target}`, response[i].result?.errors); } }); - + console.debug('Fetched bitcoind fees', result); resolve(result); } });