mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 22:46:54 +01:00
conform getPrevouts and getCpfpLocalTx to new error handling standard
This commit is contained in:
parent
e05a9a6dfa
commit
74fa3c7eb1
2 changed files with 17 additions and 13 deletions
|
@ -936,11 +936,13 @@ class BitcoinRoutes {
|
|||
try {
|
||||
const outpoints = req.body;
|
||||
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) {
|
||||
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);
|
||||
|
@ -955,7 +957,7 @@ class BitcoinRoutes {
|
|||
if (mempoolTx) {
|
||||
if (outpoint.vout < mempoolTx.vout.length) {
|
||||
prevout = mempoolTx.vout[outpoint.vout];
|
||||
unconfirmed = true;
|
||||
unconfirmed = true;
|
||||
}
|
||||
} else {
|
||||
const rawPrevout = await bitcoinClient.getTxOut(outpoint.txid, outpoint.vout, false);
|
||||
|
@ -979,7 +981,7 @@ class BitcoinRoutes {
|
|||
res.json(result);
|
||||
|
||||
} 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;
|
||||
|
||||
if (
|
||||
!tx || typeof tx !== "object" ||
|
||||
!tx.txid || typeof tx.txid !== "string" ||
|
||||
typeof tx.weight !== "number" ||
|
||||
typeof tx.sigops !== "number" ||
|
||||
typeof tx.fee !== "number" ||
|
||||
!tx || typeof tx !== 'object' ||
|
||||
!tx.txid || typeof tx.txid !== 'string' ||
|
||||
typeof tx.weight !== 'number' ||
|
||||
typeof tx.sigops !== 'number' ||
|
||||
typeof tx.fee !== 'number' ||
|
||||
!Array.isArray(tx.vin) ||
|
||||
!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());
|
||||
res.json(cpfpInfo);
|
||||
|
||||
} 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.fetchCpfp = prevouts.some(prevout => prevout?.unconfirmed);
|
||||
} catch (error) {
|
||||
this.errorPrevouts = error?.error?.message || error?.message;
|
||||
console.log(error);
|
||||
this.errorPrevouts = error?.error?.error || error?.message;
|
||||
this.isLoadingPrevouts = false;
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +172,7 @@ export class TransactionRawComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
this.isLoadingCpfpInfo = false;
|
||||
} catch (error) {
|
||||
this.errorCpfpInfo = error?.error?.message || error?.message;
|
||||
this.errorCpfpInfo = error?.error?.error || error?.message;
|
||||
this.isLoadingCpfpInfo = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue