aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-19 12:42:58 -0800
committerAdam Soltys <[email protected]>2023-12-20 14:39:08 -0800
commit5b9cf9b2ea872849c3e53a61b72fd6b9107183e3 (patch)
tree5fbc889063e9bd341416825f2cf7b3e29df8b96b
parent48fd5545bfa4417e09923e2437316466608a4c24 (diff)
downloadcoinos-server-5b9cf9b2ea872849c3e53a61b72fd6b9107183e3.tar.gz
coinos-server-5b9cf9b2ea872849c3e53a61b72fd6b9107183e3.zip
update fee method
-rw-r--r--routes/payments.js26
1 files changed, 9 insertions, 17 deletions
diff --git a/routes/payments.js b/routes/payments.js
index 36972928..bbbcf9d2 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -250,11 +250,8 @@ export default {
}
},
- async fee({ body: { amount, address, feeRate, subtract }, user }, res) {
+ async fee({ body: { amount, address, feeRate, subtract }, user }, res) {
try {
- let subtractFeeFromOutputs = subtract ? [0] : [];
- let replaceable = true;
-
let ourfee = Math.round(amount * config.fee);
let credit = await g(`credit:bitcoin:${user.id}`);
let covered = Math.min(credit, ourfee) || 0;
@@ -262,28 +259,23 @@ export default {
if (subtract) amount -= ourfee;
- let { feerate: min } = await bc.estimateSmartFee(40);
- let { feerate: max } = await bc.estimateSmartFee(1);
-
- if (feeRate) feeRate = btc(feeRate);
- else feeRate = max;
-
let outs = [{ [address]: btc(amount) }];
let raw = await bc.createRawTransaction([], outs, 0, replaceable);
let tx = await bc.fundRawTransaction(raw, {
- feeRate,
- subtractFeeFromOutputs,
- replaceable,
+ replaceable: true,
});
let fee = sats(tx.fee);
- min = sats(min);
- max = Math.round(sats(max) * 1.2);
- feeRate = sats(feeRate);
+ if (amount + fee + ourfee > await g(`balance:${user.id}`)) {
+ tx = await bc.fundRawTransaction(raw, {
+ replaceable: true,
+ subtractFeeFromOutputs: [0]
+ });
+ }
- res.send({ feeRate, min, max, fee, tx });
+ res.send({ feeRate, ourfee, fee, tx });
} catch (e) {
warn("problem estimating fee", e.message, user.username, amount, address);
bail(res, "problem estimating fee");