Update local cpfp API to accept array of transactions
This commit is contained in:
parent
af0c78be81
commit
6c95cd2149
@ -55,7 +55,7 @@ class BitcoinRoutes {
|
|||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from', this.getBlocksByBulk.bind(this))
|
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from', this.getBlocksByBulk.bind(this))
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from/:to', this.getBlocksByBulk.bind(this))
|
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from/:to', this.getBlocksByBulk.bind(this))
|
||||||
.post(config.MEMPOOL.API_URL_PREFIX + 'prevouts', this.$getPrevouts)
|
.post(config.MEMPOOL.API_URL_PREFIX + 'prevouts', this.$getPrevouts)
|
||||||
.post(config.MEMPOOL.API_URL_PREFIX + 'cpfp', this.getCpfpLocalTx)
|
.post(config.MEMPOOL.API_URL_PREFIX + 'cpfp', this.getCpfpLocalTxs)
|
||||||
// Temporarily add txs/package endpoint for all backends until esplora supports it
|
// Temporarily add txs/package endpoint for all backends until esplora supports it
|
||||||
.post(config.MEMPOOL.API_URL_PREFIX + 'txs/package', this.$submitPackage)
|
.post(config.MEMPOOL.API_URL_PREFIX + 'txs/package', this.$submitPackage)
|
||||||
;
|
;
|
||||||
@ -989,25 +989,30 @@ class BitcoinRoutes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCpfpLocalTx(req: Request, res: Response) {
|
private getCpfpLocalTxs(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const tx = req.body;
|
const transactions = req.body;
|
||||||
|
|
||||||
if (
|
if (!Array.isArray(transactions) || transactions.some(tx =>
|
||||||
!tx || typeof tx !== 'object' ||
|
!tx || typeof tx !== 'object' ||
|
||||||
!tx.txid || typeof tx.txid !== 'string' ||
|
!/^[a-fA-F0-9]{64}$/.test(tx.txid) ||
|
||||||
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)
|
||||||
) {
|
)) {
|
||||||
handleError(req, res, 400, 'Invalid transaction format');
|
handleError(req, res, 400, 'Invalid transactions format');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cpfpInfo = calculateLocalTxCpfp(tx, mempool.getMempool());
|
if (transactions.length > 1) {
|
||||||
res.json(cpfpInfo);
|
handleError(req, res, 400, 'More than one transaction is not supported yet');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cpfpInfo = calculateLocalTxCpfp(transactions[0], mempool.getMempool());
|
||||||
|
res.json([cpfpInfo]);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError(req, res, 500, 'Failed to calculate CPFP info');
|
handleError(req, res, 500, 'Failed to calculate CPFP info');
|
||||||
|
@ -222,7 +222,6 @@ export function calculateMempoolTxCpfp(tx: MempoolTransactionExtended, mempool:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an unbroadcasted transaction and a copy of the current mempool, and calculates an estimate
|
* Takes an unbroadcasted transaction and a copy of the current mempool, and calculates an estimate
|
||||||
* of the CPFP data if the transaction were to enter the mempool. This only returns potential ancerstors
|
* of the CPFP data if the transaction were to enter the mempool. This only returns potential ancerstors
|
||||||
|
@ -154,17 +154,17 @@ export class TransactionRawComponent implements OnInit, OnDestroy {
|
|||||||
if (this.hasPrevouts && this.fetchCpfp) {
|
if (this.hasPrevouts && this.fetchCpfp) {
|
||||||
try {
|
try {
|
||||||
this.isLoadingCpfpInfo = true;
|
this.isLoadingCpfpInfo = true;
|
||||||
const cpfpInfo: CpfpInfo = await firstValueFrom(this.apiService.getCpfpLocalTx$({
|
const cpfpInfo: CpfpInfo[] = await firstValueFrom(this.apiService.getCpfpLocalTx$([{
|
||||||
txid: transaction.txid,
|
txid: transaction.txid,
|
||||||
weight: transaction.weight,
|
weight: transaction.weight,
|
||||||
sigops: transaction.sigops,
|
sigops: transaction.sigops,
|
||||||
fee: transaction.fee,
|
fee: transaction.fee,
|
||||||
vin: transaction.vin,
|
vin: transaction.vin,
|
||||||
vout: transaction.vout
|
vout: transaction.vout
|
||||||
}));
|
}]));
|
||||||
|
|
||||||
if (cpfpInfo && cpfpInfo.ancestors.length > 0) {
|
if (cpfpInfo?.[0]?.ancestors?.length) {
|
||||||
const { ancestors, effectiveFeePerVsize } = cpfpInfo;
|
const { ancestors, effectiveFeePerVsize } = cpfpInfo[0];
|
||||||
transaction.effectiveFeePerVsize = effectiveFeePerVsize;
|
transaction.effectiveFeePerVsize = effectiveFeePerVsize;
|
||||||
this.cpfpInfo = { ancestors, effectiveFeePerVsize };
|
this.cpfpInfo = { ancestors, effectiveFeePerVsize };
|
||||||
this.hasCpfp = true;
|
this.hasCpfp = true;
|
||||||
|
@ -569,8 +569,8 @@ export class ApiService {
|
|||||||
return this.httpClient.post(this.apiBaseUrl + this.apiBasePath + '/api/v1/prevouts', outpoints);
|
return this.httpClient.post(this.apiBaseUrl + this.apiBasePath + '/api/v1/prevouts', outpoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCpfpLocalTx$(tx: any): Observable<CpfpInfo> {
|
getCpfpLocalTx$(tx: any[]): Observable<CpfpInfo[]> {
|
||||||
return this.httpClient.post<CpfpInfo>(this.apiBaseUrl + this.apiBasePath + '/api/v1/cpfp', tx);
|
return this.httpClient.post<CpfpInfo[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/cpfp', tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache methods
|
// Cache methods
|
||||||
|
Loading…
x
Reference in New Issue
Block a user