Renamed the electrs backend support to 'electrs'.

This commit is contained in:
Simon Lindh 2019-12-06 22:37:07 +01:00
parent aa8bccdb8f
commit d1fce86adb
18 changed files with 40 additions and 40 deletions

View File

@ -20,6 +20,6 @@
"BITCOIN_NODE_USER": "", "BITCOIN_NODE_USER": "",
"BITCOIN_NODE_PASS": "", "BITCOIN_NODE_PASS": "",
"BACKEND_API": "bitcoind", "BACKEND_API": "bitcoind",
"ESPLORA_API_URL": "https://www.blockstream.info/api", "ELECTRS_API_URL": "https://www.blockstream.info/api",
"TX_PER_SECOND_SPAN_SECONDS": 150 "TX_PER_SECOND_SPAN_SECONDS": 150
} }

View File

@ -1,12 +1,12 @@
const config = require('../../../mempool-config.json'); const config = require('../../../mempool-config.json');
import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory'; import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory';
import BitcoindApi from './bitcoind-api'; import BitcoindApi from './bitcoind-api';
import EsploraApi from './esplora-api'; import ElectrsApi from './electrs-api';
function factory(): AbstractBitcoinApi { function factory(): AbstractBitcoinApi {
switch (config.BACKEND_API) { switch (config.BACKEND_API) {
case 'esplora': case 'electrs':
return new EsploraApi(); return new ElectrsApi();
case 'bitcoind': case 'bitcoind':
default: default:
return new BitcoindApi(); return new BitcoindApi();

View File

@ -3,14 +3,14 @@ import { ITransaction, IMempoolInfo, IBlock } from '../../interfaces';
import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory'; import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory';
import * as request from 'request'; import * as request from 'request';
class EsploraApi implements AbstractBitcoinApi { class ElectrsApi implements AbstractBitcoinApi {
constructor() { constructor() {
} }
getMempoolInfo(): Promise<IMempoolInfo> { getMempoolInfo(): Promise<IMempoolInfo> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/mempool', { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/mempool', { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -24,7 +24,7 @@ class EsploraApi implements AbstractBitcoinApi {
getRawMempool(): Promise<ITransaction['txid'][]> { getRawMempool(): Promise<ITransaction['txid'][]> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/mempool/txids', { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/mempool/txids', { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -35,7 +35,7 @@ class EsploraApi implements AbstractBitcoinApi {
getRawTransaction(txId: string): Promise<ITransaction> { getRawTransaction(txId: string): Promise<ITransaction> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/tx/' + txId, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/tx/' + txId, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -50,7 +50,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlockCount(): Promise<number> { getBlockCount(): Promise<number> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/blocks/tip/height', { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/blocks/tip/height', { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -61,11 +61,11 @@ class EsploraApi implements AbstractBitcoinApi {
getBlockAndTransactions(hash: string): Promise<IBlock> { getBlockAndTransactions(hash: string): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/block/' + hash, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/block/' + hash, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
request(config.ESPLORA_API_URL + '/block/' + hash + '/txids', { json: true }, (err2, res2, response2) => { request(config.ELECTRS_API_URL + '/block/' + hash + '/txids', { json: true }, (err2, res2, response2) => {
if (err2) { if (err2) {
reject(err2); reject(err2);
} }
@ -83,7 +83,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlockHash(height: number): Promise<string> { getBlockHash(height: number): Promise<string> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/block-height/' + height, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/block-height/' + height, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -94,7 +94,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlocks(): Promise<string> { getBlocks(): Promise<string> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/blocks', { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/blocks', { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -105,7 +105,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlocksFromHeight(height: number): Promise<string> { getBlocksFromHeight(height: number): Promise<string> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/blocks/' + height, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/blocks/' + height, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -116,7 +116,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlock(hash: string): Promise<IBlock> { getBlock(hash: string): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/block/' + hash, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/block/' + hash, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -127,7 +127,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlockTransactions(hash: string): Promise<IBlock> { getBlockTransactions(hash: string): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/block/' + hash + '/txs', { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/block/' + hash + '/txs', { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -138,7 +138,7 @@ class EsploraApi implements AbstractBitcoinApi {
getBlockTransactionsFromIndex(hash: string, index: number): Promise<IBlock> { getBlockTransactionsFromIndex(hash: string, index: number): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/block/' + hash + '/txs/' + index, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/block/' + hash + '/txs/' + index, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -149,7 +149,7 @@ class EsploraApi implements AbstractBitcoinApi {
getAddress(address: string): Promise<IBlock> { getAddress(address: string): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/address/' + address, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/address/' + address, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -160,7 +160,7 @@ class EsploraApi implements AbstractBitcoinApi {
getAddressTransactions(address: string): Promise<IBlock> { getAddressTransactions(address: string): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/address/' + address + '/txs', { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/address/' + address + '/txs', { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -171,7 +171,7 @@ class EsploraApi implements AbstractBitcoinApi {
getAddressTransactionsFromLastSeenTxid(address: string, lastSeenTxid: string): Promise<IBlock> { getAddressTransactionsFromLastSeenTxid(address: string, lastSeenTxid: string): Promise<IBlock> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
request(config.ESPLORA_API_URL + '/address/' + address + '/txs/chain/' + lastSeenTxid, { json: true }, (err, res, response) => { request(config.ELECTRS_API_URL + '/address/' + address + '/txs/chain/' + lastSeenTxid, { json: true }, (err, res, response) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -181,4 +181,4 @@ class EsploraApi implements AbstractBitcoinApi {
} }
} }
export default EsploraApi; export default ElectrsApi;

View File

@ -56,7 +56,7 @@ class Mempool {
let totalOut = 0; let totalOut = 0;
transaction.vout.forEach((output) => totalOut += output.value); transaction.vout.forEach((output) => totalOut += output.value);
if (config.BACKEND_API === 'esplora') { if (config.BACKEND_API === 'electrs') {
transaction.feePerWeightUnit = (transaction.fee * 100000000) / transaction.weight || 0; transaction.feePerWeightUnit = (transaction.fee * 100000000) / transaction.weight || 0;
transaction.feePerVsize = (transaction.fee * 100000000) / (transaction.vsize) || 0; transaction.feePerVsize = (transaction.fee * 100000000) / (transaction.vsize) || 0;
transaction.totalOut = totalOut / 100000000; transaction.totalOut = totalOut / 100000000;

View File

@ -264,7 +264,7 @@ class MempoolSpace {
.get(config.API_ENDPOINT + 'statistics/6m', routes.get6MStatistics.bind(routes)) .get(config.API_ENDPOINT + 'statistics/6m', routes.get6MStatistics.bind(routes))
; ;
if (config.BACKEND_API === 'esplora') { if (config.BACKEND_API === 'electrs') {
this.app this.app
.get(config.API_ENDPOINT + 'explorer/blocks', routes.getBlocks) .get(config.API_ENDPOINT + 'explorer/blocks', routes.getBlocks)
.get(config.API_ENDPOINT + 'explorer/blocks/:height', routes.getBlocks) .get(config.API_ENDPOINT + 'explorer/blocks/:height', routes.getBlocks)

View File

@ -49,11 +49,11 @@
"vendorChunk": false, "vendorChunk": false,
"buildOptimizer": true "buildOptimizer": true
}, },
"esplora": { "electrs": {
"fileReplacements": [ "fileReplacements": [
{ {
"replace": "src/environments/environment.ts", "replace": "src/environments/environment.ts",
"with": "src/environments/environment-esplora.prod.ts" "with": "src/environments/environment-electrs.prod.ts"
} }
], ],
"optimization": true, "optimization": true,

View File

@ -6,7 +6,7 @@
"ng": "ng", "ng": "ng",
"start": "ng serve --aot --proxy-config proxy.conf.json", "start": "ng serve --aot --proxy-config proxy.conf.json",
"build": "ng build --prod", "build": "ng build --prod",
"build-esplora": "ng build --prod --configuration=esplora", "build-electrs": "ng build --prod --configuration=electrs",
"test": "ng test", "test": "ng test",
"lint": "ng lint", "lint": "ng lint",
"e2e": "ng e2e" "e2e": "ng e2e"

View File

@ -1,7 +1,7 @@
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title">Fee distribution for block <h4 class="modal-title">Fee distribution for block
<a *ngIf="!isEsploraEnabled" href="https://www.blockstream.info/block-height/{{ block.height }}" target="_blank">#{{ block.height }}</a> <a *ngIf="!isElectrsEnabled" href="https://www.blockstream.info/block-height/{{ block.height }}" target="_blank">#{{ block.height }}</a>
<a *ngIf="isEsploraEnabled" (click)="activeModal.dismiss()" [routerLink]="['/explorer/block/', block.hash]">#{{ block.height }}</a> <a *ngIf="isElectrsEnabled" (click)="activeModal.dismiss()" [routerLink]="['/explorer/block/', block.hash]">#{{ block.height }}</a>
</h4> </h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')"> <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>

View File

@ -12,7 +12,7 @@ import { environment } from '../../../environments/environment';
export class BlockModalComponent implements OnInit { export class BlockModalComponent implements OnInit {
@Input() block: IBlock; @Input() block: IBlock;
blockSubsidy = 50; blockSubsidy = 50;
isEsploraEnabled = !!environment.esplora; isElectrsEnabled = !!environment.electrs;
conversions: any; conversions: any;
constructor( constructor(

View File

@ -2,8 +2,8 @@
<div *ngFor="let block of blocks; let i = index; trackBy: trackByBlocksFn" > <div *ngFor="let block of blocks; let i = index; trackBy: trackByBlocksFn" >
<div (click)="openBlockModal(block);" class="text-center bitcoin-block mined-block" id="bitcoin-block-{{ block.height }}" [ngStyle]="getStyleForBlock(block)"> <div (click)="openBlockModal(block);" class="text-center bitcoin-block mined-block" id="bitcoin-block-{{ block.height }}" [ngStyle]="getStyleForBlock(block)">
<div class="block-height"> <div class="block-height">
<a *ngIf="!isEsploraEnabled" href="https://www.blockstream.info/block-height/{{ block.height }}" target="_blank">#{{ block.height }}</a> <a *ngIf="!isElectrsEnabled" href="https://www.blockstream.info/block-height/{{ block.height }}" target="_blank">#{{ block.height }}</a>
<a *ngIf="isEsploraEnabled" [routerLink]="['/explorer/block/', block.hash]">#{{ block.height }}</a> <a *ngIf="isElectrsEnabled" [routerLink]="['/explorer/block/', block.hash]">#{{ block.height }}</a>
</div> </div>
<div class="block-body"> <div class="block-body">
<div class="fees"> <div class="fees">

View File

@ -16,7 +16,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
blocksSubscription: Subscription; blocksSubscription: Subscription;
interval: any; interval: any;
trigger = 0; trigger = 0;
isEsploraEnabled = !!environment.esplora; isElectrsEnabled = !!environment.electrs;
constructor( constructor(
private modalService: NgbModal, private modalService: NgbModal,

View File

@ -18,7 +18,7 @@
<li class="nav-item" routerLinkActive="active"> <li class="nav-item" routerLinkActive="active">
<a class="nav-link" routerLink="/tv" (click)="collapse()">TV view &nbsp;<img src="./assets/expand.png" width="15"/></a> <a class="nav-link" routerLink="/tv" (click)="collapse()">TV view &nbsp;<img src="./assets/expand.png" width="15"/></a>
</li> </li>
<li class="nav-item" routerLinkActive="active" *ngIf="isEsploraEnabled"> <li class="nav-item" routerLinkActive="active" *ngIf="isElectrsEnabled">
<a class="nav-link" routerLink="/explorer" (click)="collapse()">Explorer</a> <a class="nav-link" routerLink="/explorer" (click)="collapse()">Explorer</a>
</li> </li>
<li class="nav-item" routerLinkActive="active"> <li class="nav-item" routerLinkActive="active">

View File

@ -13,7 +13,7 @@ export class MasterPageComponent implements OnInit {
navCollapsed = false; navCollapsed = false;
isOffline = false; isOffline = false;
searchForm: FormGroup; searchForm: FormGroup;
isEsploraEnabled = !!environment.esplora; isElectrsEnabled = !!environment.electrs;
currentBaseRoot = ''; currentBaseRoot = '';
regexAddr = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,87})$/; regexAddr = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,87})$/;

View File

@ -4,8 +4,8 @@
<tr> <tr>
<td class="text-left"><b>Transaction hash</b></td> <td class="text-left"><b>Transaction hash</b></td>
<td class="text-right"> <td class="text-right">
<a *ngIf="!isEsploraEnabled" href="https://www.blockstream.info/tx/{{ tx?.txid }}" target="_blank">{{ tx?.txid | shortenString }}</a> <a *ngIf="!isElectrsEnabled" href="https://www.blockstream.info/tx/{{ tx?.txid }}" target="_blank">{{ tx?.txid | shortenString }}</a>
<a *ngIf="isEsploraEnabled" [routerLink]="['/explorer/tx/', tx?.txid]">{{ tx?.txid | shortenString }}</a> <a *ngIf="isElectrsEnabled" [routerLink]="['/explorer/tx/', tx?.txid]">{{ tx?.txid | shortenString }}</a>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -36,7 +36,7 @@ export class TxBubbleComponent implements OnInit, OnDestroy {
txTrackingTx: ITransaction | null = null; txTrackingTx: ITransaction | null = null;
txShowTxNotFound = false; txShowTxNotFound = false;
isEsploraEnabled = !!environment.esplora; isElectrsEnabled = !!environment.electrs;
@HostListener('window:resize', ['$event']) @HostListener('window:resize', ['$event'])
onResize(event: Event) { onResize(event: Event) {

View File

@ -1,4 +1,4 @@
export const environment = { export const environment = {
production: true, production: true,
esplora: true, electrs: true,
}; };

View File

@ -1,4 +1,4 @@
export const environment = { export const environment = {
production: true, production: true,
esplora: false, electrs: false,
}; };

View File

@ -4,7 +4,7 @@
export const environment = { export const environment = {
production: false, production: false,
esplora: true, electrs: true,
}; };
/* /*