From c2464b2407ee23134732fd67586758dbfe18f9b5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 6 Sep 2022 09:20:25 -0700 Subject: prettier --- lib/buildtx.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'lib/buildtx.js') diff --git a/lib/buildtx.js b/lib/buildtx.js index 24b8c91a..daed2e73 100644 --- a/lib/buildtx.js +++ b/lib/buildtx.js @@ -1,9 +1,9 @@ import store from "./store"; import { prod } from "./utils"; -import axios from 'axios'; -import bitcoin from 'bitcoinjs-lib'; -import coinselect from 'coinselect'; -import split from 'coinselect/split'; +import axios from "axios"; +import bitcoin from "bitcoinjs-lib"; +import coinselect from "coinselect"; +import split from "coinselect/split"; const api = prod ? "https://blockstream.info/api" : "http://electrsb:3095"; const SATS = 100000000; const network = prod @@ -18,20 +18,21 @@ export default async ({ address, amount, feeRate, replaceable, user }) => { where: { received: true, account_id: user.account_id, - network: 'bitcoin', - } + network: "bitcoin" + } }); - const addresses = [...new Set(payments.map(p => p.address))]; const utxos = []; for (let i = 0; i < addresses.length; i++) { try { - utxos.push(...(await axios.get(`${api}/address/${addresses[i]}/utxo`)).data); + utxos.push( + ...(await axios.get(`${api}/address/${addresses[i]}/utxo`)).data + ); } catch (e) { err("problem fetching utxos", e.message); } - } + } let targets = [ { @@ -43,9 +44,16 @@ export default async ({ address, amount, feeRate, replaceable, user }) => { let { inputs, outputs, fee } = coinselect(utxos, targets, feeRate); if (!inputs || !outputs) { - l("utxos", amount, feeRate, utxos.map(u => u.value)); - throw new Error("Couldn't find inputs for transaction, check your balance/fee"); - } + l( + "utxos", + amount, + feeRate, + utxos.map(u => u.value) + ); + throw new Error( + "Couldn't find inputs for transaction, check your balance/fee" + ); + } let psbt = new bitcoin.Psbt({ network }); let total = 0; @@ -53,9 +61,9 @@ export default async ({ address, amount, feeRate, replaceable, user }) => { outputs.map(({ address, value }) => { total += value; if (!address) { - address = payments[payments.length - 1].address; + address = payments[payments.length - 1].address; store.change.push(address); - } + } psbt = psbt.addOutput({ address, -- cgit v1.2.3