aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-07 07:54:23 -0700
committerAdam Soltys <[email protected]>2026-09-07 07:54:23 -0700
commit779284629dd30df04b5e594b9d729546e08bbe71 (patch)
treee41a1086f96a6edcc0c6b4524af2984c3627612e /src/features
parent037f025deba86713a470916964e9a388789f3b74 (diff)
downloadcoinosv3-779284629dd30df04b5e594b9d729546e08bbe71.tar.gz
coinosv3-779284629dd30df04b5e594b9d729546e08bbe71.zip
Fix "Cannot mix BigInt and other types" when creating an on-chain gift.
_buildGiftPsbt (the v2 ephemeral-key gift builder) subtracted the funding fee — _giftFundFee returns a Number — directly from BigInt coin sums (sum - _giftFundFee(...), sum - gift - _giftFundFee(...)), which throws in JS. Any on-chain (Savings) gift creation hit it: "Split a coin first", "Lock the whole coin", and gift-all. Wrap the fee in BigInt at those sites (new fundFee() helper). Adds tools/gift-build-test.js — the on-chain gift BUILDER had no coverage, which is how this shipped. It builds a specific-amount gift, a whole-balance gift, and the split carve-out shape (all three fee branches) against a mock wallet and asserts they produce claimable v2 codes without throwing. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01MGzU12QrAA4G6BYGzGVdXz
Diffstat (limited to 'src/features')
-rw-r--r--src/features/gifts-wallet.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/features/gifts-wallet.js b/src/features/gifts-wallet.js
index 920cddc..6776788 100644
--- a/src/features/gifts-wallet.js
+++ b/src/features/gifts-wallet.js
@@ -313,16 +313,17 @@ export function installGiftWallet(wallet) {
const rate = Math.max(1, Math.round(feeRate || (this.feeRates && this.feeRates.halfHourFee) || 5));
const sum = sel.reduce((s, u) => s + BigInt(u.value), 0n);
const whole = gift >= sum; // createGiftAll: gift the entire selection
+ const fundFee = (nOut) => BigInt(_giftFundFee(sel.length, nOut, rate));
let eAmount, change;
if (whole) {
- eAmount = sum - _giftFundFee(sel.length, 1, rate);
+ eAmount = sum - fundFee(1);
change = 0n;
} else {
- change = sum - gift - _giftFundFee(sel.length, 2, rate);
+ change = sum - gift - fundFee(2);
if (change >= DUST) { eAmount = gift; }
// change would be dust: drop it into the fee, single output, honour the
// requested amount (fee = sum - gift, which must clear a 1-output fee).
- else { eAmount = gift; change = 0n; if (sum - gift < _giftFundFee(sel.length, 1, rate)) throw new Error('Not enough to cover the funding fee — try a smaller gift.'); }
+ else { eAmount = gift; change = 0n; if (sum - gift < fundFee(1)) throw new Error('Not enough to cover the funding fee — try a smaller gift.'); }
}
if (eAmount < DUST) throw new Error('Gift amount is too small.');
// the throwaway key that holds the gift until the claimer sweeps it