aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-03 19:40:41 -0800
committerAdam Soltys <[email protected]>2026-03-03 19:40:41 -0800
commit82f7ae5f84da70e8c5692ff4fffa7263784a7800 (patch)
tree0564c78d340a0bb06d256110058cb517692e2efb
parente70d96afa6b9ddcf33407e0ed89962c5956d8612 (diff)
downloadcoinos-server-82f7ae5f84da70e8c5692ff4fffa7263784a7800.tar.gz
coinos-server-82f7ae5f84da70e8c5692ff4fffa7263784a7800.zip
fee bump reserve
-rw-r--r--lib/payments.ts18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 057a98ca..47c82d9d 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -675,7 +675,7 @@ const sendNonCustodial = async (params) => {
};
export const sendOnchain = async (params) => {
- let { aid, hex, rate, user, signed } = params;
+ let { aid, hex, rate, user, signed, feeRate } = params;
if (!aid) aid = user.id;
// Non-custodial bitcoin account — use esplora
@@ -763,8 +763,18 @@ export const sendOnchain = async (params) => {
}
const amount = total - change;
- const bumpReserve = buildResult?.bumpReserve || 0;
- const parentVsize = buildResult?.parentVsize || 0;
+ let bumpReserve = buildResult?.bumpReserve || 0;
+ let parentVsize = buildResult?.parentVsize || 0;
+
+ // When hex is pre-built (custodial form submit), recalculate bump reserve
+ if (isBitcoin && p2aVout >= 0 && !buildResult) {
+ const decoded = await node.decodeRawTransaction(hex);
+ parentVsize = decoded.vsize;
+ const fees: any = await fetch(`${api[type]}/fees/recommended`).then((r) => r.json());
+ const fastestFee = Math.ceil(fees.fastestFee * 1.5);
+ const userRate = parseFloat(feeRate) || fees.halfHourFee;
+ bumpReserve = calculateBumpReserve(userRate, fastestFee, parentVsize);
+ }
const p = await debit({
aid,
@@ -1069,7 +1079,7 @@ export const build = async ({ aid, amount, address, feeRate, subtract, user }) =
if (!aid) aid = user.id;
// Non-custodial bitcoin account — use esplora
- if (aid !== user.id && type === PaymentType.bitcoin) {
+ if (type === PaymentType.bitcoin) {
const account = await g(`account:${aid}`);
if (account?.pubkey) {
return buildNonCustodial({ aid, amount, address, feeRate, subtract, user });