diff options
| author | Adam Soltys <[email protected]> | 2022-06-21 22:44:07 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-06-21 22:44:15 -0700 |
| commit | 268d283d830d8cb8f35415f2f168bae69c8a9b6e (patch) | |
| tree | 2bbf4c0193698f7c514f878b453319c34ebc709f /routes/liquid | |
| parent | 3f120a096a0465ccacd35f404237a6fb7cbe7ad2 (diff) | |
| download | coinos-server-268d283d830d8cb8f35415f2f168bae69c8a9b6e.tar.gz coinos-server-268d283d830d8cb8f35415f2f168bae69c8a9b6e.zip | |
fixes for receiving liquid assets
Diffstat (limited to 'routes/liquid')
| -rw-r--r-- | routes/liquid/receive.js | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index 2bd86805..312613e2 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -27,12 +27,28 @@ const getAccount = async (params, transaction) => { return account; } - let { asset } = params; + let { asset, pubkey } = params; let name = asset.substr(0, 6); let domain = ""; let ticker = asset.substr(0, 3).toUpperCase(); let precision = 8; + if (pubkey) { + const nc = await db.Account.findOne({ + where: { pubkey }, + order: [["id", "ASC"]], + limit: 1, + lock: transaction.LOCK.UPDATE, + transaction + }); + + params.index = 0; + params.path = nc.path; + params.pubkey = nc.pubkey; + params.privkey = nc.privkey; + params.seed = nc.seed; + } + const assets = app.get("assets"); if (assets[asset]) { @@ -56,6 +72,7 @@ const getAccount = async (params, transaction) => { params = { ...params, ...{ domain, ticker, precision, name } }; params.balance = 0; + params.pending = 0; params.network = "liquid"; return db.Account.create(params, { transaction }); }; @@ -119,48 +136,32 @@ zmqRawTx.on("message", async (topic, message, sequence) => { if (!invoice) return; - let payment = await db.Payment.findOne({ - where: { - invoice_id: invoice.id, - }, - order: [["id", "DESC"]], - transaction - }); - - if (payment) return; - let confirmed = 0; let account = await db.Account.findOne({ where: { - id: invoice.account_id, - asset + id: invoice.account_id }, lock: transaction.LOCK.UPDATE, transaction }); - if ( - account.asset === asset && - (!account.pubkey || account.network === "liquid") - ) { - await account.increment({ pending: value }, { transaction }); - await account.reload({ transaction }); - } else { + if (!(account && account.asset === asset)) { + let pubkey = account ? account.pubkey : null; + account = await getAccount( { - seed: account.seed, - path: account.path, user_id: user.id, asset, - pubkey: account.pubkey, - pending: value, - index: 0 + pubkey }, transaction ); } + await account.increment({ pending: value }, { transaction }); + await account.reload({ transaction }); + if (config.liquid.walletpass) await lq.walletPassphrase(config.liquid.walletpass, 300); |
