From 962c024ecb5e7fe3c55d73d66ab76ed27a0b53d9 Mon Sep 17 00:00:00 2001 From: softsimon Date: Mon, 19 Oct 2020 18:36:29 +0700 Subject: [PATCH] Use default configs. refs #141 --- backend/mempool-config.sample.json | 12 +++--- backend/src/config.ts | 69 ++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 421e04652..e22afbe41 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -8,12 +8,12 @@ "WEBSOCKET_REFRESH_RATE_MS": 2000 }, "ELECTRS": { - "REST_API_URL": "http://localhost:50001", + "REST_API_URL": "http://127.0.0.1:3000", "POLL_RATE_MS": 2000 }, "DATABASE": { "ENABLED": true, - "HOST": "localhost", + "HOST": "127.0.0.1", "PORT": 3306, "DATABASE": "mempool", "USERNAME": "mempool", @@ -24,18 +24,18 @@ "TX_PER_SECOND_SAMPLE_PERIOD": 150 }, "BISQ_BLOCKS": { - "ENABLED": true, + "ENABLED": false, "DATA_PATH": "/bisq/statsnode-data/btc_mainnet/db/json" }, "BISQ_MARKETS": { - "ENABLED": true, + "ENABLED": false, "DATA_PATH": "/bisq/statsnode-data/btc_mainnet/db" }, "SPONSORS": { - "ENABLED": true, + "ENABLED": false, "BTCPAY_URL": "", "BTCPAY_AUTH": "", "BTCPAY_WEBHOOK_URL": "", "TWITTER_BEARER_AUTH": "" - } + } } diff --git a/backend/src/config.ts b/backend/src/config.ts index 4451d9094..2452e10f8 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -1,6 +1,6 @@ const configFile = require('../mempool-config.json'); -export interface IConfig { +interface IConfig { MEMPOOL: { NETWORK: 'mainnet' | 'testnet' | 'liquid'; HTTP_PORT: number; @@ -42,6 +42,48 @@ export interface IConfig { }; } +const defaults: IConfig = { + 'MEMPOOL': { + 'NETWORK': 'mainnet', + 'HTTP_PORT': 8999, + 'MINED_BLOCKS_CACHE': 144, + 'SPAWN_CLUSTER_PROCS': 0, + 'API_URL_PREFIX': '/api/v1/', + 'WEBSOCKET_REFRESH_RATE_MS': 2000 + }, + 'ELECTRS': { + 'REST_API_URL': 'http://127.0.0.1:3000', + 'POLL_RATE_MS': 2000 + }, + 'DATABASE': { + 'ENABLED': true, + 'HOST': 'localhost', + 'PORT': 3306, + 'DATABASE': 'mempool', + 'USERNAME': 'mempool', + 'PASSWORD': 'mempool' + }, + 'STATISTICS': { + 'ENABLED': true, + 'TX_PER_SECOND_SAMPLE_PERIOD': 150 + }, + 'BISQ_BLOCKS': { + 'ENABLED': false, + 'DATA_PATH': '/bisq/statsnode-data/btc_mainnet/db/json' + }, + 'BISQ_MARKETS': { + 'ENABLED': false, + 'DATA_PATH': '/bisq/statsnode-data/btc_mainnet/db' + }, + 'SPONSORS': { + 'ENABLED': false, + 'BTCPAY_URL': '', + 'BTCPAY_AUTH': '', + 'BTCPAY_WEBHOOK_URL': '', + 'TWITTER_BEARER_AUTH': '' + } +}; + class Config implements IConfig { MEMPOOL: IConfig['MEMPOOL']; ELECTRS: IConfig['ELECTRS']; @@ -52,13 +94,24 @@ class Config implements IConfig { SPONSORS: IConfig['SPONSORS']; constructor() { - this.MEMPOOL = configFile.MEMPOOL; - this.ELECTRS = configFile.ELECTRS; - this.DATABASE = configFile.DATABASE; - this.STATISTICS = configFile.STATISTICS; - this.BISQ_BLOCKS = configFile.BISQ_BLOCKS; - this.BISQ_MARKETS = configFile.BISQ_MARKETS; - this.SPONSORS = configFile.SPONSORS; + const configs = this.merge(configFile, defaults); + this.MEMPOOL = configs.MEMPOOL; + this.ELECTRS = configs.ELECTRS; + this.DATABASE = configs.DATABASE; + this.STATISTICS = configs.STATISTICS; + this.BISQ_BLOCKS = configs.BISQ_BLOCKS; + this.BISQ_MARKETS = configs.BISQ_MARKETS; + this.SPONSORS = configs.SPONSORS; + } + + merge = (...objects: object[]): IConfig => { + // @ts-ignore + return objects.reduce((prev, next) => { + Object.keys(prev).forEach(key => { + next[key] = { ...next[key], ...prev[key] }; + }); + return next; + }); } }