conform getPrevouts and getCpfpLocalTx to new error handling standard
This commit is contained in:
parent
e05a9a6dfa
commit
74fa3c7eb1
@ -936,11 +936,13 @@ class BitcoinRoutes {
|
|||||||
try {
|
try {
|
||||||
const outpoints = req.body;
|
const outpoints = req.body;
|
||||||
if (!Array.isArray(outpoints) || outpoints.some((item) => !/^[a-fA-F0-9]{64}$/.test(item.txid) || typeof item.vout !== 'number')) {
|
if (!Array.isArray(outpoints) || outpoints.some((item) => !/^[a-fA-F0-9]{64}$/.test(item.txid) || typeof item.vout !== 'number')) {
|
||||||
return res.status(400).json({ message: 'Invalid input format' });
|
handleError(req, res, 400, 'Invalid outpoints format');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outpoints.length > 100) {
|
if (outpoints.length > 100) {
|
||||||
return res.status(400).json({ message: 'Too many prevouts requested' });
|
handleError(req, res, 400, 'Too many outpoints requested');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = Array(outpoints.length).fill(null);
|
const result = Array(outpoints.length).fill(null);
|
||||||
@ -955,7 +957,7 @@ class BitcoinRoutes {
|
|||||||
if (mempoolTx) {
|
if (mempoolTx) {
|
||||||
if (outpoint.vout < mempoolTx.vout.length) {
|
if (outpoint.vout < mempoolTx.vout.length) {
|
||||||
prevout = mempoolTx.vout[outpoint.vout];
|
prevout = mempoolTx.vout[outpoint.vout];
|
||||||
unconfirmed = true;
|
unconfirmed = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const rawPrevout = await bitcoinClient.getTxOut(outpoint.txid, outpoint.vout, false);
|
const rawPrevout = await bitcoinClient.getTxOut(outpoint.txid, outpoint.vout, false);
|
||||||
@ -979,7 +981,7 @@ class BitcoinRoutes {
|
|||||||
res.json(result);
|
res.json(result);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
handleError(req, res, 500, 'Failed to get prevouts');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -988,22 +990,23 @@ class BitcoinRoutes {
|
|||||||
const tx = req.body;
|
const tx = req.body;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!tx || typeof tx !== "object" ||
|
!tx || typeof tx !== 'object' ||
|
||||||
!tx.txid || typeof tx.txid !== "string" ||
|
!tx.txid || typeof tx.txid !== 'string' ||
|
||||||
typeof tx.weight !== "number" ||
|
typeof tx.weight !== 'number' ||
|
||||||
typeof tx.sigops !== "number" ||
|
typeof tx.sigops !== 'number' ||
|
||||||
typeof tx.fee !== "number" ||
|
typeof tx.fee !== 'number' ||
|
||||||
!Array.isArray(tx.vin) ||
|
!Array.isArray(tx.vin) ||
|
||||||
!Array.isArray(tx.vout)
|
!Array.isArray(tx.vout)
|
||||||
) {
|
) {
|
||||||
return res.status(400).json({ message: 'Invalid transaction format: missing or incorrect fields' });
|
handleError(req, res, 400, 'Invalid transaction format');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cpfpInfo = calculateLocalTxCpfp(tx, mempool.getMempool());
|
const cpfpInfo = calculateLocalTxCpfp(tx, mempool.getMempool());
|
||||||
res.json(cpfpInfo);
|
res.json(cpfpInfo);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError(req, res, 500, e instanceof Error ? e.message : e);
|
handleError(req, res, 500, 'Failed to calculate CPFP info');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,8 @@ export class TransactionRawComponent implements OnInit, OnDestroy {
|
|||||||
this.isLoadingPrevouts = false;
|
this.isLoadingPrevouts = false;
|
||||||
this.fetchCpfp = prevouts.some(prevout => prevout?.unconfirmed);
|
this.fetchCpfp = prevouts.some(prevout => prevout?.unconfirmed);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.errorPrevouts = error?.error?.message || error?.message;
|
console.log(error);
|
||||||
|
this.errorPrevouts = error?.error?.error || error?.message;
|
||||||
this.isLoadingPrevouts = false;
|
this.isLoadingPrevouts = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +172,7 @@ export class TransactionRawComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
this.isLoadingCpfpInfo = false;
|
this.isLoadingCpfpInfo = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.errorCpfpInfo = error?.error?.message || error?.message;
|
this.errorCpfpInfo = error?.error?.error || error?.message;
|
||||||
this.isLoadingCpfpInfo = false;
|
this.isLoadingCpfpInfo = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user