aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-04-04 14:57:24 -0700
committerAdam Soltys <[email protected]>2020-04-04 14:57:24 -0700
commit54714984ce540a6a2f9004325aed6524b117d0c6 (patch)
tree5ec53e5f10260126098ae101aaa9d1d3939e8773
parent11692b3a05742abc94e3f85a4afbbc29da35369f (diff)
downloadcoinos-server-54714984ce540a6a2f9004325aed6524b117d0c6.tar.gz
coinos-server-54714984ce540a6a2f9004325aed6524b117d0c6.zip
sign transaction in order to get accurate fee rate
-rw-r--r--routes/bitcoin/fee.js21
1 files changed, 8 insertions, 13 deletions
diff --git a/routes/bitcoin/fee.js b/routes/bitcoin/fee.js
index 99ef7fb8..7a0053c4 100644
--- a/routes/bitcoin/fee.js
+++ b/routes/bitcoin/fee.js
@@ -6,7 +6,7 @@ module.exports = async (req, res) => {
try {
amount = parseInt(amount);
- let unsigned = await bc.createRawTransaction([], {
+ let partial = await bc.createRawTransaction([], {
[address]: (amount / SATS).toFixed(8)
});
@@ -15,22 +15,17 @@ module.exports = async (req, res) => {
}
if (feeRate) params.feeRate = (feeRate / SATS).toFixed(8);
- l.info("requested rate", params.feeRate * SATS);
- let decoded = await bc.decodeRawTransaction(unsigned);
- let { weight, size, vsize } = decoded;
+ tx = await bc.fundRawTransaction(partial, params);
- tx = await bc.fundRawTransaction(unsigned, params);
- feeRate = parseInt(tx.fee * SATS * 1000 / decoded.size);
- l.info("unsigned", { weight, size, vsize, feeRate });
-
- decoded = await bc.decodeRawTransaction(tx.hex);
- feeRate = parseInt(tx.fee * SATS * 1000 / decoded.size);
- ({ weight, size, vsize } = decoded)
- l.info("signed", { weight, size, vsize, feeRate });
+ if (config.bitcoin.walletpass)
+ await bc.walletPassphrase(config.bitcoin.walletpass, 300);
+ let signed = (await bc.signRawTransactionWithWallet(tx.hex));
+ decoded = await bc.decodeRawTransaction(signed.hex);
+ feeRate = parseInt(tx.fee * SATS * 1000 / decoded.vsize);
- res.send({ feeRate, unsigned, tx });
+ res.send({ feeRate, tx });
} catch (e) {
l.error("bitcoin fee estimation error", e);
return res.status(500).send(e.message);