Fix unnecessary cpfp 404 responses

This commit is contained in:
Mononaut 2023-03-06 00:02:21 -06:00
parent 5a09e3099c
commit 182cb16695
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
6 changed files with 33 additions and 14 deletions

View File

@ -220,19 +220,18 @@ class BitcoinRoutes {
let cpfpInfo; let cpfpInfo;
if (config.DATABASE.ENABLED) { if (config.DATABASE.ENABLED) {
cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId); cpfpInfo = await transactionRepository.$getCpfpInfo(req.params.txId);
}
if (cpfpInfo) {
res.json(cpfpInfo);
return;
} else { } else {
res.json({ res.json({
ancestors: [] ancestors: []
}); });
return; return;
} }
if (cpfpInfo) {
res.json(cpfpInfo);
return;
} }
} }
res.status(404).send(`Transaction has no CPFP info available.`);
}
private getBackendInfo(req: Request, res: Response) { private getBackendInfo(req: Request, res: Response) {
res.json(backendInfo.getBackendInfo()); res.json(backendInfo.getBackendInfo());
@ -652,7 +651,7 @@ class BitcoinRoutes {
if (result) { if (result) {
res.json(result); res.json(result);
} else { } else {
res.status(404).send('not found'); res.status(204).send();
} }
} catch (e) { } catch (e) {
res.status(500).send(e instanceof Error ? e.message : e); res.status(500).send(e instanceof Error ? e.message : e);

View File

@ -263,7 +263,7 @@ class MiningRoutes {
const audit = await BlocksAuditsRepository.$getBlockAudit(req.params.hash); const audit = await BlocksAuditsRepository.$getBlockAudit(req.params.hash);
if (!audit) { if (!audit) {
res.status(404).send(`This block has not been audited.`); res.status(204).send(`This block has not been audited.`);
return; return;
} }

View File

@ -210,6 +210,7 @@
<div class="graph-container" #graphContainer> <div class="graph-container" #graphContainer>
<tx-bowtie-graph <tx-bowtie-graph
[tx]="tx" [tx]="tx"
[cached]="isCached"
[width]="graphWidth" [width]="graphWidth"
[height]="graphHeight" [height]="graphHeight"
[lineLimit]="inOutLimit" [lineLimit]="inOutLimit"
@ -250,7 +251,7 @@
</div> </div>
<app-transactions-list #txList [transactions]="[tx]" [errorUnblinded]="errorUnblinded" [inputIndex]="inputIndex" [outputIndex]="outputIndex" [transactionPage]="true"></app-transactions-list> <app-transactions-list #txList [transactions]="[tx]" [cached]="isCached" [errorUnblinded]="errorUnblinded" [inputIndex]="inputIndex" [outputIndex]="outputIndex" [transactionPage]="true"></app-transactions-list>
<div class="title text-left"> <div class="title text-left">
<h2 i18n="transaction.details">Details</h2> <h2 i18n="transaction.details">Details</h2>

View File

@ -57,6 +57,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
fetchCpfp$ = new Subject<string>(); fetchCpfp$ = new Subject<string>();
fetchRbfHistory$ = new Subject<string>(); fetchRbfHistory$ = new Subject<string>();
fetchCachedTx$ = new Subject<string>(); fetchCachedTx$ = new Subject<string>();
isCached: boolean = false;
now = new Date().getTime(); now = new Date().getTime();
timeAvg$: Observable<number>; timeAvg$: Observable<number>;
liquidUnblinding = new LiquidUnblinding(); liquidUnblinding = new LiquidUnblinding();
@ -196,6 +197,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
} }
this.tx = tx; this.tx = tx;
this.isCached = true;
if (tx.fee === undefined) { if (tx.fee === undefined) {
this.tx.fee = 0; this.tx.fee = 0;
} }
@ -289,6 +291,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy {
} }
this.tx = tx; this.tx = tx;
this.isCached = false;
if (tx.fee === undefined) { if (tx.fee === undefined) {
this.tx.fee = 0; this.tx.fee = 0;
} }

View File

@ -1,7 +1,7 @@
import { Component, OnInit, Input, ChangeDetectionStrategy, OnChanges, Output, EventEmitter, ChangeDetectorRef } from '@angular/core'; import { Component, OnInit, Input, ChangeDetectionStrategy, OnChanges, Output, EventEmitter, ChangeDetectorRef } from '@angular/core';
import { StateService } from '../../services/state.service'; import { StateService } from '../../services/state.service';
import { CacheService } from '../../services/cache.service'; import { CacheService } from '../../services/cache.service';
import { Observable, ReplaySubject, BehaviorSubject, merge, Subscription } from 'rxjs'; import { Observable, ReplaySubject, BehaviorSubject, merge, Subscription, of } from 'rxjs';
import { Outspend, Transaction, Vin, Vout } from '../../interfaces/electrs.interface'; import { Outspend, Transaction, Vin, Vout } from '../../interfaces/electrs.interface';
import { ElectrsApiService } from '../../services/electrs-api.service'; import { ElectrsApiService } from '../../services/electrs-api.service';
import { environment } from '../../../environments/environment'; import { environment } from '../../../environments/environment';
@ -23,6 +23,7 @@ export class TransactionsListComponent implements OnInit, OnChanges {
showMoreIncrement = 1000; showMoreIncrement = 1000;
@Input() transactions: Transaction[]; @Input() transactions: Transaction[];
@Input() cached: boolean = false;
@Input() showConfirmations = false; @Input() showConfirmations = false;
@Input() transactionPage = false; @Input() transactionPage = false;
@Input() errorUnblinded = false; @Input() errorUnblinded = false;
@ -67,7 +68,13 @@ export class TransactionsListComponent implements OnInit, OnChanges {
this.outspendsSubscription = merge( this.outspendsSubscription = merge(
this.refreshOutspends$ this.refreshOutspends$
.pipe( .pipe(
switchMap((txIds) => this.apiService.getOutspendsBatched$(txIds)), switchMap((txIds) => {
if (!this.cached) {
return this.apiService.getOutspendsBatched$(txIds);
} else {
return of([]);
}
}),
tap((outspends: Outspend[][]) => { tap((outspends: Outspend[][]) => {
if (!this.transactions) { if (!this.transactions) {
return; return;
@ -155,7 +162,7 @@ export class TransactionsListComponent implements OnInit, OnChanges {
).subscribe(); ).subscribe();
}); });
const txIds = this.transactions.filter((tx) => !tx._outspends).map((tx) => tx.txid); const txIds = this.transactions.filter((tx) => !tx._outspends).map((tx) => tx.txid);
if (txIds.length) { if (txIds.length && !this.cached) {
this.refreshOutspends$.next(txIds); this.refreshOutspends$.next(txIds);
} }
if (this.stateService.env.LIGHTNING) { if (this.stateService.env.LIGHTNING) {

View File

@ -2,7 +2,7 @@ import { Component, OnInit, Input, OnChanges, HostListener, Inject, LOCALE_ID }
import { StateService } from '../../services/state.service'; import { StateService } from '../../services/state.service';
import { Outspend, Transaction } from '../../interfaces/electrs.interface'; import { Outspend, Transaction } from '../../interfaces/electrs.interface';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ReplaySubject, merge, Subscription } from 'rxjs'; import { ReplaySubject, merge, Subscription, of } from 'rxjs';
import { tap, switchMap } from 'rxjs/operators'; import { tap, switchMap } from 'rxjs/operators';
import { ApiService } from '../../services/api.service'; import { ApiService } from '../../services/api.service';
import { RelativeUrlPipe } from '../../shared/pipes/relative-url/relative-url.pipe'; import { RelativeUrlPipe } from '../../shared/pipes/relative-url/relative-url.pipe';
@ -40,6 +40,7 @@ interface Xput {
export class TxBowtieGraphComponent implements OnInit, OnChanges { export class TxBowtieGraphComponent implements OnInit, OnChanges {
@Input() tx: Transaction; @Input() tx: Transaction;
@Input() network: string; @Input() network: string;
@Input() cached: boolean = false;
@Input() width = 1200; @Input() width = 1200;
@Input() height = 600; @Input() height = 600;
@Input() lineLimit = 250; @Input() lineLimit = 250;
@ -107,7 +108,13 @@ export class TxBowtieGraphComponent implements OnInit, OnChanges {
this.outspendsSubscription = merge( this.outspendsSubscription = merge(
this.refreshOutspends$ this.refreshOutspends$
.pipe( .pipe(
switchMap((txid) => this.apiService.getOutspendsBatched$([txid])), switchMap((txid) => {
if (!this.cached) {
return this.apiService.getOutspendsBatched$([txid]);
} else {
return of(null);
}
}),
tap((outspends: Outspend[][]) => { tap((outspends: Outspend[][]) => {
if (!this.tx || !outspends || !outspends.length) { if (!this.tx || !outspends || !outspends.length) {
return; return;
@ -132,8 +139,10 @@ export class TxBowtieGraphComponent implements OnInit, OnChanges {
ngOnChanges(): void { ngOnChanges(): void {
this.initGraph(); this.initGraph();
if (!this.cached) {
this.refreshOutspends$.next(this.tx.txid); this.refreshOutspends$.next(this.tx.txid);
} }
}
initGraph(): void { initGraph(): void {
this.isLiquid = (this.network === 'liquid' || this.network === 'liquidtestnet'); this.isLiquid = (this.network === 'liquid' || this.network === 'liquidtestnet');