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/:to', this.getBlocksByBulk.bind(this)) | ||||
|       .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
 | ||||
|       .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 { | ||||
|       const tx = req.body; | ||||
|       const transactions = req.body; | ||||
| 
 | ||||
|       if ( | ||||
|       if (!Array.isArray(transactions) || transactions.some(tx => | ||||
|         !tx || typeof tx !== 'object' || | ||||
|         !tx.txid || typeof tx.txid !== 'string' || | ||||
|         !/^[a-fA-F0-9]{64}$/.test(tx.txid) || | ||||
|         typeof tx.weight !== 'number' || | ||||
|         typeof tx.sigops !== 'number' || | ||||
|         typeof tx.fee !== 'number' || | ||||
|         !Array.isArray(tx.vin) || | ||||
|         !Array.isArray(tx.vout) | ||||
|       ) { | ||||
|         handleError(req, res, 400, 'Invalid transaction format'); | ||||
|       )) { | ||||
|         handleError(req, res, 400, 'Invalid transactions format'); | ||||
|         return; | ||||
|       } | ||||
| 
 | ||||
|       const cpfpInfo = calculateLocalTxCpfp(tx, mempool.getMempool()); | ||||
|       res.json(cpfpInfo); | ||||
|       if (transactions.length > 1) { | ||||
|         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) { | ||||
|       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 | ||||
|  * 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) { | ||||
|       try { | ||||
|         this.isLoadingCpfpInfo = true; | ||||
|         const cpfpInfo: CpfpInfo = await firstValueFrom(this.apiService.getCpfpLocalTx$({ | ||||
|         const cpfpInfo: CpfpInfo[] = await firstValueFrom(this.apiService.getCpfpLocalTx$([{ | ||||
|           txid: transaction.txid, | ||||
|           weight: transaction.weight, | ||||
|           sigops: transaction.sigops, | ||||
|           fee: transaction.fee, | ||||
|           vin: transaction.vin, | ||||
|           vout: transaction.vout | ||||
|         })); | ||||
|         }])); | ||||
| 
 | ||||
|         if (cpfpInfo && cpfpInfo.ancestors.length > 0) { | ||||
|           const { ancestors, effectiveFeePerVsize } = cpfpInfo; | ||||
|         if (cpfpInfo?.[0]?.ancestors?.length) { | ||||
|           const { ancestors, effectiveFeePerVsize } = cpfpInfo[0]; | ||||
|           transaction.effectiveFeePerVsize = effectiveFeePerVsize; | ||||
|           this.cpfpInfo = { ancestors, effectiveFeePerVsize }; | ||||
|           this.hasCpfp = true; | ||||
|  | ||||
| @ -569,8 +569,8 @@ export class ApiService { | ||||
|     return this.httpClient.post(this.apiBaseUrl + this.apiBasePath + '/api/v1/prevouts', outpoints); | ||||
|   } | ||||
| 
 | ||||
|   getCpfpLocalTx$(tx: any): Observable<CpfpInfo> { | ||||
|     return this.httpClient.post<CpfpInfo>(this.apiBaseUrl + this.apiBasePath + '/api/v1/cpfp', tx); | ||||
|   getCpfpLocalTx$(tx: any[]): Observable<CpfpInfo[]> { | ||||
|     return this.httpClient.post<CpfpInfo[]>(this.apiBaseUrl + this.apiBasePath + '/api/v1/cpfp', tx); | ||||
|   } | ||||
| 
 | ||||
|   // Cache methods
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user