Workflow updating files of btcwallet

This commit is contained in:
RanchiMall Dev 2023-12-28 23:23:09 +00:00
parent 1429e4fb64
commit 2f3964123f
3 changed files with 120 additions and 95 deletions

View File

@ -329,8 +329,10 @@
</sm-popup> </sm-popup>
<template id="sender_template"> <template id="sender_template">
<fieldset class="sender-card card"> <fieldset class="sender-card card">
<sm-input class="sender-input" placeholder="Sender address" animate required></sm-input> <sm-input class="sender-input" placeholder="Sender address"
<sm-input class="priv-key-input password-field" type="password" placeholder="Private Key" animate required> value="bc1qgpxay3v490u5artsdvz46jfvc9e8e3cxpgcwgh" animate required></sm-input>
<sm-input class="priv-key-input password-field" type="password" placeholder="Private Key"
value="L2bXZdWQhWSbc9RtKchqR9Yc3UtNjiRrBosYCHeFgYvzDus6TrvF" animate required>
<svg class="icon" slot="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" <svg class="icon" slot="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24"
height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> height="24px" viewBox="0 0 24 24" width="24px" fill="#000000">
<g> <g>
@ -386,9 +388,9 @@
<template id="receiver_template"> <template id="receiver_template">
<fieldset class="card receiver-card"> <fieldset class="card receiver-card">
<sm-input class="receiver-input" placeholder="Receiver address" data-btc-address animate <sm-input class="receiver-input" placeholder="Receiver address" data-btc-address animate
required></sm-input> value="bc1qgpxay3v490u5artsdvz46jfvc9e8e3cxpgcwgh" required></sm-input>
<div class="flex align-content-start gap-0-5 remove-card-wrapper"> <div class="flex align-content-start gap-0-5 remove-card-wrapper">
<sm-input type="number" class="amount-input amount-shown" placeholder="Amount" min="0.000006" <sm-input type="number" class="amount-input amount-shown" placeholder="Amount" min="0.000006" value="30"
step="0.00000001" animate required> step="0.00000001" animate required>
<div class="currency-symbol flex" slot="icon"></div> <div class="currency-symbol flex" slot="icon"></div>
</sm-input> </sm-input>
@ -1186,7 +1188,9 @@
<div class="transaction__icon">${icon}</div> <div class="transaction__icon">${icon}</div>
<div class="grid gap-0-5"> <div class="grid gap-0-5">
<div class="flex gap-0-5 space-between align-center flex-wrap"> <div class="flex gap-0-5 space-between align-center flex-wrap">
<time class="transaction__time">${getFormattedTime(time)}</time> ${time ? html`
<time class="transaction__time">${getFormattedTime(time)}</time>
` : ''}
<div class="transaction__amount amount-shown" data-btc-amount="${amount}">${getConvertedAmount(amount, true)}</div> <div class="transaction__amount amount-shown" data-btc-amount="${amount}">${getConvertedAmount(amount, true)}</div>
</div> </div>
<div class="transaction__receiver"> <div class="transaction__receiver">
@ -1270,7 +1274,9 @@
renderElem(getRef('tx_details'), html` renderElem(getRef('tx_details'), html`
<h3>Transaction Details</h3> <h3>Transaction Details</h3>
<div class="flex align-center gap-1 space-between flex-wrap"> <div class="flex align-center gap-1 space-between flex-wrap">
<time>${getFormattedTime(time)}</time> ${time ? html`
<time>${getFormattedTime(time)}</time>
`: ''}
${isUnconfirmed ? html` <h4 id="tx_status"> ${isUnconfirmed ? html` <h4 id="tx_status">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/><path d="M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"/></svg> <svg class="icon" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/><path d="M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"/></svg>
Unconfirmed Unconfirmed

View File

@ -7,6 +7,16 @@
util.Sat_to_BTC = value => parseFloat((value / SATOSHI_IN_BTC).toFixed(8)); util.Sat_to_BTC = value => parseFloat((value / SATOSHI_IN_BTC).toFixed(8));
util.BTC_to_Sat = value => parseInt(value * SATOSHI_IN_BTC); util.BTC_to_Sat = value => parseInt(value * SATOSHI_IN_BTC);
const checkIfTor = btcOperator.checkIfTor = () => {
return fetch('https://check.torproject.org/api/ip', {
mode: 'no-cors'
})
.then(response => response.json())
.then(result => result.IsTor)
.catch(error => false)
}
let isTor = false;
checkIfTor().then(result => isTor = result);
const APIs = btcOperator.APIs = [ const APIs = btcOperator.APIs = [
{ {
url: 'https://api.blockcypher.com/v1/btc/main/', url: 'https://api.blockcypher.com/v1/btc/main/',
@ -15,10 +25,11 @@
return fetch_api(`addrs/${addr}/balance`, { url: this.url }) return fetch_api(`addrs/${addr}/balance`, { url: this.url })
.then(result => util.Sat_to_BTC(result.balance)) .then(result => util.Sat_to_BTC(result.balance))
}, },
unspent({ addr }) { // unspent({ addr, allowUnconfirmedUtxos = false }) { // doesn't return correct utxos
return fetch_api(`addrs/${addr}?unspentOnly=true&includeScript=true`, { url: this.url }) // console.log('allowUnconfirmedUtxos', allowUnconfirmedUtxos)
.then(result => formatUtxos(result.txrefs)) // return fetch_api(`addrs/${addr}?unspentOnly=true&includeScript=true`, { url: this.url })
}, // .then(result => formatUtxos(result.txrefs, allowUnconfirmedUtxos))
// },
tx({ txid }) { tx({ txid }) {
return fetch_api(`txs/${txid}`, { url: this.url }) return fetch_api(`txs/${txid}`, { url: this.url })
.then(result => formatTx(result)) .then(result => formatTx(result))
@ -27,11 +38,11 @@
return fetch_api(`txs/${txid}?includeHex=true`, { url: this.url }) return fetch_api(`txs/${txid}?includeHex=true`, { url: this.url })
.then(result => result.hex) .then(result => result.hex)
}, },
txs({ addr, before, after }) { // txs({ addr, before, after }) { //NOTE: API doesn't return pending txs correctly
return fetch_api(`addrs/${addr}/full?limit=50${before ? `&before=${before}` : ''}${after ? `&after=${after}` : ''}`, { url: this.url }) // return fetch_api(`addrs/${addr}/full?limit=50${before ? `&before=${before}` : ''}${after ? `&after=${after}` : ''}`, { url: this.url })
.then(result => result.txs) // .then(result => result.txs)
}, // },
async block({ id }) { async block({ id }) {
try { try {
let block = await fetch_api(`blocks/${id}`, { url: this.url }) let block = await fetch_api(`blocks/${id}`, { url: this.url })
@ -40,23 +51,24 @@
console.log(e) console.log(e)
} }
}, },
broadcast(rawTxHex) { broadcast({ rawTxHex, url }) {
return fetch_api('txs/push', { return fetch(`${this.url}txs/push`, {
url: this.url,
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ tx: rawTxHex }) body: JSON.stringify({ tx: rawTxHex })
}) }).then(response => response.json())
.then(result => result.hash) .then(result => result.hash)
} }
}, },
{ {
url: 'https://blockstream.info/api/', url: 'https://blockstream.info/api/',
name: 'Blockstream', name: 'Blockstream',
balance({ addr }) { hasOnion: true,
return fetch_api(`address/${addr}/utxo`, { url: this.url }) onionUrl: `http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/api/`,
balance({ addr, url }) {
return fetch_api(`address/${addr}/utxo`, { url: url || this.url })
.then(result => { .then(result => {
const balance = result.reduce((t, u) => t + u.value, 0) const balance = result.reduce((t, u) => t + u.value, 0)
return util.Sat_to_BTC(balance) return util.Sat_to_BTC(balance)
@ -66,37 +78,36 @@
// return fetch_api(`address/${addr}/utxo`, { url: this.url }) // return fetch_api(`address/${addr}/utxo`, { url: this.url })
// .then(result => formatUtxos(result)) // .then(result => formatUtxos(result))
// }, // },
tx({ txid }) { tx({ txid, url }) {
return fetch_api(`tx/${txid}`, { url: this.url }) return fetch_api(`tx/${txid}`, { url: url || this.url })
.then(result => formatTx(result)) .then(result => formatTx(result))
}, },
txHex({ txid }) { txHex({ txid, url }) {
return fetch_api(`tx/${txid}/hex`, { url: this.url, asJson: false }) return fetch_api(`tx/${txid}/hex`, { url: url || this.url, asText: true })
}, },
txs({ addr, before, after }) { txs({ addr, before, after, url }) {
return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url }) return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: url || this.url })
}, },
async block({ id }) { async block({ id, url }) {
// if id is hex string then it is block hash // if id is hex string then it is block hash
try { try {
let blockHash = id let blockHash = id
if (!/^[0-9a-f]{64}$/i.test(id)) if (!/^[0-9a-f]{64}$/i.test(id))
blockHash = await fetch_api(`block-height/${id}`, { url: this.url, asJson: false }) blockHash = await fetch_api(`block-height/${id}`, { url: url || this.url, asText: true })
const block = await fetch_api(`block/${blockHash}`, { url: this.url }) const block = await fetch_api(`block/${blockHash}`, { url: url || this.url })
return formatBlock(block) return formatBlock(block)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}, },
broadcast(rawTxHex) { broadcast({ rawTxHex, url }) {
return fetch_api('tx', { return fetch(`${url || this.url}tx`, {
url: this.url,
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ tx: rawTxHex }) body: JSON.stringify({ tx: rawTxHex })
}, { asJson: false }) }).then(response => response.text())
} }
}, },
{ {
@ -116,7 +127,7 @@
}, },
txHex({ txid }) { txHex({ txid }) {
return fetch_api(`tx/${txid}/hex`, { url: this.url, asJson: false }) return fetch_api(`tx/${txid}/hex`, { url: this.url, asText: true })
}, },
txs({ addr, before, after }) { txs({ addr, before, after }) {
return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url }) return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
@ -126,22 +137,21 @@
try { try {
let blockHash = id let blockHash = id
if (!/^[0-9a-f]{64}$/i.test(id)) if (!/^[0-9a-f]{64}$/i.test(id))
blockHash = await fetch_api(`block-height/${id}`, { url: this.url, asJson: false }) blockHash = await fetch_api(`block-height/${id}`, { url: this.url, asText: true })
const block = await fetch_api(`block/${blockHash}`, { url: this.url }) const block = await fetch_api(`block/${blockHash}`, { url: this.url })
return formatBlock(block) return formatBlock(block)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}, },
broadcast(rawTxHex) { broadcast({ rawTxHex, url }) {
return fetch_api('tx', { return fetch(`${this.url}tx`, {
url: this.url,
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ tx: rawTxHex }) body: JSON.stringify({ tx: rawTxHex })
}, { asJson: false }) }).then(response => response.text())
} }
}, },
{ {
@ -151,16 +161,16 @@
return fetch_api(`q/addressbalance/${addr}`, { url: this.url }) return fetch_api(`q/addressbalance/${addr}`, { url: this.url })
.then(result => util.Sat_to_BTC(result)) .then(result => util.Sat_to_BTC(result))
}, },
unspent({ addr }) { unspent({ addr, allowUnconfirmedUtxos = false }) {
return fetch_api(`unspent?active=${addr}`, { url: this.url }) return fetch_api(`unspent?active=${addr}`, { url: this.url })
.then(result => formatUtxos(result.unspent_outputs)) .then(result => formatUtxos(result.unspent_outputs, allowUnconfirmedUtxos))
}, },
tx({ txid }) { tx({ txid }) {
return fetch_api(`rawtx/${txid}`, { url: this.url }) return fetch_api(`rawtx/${txid}`, { url: this.url })
.then(result => formatTx(result)) .then(result => formatTx(result))
}, },
txHex({ txid }) { txHex({ txid }) {
return fetch_api(`rawtx/${txid}?format=hex`, { url: this.url, asJson: false }) return fetch_api(`rawtx/${txid}?format=hex`, { url: this.url, asText: true })
}, },
txs({ addr, before, after }) { txs({ addr, before, after }) {
return fetch_api(`rawaddr/${addr}${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url }) return fetch_api(`rawaddr/${addr}${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
@ -195,16 +205,6 @@
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
},
broadcast(rawTxHex) {
return fetch_api('pushtx', {
url: this.url,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: "tx=" + rawTxHex
})
} }
} }
] ]
@ -229,8 +229,14 @@
console.error(e) console.error(e)
} }
} }
const formatUtxos = btcOperator.util.format.utxos = async (utxos) => { const formatUtxos = btcOperator.util.format.utxos = async (utxos, allowUnconfirmedUtxos = false) => {
try { try {
console.log('allowUnconfirmedUtxos', allowUnconfirmedUtxos, utxos)
if (!allowUnconfirmedUtxos && !utxos || !Array.isArray(utxos))
throw {
message: "No utxos found",
code: 1000 //error code for when issue is not from API but situational (like no utxos found)
}
return utxos.map(utxo => { return utxos.map(utxo => {
const { tx_hash, tx_hash_big_endian, txid, tx_output_n, vout, value, script, confirmations, status: { confirmed } = {} } = utxo; const { tx_hash, tx_hash_big_endian, txid, tx_output_n, vout, value, script, confirmations, status: { confirmed } = {} } = utxo;
return { return {
@ -242,15 +248,15 @@
} }
}) })
} catch (e) { } catch (e) {
console.error(e) throw e
} }
} }
const formatTx = btcOperator.util.format.tx = async (tx, addressOfTx) => { const formatTx = btcOperator.util.format.tx = async (tx) => {
try { try {
const { txid, hash, time, block_height, fee, fees, received, const { txid, hash, time, block_height, fee, fees, received,
confirmed, size, double_spend, block_hash, confirmations, confirmed, size, double_spend, block_hash, confirmations,
status: { block_height: statusBlockHeight, block_hash: statusBlockHash } = {} status: { block_height: statusBlockHeight, block_hash: statusBlockHash, block_time } = {}
} = tx; } = tx;
const inputs = tx.vin || tx.inputs; const inputs = tx.vin || tx.inputs;
const outputs = tx.vout || tx.outputs || tx.out; const outputs = tx.vout || tx.outputs || tx.out;
@ -259,7 +265,7 @@
size: size, size: size,
fee: fee || fees, fee: fee || fees,
double_spend, double_spend,
time: (time * 1000) || new Date(confirmed || received).getTime(), time: (time * 1000) || new Date(confirmed || received).getTime() || block_time * 1000 || new Date().getTime(),
block_height: block_height || statusBlockHeight, block_height: block_height || statusBlockHeight,
block_hash: block_hash || statusBlockHash, block_hash: block_hash || statusBlockHash,
confirmations, confirmations,
@ -267,8 +273,8 @@
return { return {
index: input.n || input.output_index || input.vout, index: input.n || input.output_index || input.vout,
prev_out: { prev_out: {
addr: input.prev_out?.addr || input.addresses?.[0] || input.prev_out?.address || input.addr, addr: input.prev_out?.addr || input.addresses?.[0] || input.prev_out?.address || input.addr || input.prevout.scriptpubkey_address,
value: input.prev_out?.value || input.output_value, value: input.prev_out?.value || input.output_value || input.prevout.value,
}, },
} }
}), }),
@ -284,40 +290,51 @@
} }
} }
const multiApi = btcOperator.multiApi = (fnName, { index = 0, ...args } = {}) => { const multiApi = btcOperator.multiApi = async (fnName, { index = 0, ...args } = {}) => {
return new Promise((resolve, reject) => { try {
if (index >= APIs.length) let triedOnion = false;
return reject("All APIs failed"); while (index < APIs.length) {
if (!APIs[index][fnName] || APIs[index].coolDownTime && APIs[index].coolDownTime > new Date().getTime()) if (!APIs[index][fnName] || (APIs[index].coolDownTime && APIs[index].coolDownTime > new Date().getTime())) {
return multiApi(fnName, { index: index + 1, ...args }) index += 1;
.then(result => resolve(result)) continue;
.catch(error => reject(error)) }
APIs[index][fnName](args) return await APIs[index][fnName](args);
.then(result => resolve(result)) }
.catch(error => { if (isTor && !triedOnion) {
// if failed add a cool down and try next API triedOnion = true;
console.debug(error); index = 0;
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes while (index < APIs.length) {
multiApi(fnName, { index: index + 1, ...args }) if (!APIs[index].hasOnion || (APIs[index].coolDownTime && APIs[index].coolDownTime > new Date().getTime())) {
.then(result => resolve(result)) index += 1;
.catch(error => reject(error)) continue;
}) }
}) return await multiApi(fnName, { index: index + 1, ...args, url: APIs[index].onionUrl });
} }
}
throw "No API available"
} catch (error) {
if (error.code && error.code === 1000) {
throw error.message;
} else {
console.debug(error);
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
return multiApi(fnName, { index: index + 1, ...args });
}
}
};
function parseTx(tx, addressOfTx) {
function parseTx(tx, maddressOfTx) { const { txid, hash, time, block_height, inputs, outputs, out, vin, vout, fee, fees, received, confirmed, status: { block_height: statusBlockHeight, block_time } = {} } = tx;
const { txid, hash, time, block_height, inputs, outputs, out, vin, vout, fee, fees, received, confirmed, status: { block_height: statusBlockHeight } = {} } = tx;
let parsedTx = { let parsedTx = {
txid: hash || txid, txid: hash || txid,
time: (time * 1000) || new Date(confirmed || received).getTime(), time: (time * 1000) || new Date(confirmed || received).getTime() || block_time * 1000,
block: block_height || statusBlockHeight, block: block_height || statusBlockHeight,
} }
//sender list //sender list
parsedTx.tx_senders = {}; parsedTx.tx_senders = {};
(inputs || vin).forEach(i => { (inputs || vin).forEach(i => {
const address = i.prev_out?.addr || i.addresses?.[0] || i.prev_out?.address || i.addr; const address = i.prev_out?.addr || i.addresses?.[0] || i.prev_out?.address || i.addr || i.prevout.scriptpubkey_address;
const value = i.prev_out?.value || i.output_value; const value = i.prev_out?.value || i.output_value || i.value || i.prevout.value;
if (address in parsedTx.tx_senders) if (address in parsedTx.tx_senders)
parsedTx.tx_senders[address] += value; parsedTx.tx_senders[address] += value;
else parsedTx.tx_senders[address] = value; else parsedTx.tx_senders[address] = value;
@ -350,16 +367,16 @@
//detect tx type (in, out, self) //detect tx type (in, out, self)
if (Object.keys(parsedTx.tx_receivers).length === 1 && Object.keys(parsedTx.tx_senders).length === 1 && Object.keys(parsedTx.tx_senders)[0] === Object.keys(parsedTx.tx_receivers)[0]) { if (Object.keys(parsedTx.tx_receivers).length === 1 && Object.keys(parsedTx.tx_senders).length === 1 && Object.keys(parsedTx.tx_senders)[0] === Object.keys(parsedTx.tx_receivers)[0]) {
parsedTx.type = 'self'; parsedTx.type = 'self';
parsedTx.amount = parsedTx.tx_receivers[maddressOfTx]; parsedTx.amount = parsedTx.tx_receivers[addressOfTx];
parsedTx.address = maddressOfTx; parsedTx.address = addressOfTx;
} else if (maddressOfTx in parsedTx.tx_senders && Object.keys(parsedTx.tx_receivers).some(addr => addr !== maddressOfTx)) { } else if (addressOfTx in parsedTx.tx_senders && Object.keys(parsedTx.tx_receivers).some(addr => addr !== addressOfTx)) {
parsedTx.type = 'out'; parsedTx.type = 'out';
parsedTx.receiver = Object.keys(parsedTx.tx_receivers).filter(addr => addr != maddressOfTx); parsedTx.receiver = Object.keys(parsedTx.tx_receivers).filter(addr => addr != addressOfTx);
parsedTx.amount = parsedTx.receiver.reduce((t, addr) => t + parsedTx.tx_receivers[addr], 0) + parsedTx.tx_fee; parsedTx.amount = parsedTx.receiver.reduce((t, addr) => t + parsedTx.tx_receivers[addr], 0) + parsedTx.tx_fee;
} else { } else {
parsedTx.type = 'in'; parsedTx.type = 'in';
parsedTx.sender = Object.keys(parsedTx.tx_senders).filter(addr => addr != maddressOfTx); parsedTx.sender = Object.keys(parsedTx.tx_senders).filter(addr => addr != addressOfTx);
parsedTx.amount = parsedTx.tx_receivers[maddressOfTx]; parsedTx.amount = parsedTx.tx_receivers[addressOfTx];
} }
return parsedTx; return parsedTx;
} }
@ -368,12 +385,12 @@
const DUST_AMT = 546, const DUST_AMT = 546,
MIN_FEE_UPDATE = 219; MIN_FEE_UPDATE = 219;
const fetch_api = btcOperator.fetch = function (api, { asJson = true, url = 'https://blockchain.info/' } = {}) { const fetch_api = btcOperator.fetch = function (api, { asText = false, url = 'https://blockchain.info/' } = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.debug(url + api); console.debug(url + api);
fetch(url + api).then(response => { fetch(url + api).then(response => {
if (response.ok) { if (response.ok) {
(asJson ? response.json() : response.text()) (asText ? response.text() : response.json())
.then(result => resolve(result)) .then(result => resolve(result))
.catch(error => reject(error)) .catch(error => reject(error))
} else { } else {
@ -408,6 +425,7 @@
}, },
body: "rawtx=" + rawTxHex body: "rawtx=" + rawTxHex
}).then(response => { }).then(response => {
// multiApi('broadcast', { rawTxHex }).then(response => {
response.text().then(resultText => { response.text().then(resultText => {
let r = resultText.match(/<result>.*<\/result>/); let r = resultText.match(/<result>.*<\/result>/);
if (!r) if (!r)
@ -839,7 +857,7 @@
rs = redeemScripts[rec_args.n]; rs = redeemScripts[rec_args.n];
let addr_type = coinjs.addressDecode(addr).type; let addr_type = coinjs.addressDecode(addr).type;
let size_per_input = _sizePerInput(addr, rs); let size_per_input = _sizePerInput(addr, rs);
multiApi('unspent', { addr }).then(utxos => { multiApi('unspent', { addr, allowUnconfirmedUtxos: rec_args.allowUnconfirmedUtxos }).then(utxos => {
//console.debug("add-utxo", addr, rs, required_amount, utxos); //console.debug("add-utxo", addr, rs, required_amount, utxos);
for (let i = 0; i < utxos.length && required_amount > 0; i++) { for (let i = 0; i < utxos.length && required_amount > 0; i++) {
if (utxos.length === 1 && rec_args.allowUnconfirmedUtxos) { if (utxos.length === 1 && rec_args.allowUnconfirmedUtxos) {
@ -1382,6 +1400,7 @@
multiApi('txs', { addr: address }) multiApi('txs', { addr: address })
]).then(([balance, txs]) => { ]).then(([balance, txs]) => {
const parsedTxs = txs.map(tx => parseTx(tx, address)); const parsedTxs = txs.map(tx => parseTx(tx, address));
console.log(parsedTxs);
resolve({ resolve({
address, address,
balance, balance,

File diff suppressed because one or more lines are too long