Merge pull request #4848 from mempool/mononaut/esplora-only-address-graph

Add backend type flag, disable address graphs for non-esplora
This commit is contained in:
softsimon 2024-04-01 19:11:54 +09:00 committed by GitHub
commit ecf1db0716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 15 additions and 2 deletions

View file

@ -83,6 +83,7 @@ class WebsocketHandler {
const _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT); const _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT);
const da = difficultyAdjustment.getDifficultyAdjustment(); const da = difficultyAdjustment.getDifficultyAdjustment();
this.updateSocketDataFields({ this.updateSocketDataFields({
'backend': config.MEMPOOL.BACKEND,
'mempoolInfo': memPool.getMempoolInfo(), 'mempoolInfo': memPool.getMempoolInfo(),
'vBytesPerSecond': memPool.getVBytesPerSecond(), 'vBytesPerSecond': memPool.getVBytesPerSecond(),
'blocks': _blocks, 'blocks': _blocks,

View file

@ -51,7 +51,7 @@
</div> </div>
</div> </div>
<ng-container *ngIf="address && transactions && transactions.length > 2"> <ng-container *ngIf="(stateService.backend$ | async) === 'esplora' && address && transactions && transactions.length > 2">
<br> <br>
<div class="box"> <div class="box">
<div class="row"> <div class="row">

View file

@ -44,7 +44,7 @@ export class AddressComponent implements OnInit, OnDestroy {
private route: ActivatedRoute, private route: ActivatedRoute,
private electrsApiService: ElectrsApiService, private electrsApiService: ElectrsApiService,
private websocketService: WebsocketService, private websocketService: WebsocketService,
private stateService: StateService, public stateService: StateService,
private audioService: AudioService, private audioService: AudioService,
private apiService: ApiService, private apiService: ApiService,
private seoService: SeoService, private seoService: SeoService,

View file

@ -4,6 +4,7 @@ import { Transaction } from './electrs.interface';
import { BlockExtended, DifficultyAdjustment, RbfTree } from './node-api.interface'; import { BlockExtended, DifficultyAdjustment, RbfTree } from './node-api.interface';
export interface WebsocketResponse { export interface WebsocketResponse {
backend?: 'esplora' | 'electrum' | 'none';
block?: BlockExtended; block?: BlockExtended;
blocks?: BlockExtended[]; blocks?: BlockExtended[];
conversions?: any; conversions?: any;

View file

@ -92,6 +92,7 @@ const defaultEnv: Env = {
export class StateService { export class StateService {
isBrowser: boolean = isPlatformBrowser(this.platformId); isBrowser: boolean = isPlatformBrowser(this.platformId);
isMempoolSpaceBuild = window['isMempoolSpaceBuild'] ?? false; isMempoolSpaceBuild = window['isMempoolSpaceBuild'] ?? false;
backend: 'esplora' | 'electrum' | 'none' = 'esplora';
network = ''; network = '';
lightning = false; lightning = false;
blockVSize: number; blockVSize: number;
@ -99,6 +100,7 @@ export class StateService {
latestBlockHeight = -1; latestBlockHeight = -1;
blocks: BlockExtended[] = []; blocks: BlockExtended[] = [];
backend$ = new BehaviorSubject<'esplora' | 'electrum' | 'none'>('esplora');
networkChanged$ = new ReplaySubject<string>(1); networkChanged$ = new ReplaySubject<string>(1);
lightningChanged$ = new ReplaySubject<boolean>(1); lightningChanged$ = new ReplaySubject<boolean>(1);
blocksSubject$ = new BehaviorSubject<BlockExtended[]>([]); blocksSubject$ = new BehaviorSubject<BlockExtended[]>([]);
@ -257,6 +259,10 @@ export class StateService {
const rateUnitPreference = this.storageService.getValue('rate-unit-preference'); const rateUnitPreference = this.storageService.getValue('rate-unit-preference');
this.rateUnits$ = new BehaviorSubject<string>(rateUnitPreference || 'vb'); this.rateUnits$ = new BehaviorSubject<string>(rateUnitPreference || 'vb');
this.backend$.subscribe(backend => {
this.backend = backend;
});
} }
setNetworkBasedonUrl(url: string) { setNetworkBasedonUrl(url: string) {

View file

@ -62,6 +62,7 @@ export class WebsocketService {
if (theInitData.body.blocks) { if (theInitData.body.blocks) {
theInitData.body.blocks = theInitData.body.blocks.reverse(); theInitData.body.blocks = theInitData.body.blocks.reverse();
} }
this.stateService.backend$.next(theInitData.backend);
this.stateService.isLoadingWebSocket$.next(false); this.stateService.isLoadingWebSocket$.next(false);
this.handleResponse(theInitData.body); this.handleResponse(theInitData.body);
this.startSubscription(false, true); this.startSubscription(false, true);
@ -290,6 +291,10 @@ export class WebsocketService {
handleResponse(response: WebsocketResponse) { handleResponse(response: WebsocketResponse) {
let reinitBlocks = false; let reinitBlocks = false;
if (response.backend) {
this.stateService.backend$.next(response.backend);
}
if (response.blocks && response.blocks.length) { if (response.blocks && response.blocks.length) {
const blocks = response.blocks; const blocks = response.blocks;
this.stateService.resetBlocks(blocks); this.stateService.resetBlocks(blocks);