mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 14:40:38 +01:00
stratum backend config
This commit is contained in:
parent
4ecf2eb679
commit
eddd7344ad
5 changed files with 27 additions and 2 deletions
|
@ -151,5 +151,9 @@
|
|||
"ENABLED": true,
|
||||
"PAID": false,
|
||||
"API_KEY": "__MEMPOOL_CURRENCY_API_KEY__"
|
||||
},
|
||||
"STRATUM": {
|
||||
"ENABLED": false,
|
||||
"API": "http://127.0.0.1:1234"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,11 @@ describe('Mempool Backend Config', () => {
|
|||
PAID: false,
|
||||
API_KEY: '',
|
||||
});
|
||||
|
||||
expect(config.STRATUM).toStrictEqual({
|
||||
ENABLED: false,
|
||||
API: 'http://127.0.0.1:1234',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { WebSocket } from 'ws';
|
||||
import logger from '../../logger';
|
||||
import config from '../../config';
|
||||
import websocketHandler from '../websocket-handler';
|
||||
|
||||
export interface StratumJob {
|
||||
|
@ -58,6 +59,9 @@ class StratumApi {
|
|||
}
|
||||
|
||||
public async connectWebsocket(): Promise<void> {
|
||||
if (!config.STRATUM.ENABLED) {
|
||||
return;
|
||||
}
|
||||
this.runWebsocketLoop = true;
|
||||
if (this.startedWebsocketLoop) {
|
||||
return;
|
||||
|
@ -65,7 +69,7 @@ class StratumApi {
|
|||
while (this.runWebsocketLoop) {
|
||||
this.startedWebsocketLoop = true;
|
||||
if (!this.ws) {
|
||||
this.ws = new WebSocket(`http://localhost:3333`);
|
||||
this.ws = new WebSocket(`${config.STRATUM.API}`);
|
||||
this.websocketConnected = true;
|
||||
|
||||
this.ws.on('open', () => {
|
||||
|
|
|
@ -165,6 +165,10 @@ interface IConfig {
|
|||
WALLETS: {
|
||||
ENABLED: boolean;
|
||||
WALLETS: string[];
|
||||
},
|
||||
STRATUM: {
|
||||
ENABLED: boolean;
|
||||
API: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,6 +336,10 @@ const defaults: IConfig = {
|
|||
'ENABLED': false,
|
||||
'WALLETS': [],
|
||||
},
|
||||
'STRATUM': {
|
||||
'ENABLED': false,
|
||||
'API': 'http://127.0.0.1:1234',
|
||||
}
|
||||
};
|
||||
|
||||
class Config implements IConfig {
|
||||
|
@ -354,6 +362,7 @@ class Config implements IConfig {
|
|||
REDIS: IConfig['REDIS'];
|
||||
FIAT_PRICE: IConfig['FIAT_PRICE'];
|
||||
WALLETS: IConfig['WALLETS'];
|
||||
STRATUM: IConfig['STRATUM'];
|
||||
|
||||
constructor() {
|
||||
const configs = this.merge(configFromFile, defaults);
|
||||
|
@ -376,6 +385,7 @@ class Config implements IConfig {
|
|||
this.REDIS = configs.REDIS;
|
||||
this.FIAT_PRICE = configs.FIAT_PRICE;
|
||||
this.WALLETS = configs.WALLETS;
|
||||
this.STRATUM = configs.STRATUM;
|
||||
}
|
||||
|
||||
merge = (...objects: object[]): IConfig => {
|
||||
|
|
|
@ -321,7 +321,9 @@ class Server {
|
|||
loadingIndicators.setProgressChangedCallback(websocketHandler.handleLoadingChanged.bind(websocketHandler));
|
||||
|
||||
accelerationApi.connectWebsocket();
|
||||
stratumApi.connectWebsocket();
|
||||
if (config.STRATUM.ENABLED) {
|
||||
stratumApi.connectWebsocket();
|
||||
}
|
||||
}
|
||||
|
||||
setUpHttpApiRoutes(): void {
|
||||
|
|
Loading…
Add table
Reference in a new issue