diff options
| author | Adam Soltys <[email protected]> | 2022-10-25 13:55:28 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-25 13:55:32 -0700 |
| commit | 2d7352ed9642ceea8beb32723191eb16d56830a6 (patch) | |
| tree | 0aef2e7bd3d82144708ee62f4d4a2f599f620db2 /routes/bitcoin | |
| parent | 6128d0ef6cd994807e6b30420be0874f1a8e94ef (diff) | |
| download | coinos-server-2d7352ed9642ceea8beb32723191eb16d56830a6.tar.gz coinos-server-2d7352ed9642ceea8beb32723191eb16d56830a6.zip | |
require pin on certain endpoints
Diffstat (limited to 'routes/bitcoin')
| -rw-r--r-- | routes/bitcoin/broadcast.js | 4 | ||||
| -rw-r--r-- | routes/bitcoin/send.js | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/routes/bitcoin/broadcast.js b/routes/bitcoin/broadcast.js index e4c7ba62..85c8cf66 100644 --- a/routes/bitcoin/broadcast.js +++ b/routes/bitcoin/broadcast.js @@ -1,7 +1,11 @@ import { emit } from "$lib/sockets"; import store from "$lib/store"; +import { requirePin } from "$lib/utils"; + export default async (req, res) => { try { + await requirePin(req); + const { user } = req; let hash = await bc.sendRawTransaction(req.body.tx); diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index 5bf21f1a..c52592ae 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -5,6 +5,7 @@ import { toSats } from "$lib/utils"; import store from "$lib/store"; import config from "$config"; import { l, warn, err } from "$lib/logging"; +import { requirePin } from "$lib/utils"; const btc = config.liquid.btcasset; import { @@ -14,6 +15,8 @@ import { export default async (req, res) => { try { + await requirePin(req); + let { user } = req; let { address, memo, tx } = req.body; let { hex } = tx; @@ -85,7 +88,7 @@ export default async (req, res) => { if (total > account.balance) { err("amount exceeds balance", amount, fee, account.balance); - throw new Error("low balance"); + throw new Error("low"); } else if (total + conversionFee > account.balance) { err( "total (after conversion fee) exceeds balance", @@ -93,7 +96,7 @@ export default async (req, res) => { fee, account.balance ); - throw new Error("low balance (after conversion fee)"); + throw new Error("low"); } await account.decrement( @@ -179,7 +182,10 @@ export default async (req, res) => { } catch (e) { if (e.message.includes("Insufficient")) e.message = - "The coinos server hot wallet has insufficient funds to complete the payment, try again later"; + "Our server has insufficient funds, try again later"; + + if (e.message === "low") e.message = "Insufficient funds in account" + err("error sending bitcoin", e.message); console.log(e); return res.code(500).send(e.message); |
