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 /bitcoinPayments.js | |
| parent | 629701a87138e2fedb69e260bc3951cb567b322c (diff) | |
| download | coinos-server-d7b9a6e6d9b33ea974bfdb6b8bf38573906c7d01.tar.gz coinos-server-d7b9a6e6d9b33ea974bfdb6b8bf38573906c7d01.zip | |
parse tx with javascript
Diffstat (limited to 'bitcoinPayments.js')
| -rw-r--r-- | bitcoinPayments.js | 19 |
1 files changed, 13 insertions, 6 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); |
