Added better confirmations counting
This commit is contained in:
parent
779af53fcb
commit
32cc6e166c
@ -1279,8 +1279,9 @@
|
||||
}
|
||||
txDetailsAbortController = new AbortController();
|
||||
btcOperator.getTx(txid).then(result => {
|
||||
console.log(result)
|
||||
const { block, time, size, fee, inputs, outputs, confirmations = 0, total_input_value, total_output_value } = result;
|
||||
const isUnconfirmed = block === null || confirmations === 0 || confirmations === null || block <= 0;
|
||||
const isUnconfirmed = block < 0 || block === null || block === undefined
|
||||
renderElem(getRef('tx_details'), html`
|
||||
<h3>Transaction Details</h3>
|
||||
<div class="flex align-center gap-1 space-between flex-wrap">
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
(function (EXPORTS) { //btcOperator v1.2.6
|
||||
(function (EXPORTS) { //btcOperator v1.2.7
|
||||
/* BTC Crypto and API Operator */
|
||||
const btcOperator = EXPORTS;
|
||||
const SATOSHI_IN_BTC = 1e8;
|
||||
@ -75,6 +75,9 @@
|
||||
return util.Sat_to_BTC(balance)
|
||||
})
|
||||
},
|
||||
latestBlock() {
|
||||
return fetch_api(`blocks/tip/height`, { url: this.url })
|
||||
},
|
||||
// tx({ txid, url }) {
|
||||
// return fetch_api(`tx/${txid}`, { url: url || this.url })
|
||||
// .then(result => formatTx(result))
|
||||
@ -108,6 +111,9 @@
|
||||
return fetch_api(`address/${addr}`, { url: this.url })
|
||||
.then(result => util.Sat_to_BTC(result.chain_stats.funded_txo_sum - result.chain_stats.spent_txo_sum))
|
||||
},
|
||||
latestBlock() {
|
||||
return fetch_api(`blocks/tip/height`, { url: this.url })
|
||||
},
|
||||
// tx({ txid }) {
|
||||
// return fetch_api(`tx/${txid}`, { url: this.url })
|
||||
// .then(result => formatTx(result))
|
||||
@ -157,6 +163,9 @@
|
||||
return fetch_api(`rawaddr/${addr}${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
|
||||
.then(result => result.txs)
|
||||
},
|
||||
latestBlock() {
|
||||
return fetch_api(`q/getblockcount`, { url: this.url })
|
||||
},
|
||||
async block({ id }) {
|
||||
try {
|
||||
let block
|
||||
@ -234,10 +243,14 @@
|
||||
|
||||
const formatTx = btcOperator.util.format.tx = async (tx) => {
|
||||
try {
|
||||
const { txid, hash, time, block_height, fee, fees, received,
|
||||
let { txid, hash, time, block_height, fee, fees, received,
|
||||
confirmed, size, double_spend, block_hash, confirmations,
|
||||
status: { block_height: statusBlockHeight, block_hash: statusBlockHash, block_time } = {}
|
||||
} = tx;
|
||||
if ((block_height || statusBlockHeight) && confirmations === undefined || confirmations === null) {
|
||||
const latestBlock = await multiApi('latestBlock');
|
||||
confirmations = latestBlock - (block_height || statusBlockHeight);
|
||||
}
|
||||
const inputs = tx.vin || tx.inputs;
|
||||
const outputs = tx.vout || tx.outputs || tx.out;
|
||||
return {
|
||||
@ -294,9 +307,9 @@
|
||||
throw "No API available"
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
if (error.code && [429, 404].includes(error.code)) {
|
||||
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
|
||||
return multiApi(fnName, { index: index + 1, ...args });
|
||||
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
|
||||
return multiApi(fnName, { index: index + 1, ...args });
|
||||
if (error.code && [301, 429, 404].includes(error.code)) {
|
||||
} else {
|
||||
throw error.message || error;
|
||||
}
|
||||
@ -1380,18 +1393,11 @@
|
||||
return Crypto.util.bytesToHex(txid);
|
||||
}
|
||||
|
||||
const getLatestBlock = btcOperator.getLatestBlock = () => new Promise((resolve, reject) => {
|
||||
fetch_api(`q/getblockcount`)
|
||||
.then(result => resolve(result))
|
||||
.catch(error => reject(error))
|
||||
})
|
||||
|
||||
const getTx = btcOperator.getTx = txid => new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const result = await multiApi('tx', { txid });
|
||||
if (!result.hasOwnProperty('confirmations'))
|
||||
result.confirmations = await getLatestBlock() - result.block_height;
|
||||
resolve({
|
||||
confirmations: result.confirmations,
|
||||
block: result.block_height,
|
||||
txid: result.hash,
|
||||
time: result.time,
|
||||
|
||||
2
scripts/btcOperator.min.js
vendored
2
scripts/btcOperator.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user