diff options
| author | Adam Soltys <[email protected]> | 2021-05-21 14:05:02 -0400 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-05-21 14:05:02 -0400 |
| commit | 3ce9c73b1d4a281fe1475206d49c4f436e0b992e (patch) | |
| tree | 8e8324d74761f164d9615a068a0f4f840506e642 /routes/liquid | |
| parent | 37412d24f5c7b0c6d316ce240ef29cd4ccd2ca6d (diff) | |
| download | coinos-server-3ce9c73b1d4a281fe1475206d49c4f436e0b992e.tar.gz coinos-server-3ce9c73b1d4a281fe1475206d49c4f436e0b992e.zip | |
persist liquid conversion requests
Diffstat (limited to 'routes/liquid')
| -rw-r--r-- | routes/liquid/fee.js | 22 | ||||
| -rw-r--r-- | routes/liquid/receive.js | 11 | ||||
| -rw-r--r-- | routes/liquid/send.js | 23 |
3 files changed, 34 insertions, 22 deletions
diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js index debbdf55..2070873a 100644 --- a/routes/liquid/fee.js +++ b/routes/liquid/fee.js @@ -2,6 +2,12 @@ const buildTx = require("../../lib/buildliquidtx"); liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => { let tx, fee; + let node = lq; + /* + if (asset === config.liquid.btcasset) { + node = rare; + } + */ if (user.account.pubkey) { let psbt = await buildTx({ @@ -25,7 +31,7 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => { }); if (invoice) { - let { ismine } = await lq.getAddressInfo(address); + let { ismine } = await node.getAddressInfo(address); if (ismine) { emit(user.username, "to", invoice.user); return; @@ -33,7 +39,7 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => { } if (config.liquid.walletpass) - await lq.walletPassphrase(config.liquid.walletpass, 300); + await node.walletPassphrase(config.liquid.walletpass, 300); amount = parseInt(amount); @@ -44,9 +50,9 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => { let value = (amount / SATS).toFixed(8); if (feeRate) params.feeRate = (feeRate / SATS).toFixed(8); - let info = await lq.getAddressInfo(address); + let info = await node.getAddressInfo(address); - tx = await lq.createRawTransaction( + tx = await node.createRawTransaction( [], { [address]: (amount / SATS).toFixed(8) @@ -58,12 +64,12 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => { } ); - tx = await lq.fundRawTransaction(tx, params); + tx = await node.fundRawTransaction(tx, params); - let blinded = await lq.blindRawTransaction(tx.hex); - let signed = await lq.signRawTransactionWithWallet(blinded); + let blinded = await node.blindRawTransaction(tx.hex); + let signed = await node.signRawTransactionWithWallet(blinded); - decoded = await lq.decodeRawTransaction(signed.hex); + decoded = await node.decodeRawTransaction(signed.hex); feeRate = Math.round((tx.fee * SATS * 1000) / decoded.vsize); l.info("estimated", asset, feeRate); diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index f6a78cfa..14fc8b3d 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -308,7 +308,7 @@ setInterval(async () => { ({ account, address, user } = p); if (p && p.account) { - let total = p.amount + p.tip; + total = p.amount + p.tip; p.confirmed = 1; await p.account.save({ transaction }); @@ -344,20 +344,17 @@ setInterval(async () => { let c = convert[address]; if (c) { - let { tx } = c; user.account = account; - delete queue[hash]; - await sendLiquid({ - address, + address: c.address, + amount: total - 100, user, - tx, limit: total }); } } } catch (e) { - l.error("problem processing queued liquid transaction", e.message); + l.error("problem processing queued liquid transaction", e.message, e.stack); } }, 1000); diff --git a/routes/liquid/send.js b/routes/liquid/send.js index b80471b0..55041845 100644 --- a/routes/liquid/send.js +++ b/routes/liquid/send.js @@ -1,7 +1,19 @@ const btc = config.liquid.btcasset; const lcad = config.liquid.cadasset; -sendLiquid = async ({ user, address, memo, tx, limit }) => { +sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => { + l.info("sending liquid", amount, user, address); + if (!tx) { + ({ tx } = await liquidTx({ + address, + asset, + amount, + feeRate: 100, + replaceable: false, + user + })); + } + const isChange = async address => (await lq.getAddressInfo(address)).ismine && !Object.keys(addresses).includes(address); @@ -126,6 +138,8 @@ sendLiquid = async ({ user, address, memo, tx, limit }) => { let signed = await lq.signRawTransactionWithWallet(blinded); let txid = await lq.sendRawTransaction(signed.hex); + l.info("sent liquid tx", txid, address); + let main; for (let i = 0; i < assets.length; i++) { p = payments[i]; @@ -150,12 +164,7 @@ module.exports = ah(async (req, res) => { let { user } = req; try { - let { address, feeRate, memo, tx } = req.body; - - if (!tx) { - ({ tx } = await liquidTx({ ...req.body, user })); - } - res.send(await sendLiquid({ user, address, memo, tx })); + res.send(await sendLiquid({...req.body, user })); } catch (e) { l.error("problem sending liquid", user.username, e.message); return res.status(500).send(e); |
