aboutsummaryrefslogtreecommitdiffstats
path: root/lib/buildtx.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-06 09:20:25 -0700
committerAdam Soltys <[email protected]>2022-09-06 09:20:25 -0700
commitc2464b2407ee23134732fd67586758dbfe18f9b5 (patch)
tree3e2d9f009bb325a9a7c4304ea02f6e64dda85bd1 /lib/buildtx.js
parent8a080ef9a198799e7ee31cf81f92afd5495e4074 (diff)
downloadcoinos-server-c2464b2407ee23134732fd67586758dbfe18f9b5.tar.gz
coinos-server-c2464b2407ee23134732fd67586758dbfe18f9b5.zip
prettier
Diffstat (limited to 'lib/buildtx.js')
-rw-r--r--lib/buildtx.js36
1 files changed, 22 insertions, 14 deletions
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,