aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin/receive.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-08-16 21:34:13 -0700
committerAdam Soltys <[email protected]>2020-08-16 21:34:13 -0700
commit7ab3036cb1576fe38ba1fd423a58b7cd97a58579 (patch)
tree305b1a0aa321389b60385009876bbdb1fe0a1c68 /routes/bitcoin/receive.js
parentb2208797d3c5559c7e8cc7d35b7a020da0c61193 (diff)
downloadcoinos-server-7ab3036cb1576fe38ba1fd423a58b7cd97a58579.tar.gz
coinos-server-7ab3036cb1576fe38ba1fd423a58b7cd97a58579.zip
non-custodial liquid wallets
Diffstat (limited to 'routes/bitcoin/receive.js')
-rw-r--r--routes/bitcoin/receive.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index ec120605..987f5079 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -1,6 +1,7 @@
const reverse = require("buffer-reverse");
const zmq = require("zeromq");
const { Op } = require("sequelize");
+const { fromBase58 } = require("bip32");
const bitcoin = require("bitcoinjs-lib");
@@ -35,7 +36,10 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
return;
}
- if (Object.keys(addresses).includes(address) && !change.includes(address)) {
+ if (
+ Object.keys(addresses).includes(address) &&
+ !change.includes(address)
+ ) {
payments.push(hash);
let user = await db.User.findOne({
@@ -55,7 +59,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
const currency = invoice ? invoice.currency : user.currency;
const rate = invoice ? invoice.rate : app.get("rates")[user.currency];
const tip = invoice ? invoice.tip : 0;
- const memo = invoice ? invoice.memo : '';
+ const memo = invoice ? invoice.memo : "";
let confirmed = false;
@@ -66,7 +70,19 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
},
});
- let account = accounts.find(a => a.address === address);
+ let account = accounts.find(({ index, pubkey }) => {
+ const { payments } = bitcoin;
+ index &&
+ pubkey &&
+ address ===
+ payments.p2wpkh({
+ pubkey: fromBase58(pubkey, network).derivePath(
+ `${index}`
+ ).publicKey,
+ network,
+ }).address;
+ });
+
if (!account) account = accounts[0];
account.pending += value;