diff options
| author | Adam Soltys <[email protected]> | 2020-03-10 15:11:47 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-03-10 15:11:47 -0700 |
| commit | d7b9a6e6d9b33ea974bfdb6b8bf38573906c7d01 (patch) | |
| tree | 04f46e3a1b3f787c57a64241522044474a3c16d6 | |
| parent | 629701a87138e2fedb69e260bc3951cb567b322c (diff) | |
| download | coinos-server-d7b9a6e6d9b33ea974bfdb6b8bf38573906c7d01.tar.gz coinos-server-d7b9a6e6d9b33ea974bfdb6b8bf38573906c7d01.zip | |
parse tx with javascript
| -rw-r--r-- | bitcoinPayments.js | 19 | ||||
| -rw-r--r-- | estimateBitcoinFee.js | 4 | ||||
| -rw-r--r-- | estimateLiquidFee.js | 4 | ||||
| -rw-r--r-- | sendCoins.js | 2 |
4 files changed, 15 insertions, 14 deletions
diff --git a/bitcoinPayments.js b/bitcoinPayments.js index 5b916265..0d410a6a 100644 --- a/bitcoinPayments.js +++ b/bitcoinPayments.js @@ -20,17 +20,24 @@ let NETWORK = bitcoin.networks[config.bitcoin.network === "mainnet" ? "bitcoin" module.exports = (app, bc, db, addresses, payments, emit) => { zmqRawTx.on("message", async (topic, message, sequence) => { const hex = message.toString("hex"); - const tx = await bc.decodeRawTransaction(hex); - let hash = tx.txid; + let tx = bitcoin.Transaction.fromHex(message); + let hash = reverse(tx.getHash()).toString("hex"); if (payments.includes(hash)) return; Promise.all( - tx.vout.map(async o => { - if (!(o.scriptPubKey && o.scriptPubKey.addresses)) return; + tx.outs.map(async o => { + const { value } = o; - const value = toSats(o.value); - const address = o.scriptPubKey.addresses[0]; + let address; + try { + address = bitcoin.address.fromOutputScript( + o.script, + NETWORK + ); + } catch (e) { + return; + } if (Object.keys(addresses).includes(address)) { payments.push(hash); diff --git a/estimateBitcoinFee.js b/estimateBitcoinFee.js index 215a180d..b32a0dc6 100644 --- a/estimateBitcoinFee.js +++ b/estimateBitcoinFee.js @@ -5,7 +5,7 @@ const SATS = 100000000; module.exports = (app, bc, db, emit) => async (req, res) => { let { user } = req; - let { address, amount, confTarget, feeRate, mode } = req.body; + let { address, amount, feeRate } = req.body; let tx, fee; try { @@ -20,8 +20,6 @@ module.exports = (app, bc, db, emit) => async (req, res) => { } if (feeRate) params["feeRate"] = (parseInt(feeRate) / SATS * 1000).toFixed(8); - if (confTarget) params["conf_target"] = parseInt(confTarget); - if (mode) params["estimate_mode"] = mode; tx = await bc.fundRawTransaction(tx, params); res.send({ tx }); diff --git a/estimateLiquidFee.js b/estimateLiquidFee.js index fc1655b6..fb9e54f0 100644 --- a/estimateLiquidFee.js +++ b/estimateLiquidFee.js @@ -8,7 +8,7 @@ const bc = new BitcoinCore(config.liquid); module.exports = (app, db, emit) => async (req, res) => { let { user } = req; - let { address, amount, confTarget, feeRate, mode } = req.body; + let { address, amount, feeRate } = req.body; let tx, fee; try { @@ -23,8 +23,6 @@ module.exports = (app, db, emit) => async (req, res) => { } if (feeRate) params["feeRate"] = (parseInt(feeRate) / SATS * 1000).toFixed(8); - if (confTarget) params["conf_target"] = parseInt(confTarget); - if (mode) params["estimate_mode"] = mode; tx = await bc.fundRawTransaction(tx, params); res.send({ tx }); diff --git a/sendCoins.js b/sendCoins.js index 6d871ca4..1c9f6937 100644 --- a/sendCoins.js +++ b/sendCoins.js @@ -33,10 +33,8 @@ module.exports = (addresses, app, bc, db, emit) => async (req, res) => { } } - l.info(total); total = (total - change) + fee; let amount = total - fee; - l.info(fee, total, amount, change); try { await db.transaction(async transaction => { |
