diff options
| author | Adam Soltys <[email protected]> | 2020-03-09 10:59:04 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-03-09 10:59:10 -0700 |
| commit | 1ae4c03116ce3a650af88f78a4b5d19581238c71 (patch) | |
| tree | 10fce06803f0a13c5ba990f08d687c4deced6186 /liquidPayments.js | |
| parent | ddb61fe99e4103c1ba8a5d29e3aa66a580c63bf6 (diff) | |
| download | coinos-server-1ae4c03116ce3a650af88f78a4b5d19581238c71.tar.gz coinos-server-1ae4c03116ce3a650af88f78a4b5d19581238c71.zip | |
fee estimation
Diffstat (limited to 'liquidPayments.js')
| -rw-r--r-- | liquidPayments.js | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/liquidPayments.js b/liquidPayments.js index 8ed5507a..3c2a12f4 100644 --- a/liquidPayments.js +++ b/liquidPayments.js @@ -17,7 +17,7 @@ zmqRawTx.subscribe("rawtx"); let NETWORK = bitcoin.networks[config.bitcoin.network === "mainnet" ? "bitcoin" : config.bitcoin.network]; const bc = new BitcoinCore(config.liquid); -const SATS = 100000000; +const toSats = n => parseInt((n * 100000000).toFixed()) module.exports = (app, db, addresses, payments, emit) => { zmqRawTx.on("message", async (topic, message, sequence) => { @@ -30,8 +30,7 @@ module.exports = (app, db, addresses, payments, emit) => { Promise.all( tx.vout.map(async o => { if (!(o.scriptPubKey && o.scriptPubKey.addresses)) return; - let { value } = o; - value *= SATS + const value = toSats(o.value); const address = o.scriptPubKey.addresses[0]; if (Object.keys(addresses).includes(address)) { @@ -58,20 +57,15 @@ module.exports = (app, db, addresses, payments, emit) => { let confirmed = 0; - if (user.friend) { - user.balance += value; - confirmed = 1; - } else { - user.pending += value; - } - + user.pending += value; user.confidential = await bc.getNewAddress(); user.liquid = (await bc.getAddressInfo(user.confidential)).unconfidential; - addresses[user.liquid] = user.username; await user.save(); emit(user.username, "user", user); + addresses[user.liquid] = user.username; + const payment = await db.Payment.create({ user_id: user.id, hash: blinded.txid, @@ -126,7 +120,7 @@ module.exports = (app, db, addresses, payments, emit) => { let user = await p.getUser(); user.balance += p.amount; - user.pending -= p.amount; + user.pending -= Math.min(user.pending, p.amount); l.info("liquid confirmed", user.username, p.amount); emit(user.username, "user", user); |
