Make the Currency Conversion Service URLs configurable and log when queried
This commit is contained in:
		
							parent
							
								
									e6a318d310
								
							
						
					
					
						commit
						78090a9676
					
				
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							@ -265,6 +265,20 @@ docker-compose overrides:
 | 
			
		||||
      SOCKS5PROXY_PASSWORD: ""
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
JSON:
 | 
			
		||||
```
 | 
			
		||||
  "PRICENODE": {
 | 
			
		||||
    "TOR_URL": "http://wizpriceje6q5tdrxkyiazsgu7irquiqjy2dptezqhrtu7l2qelqktid.onion/getAllMarketPrices",
 | 
			
		||||
    "CLEARNET_URL": "https://price.bisq.wiz.biz/getAllMarketPrices"
 | 
			
		||||
  }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
docker-compose overrides:
 | 
			
		||||
```
 | 
			
		||||
      PRICENODE_TOR_URL: ""
 | 
			
		||||
      PRICENODE_CLEARNET_URL: ""
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
# Manual Installation
 | 
			
		||||
 | 
			
		||||
The following instructions are for a manual installation on Linux or FreeBSD. The file and directory paths may need to be changed to match your OS.
 | 
			
		||||
 | 
			
		||||
@ -68,5 +68,9 @@
 | 
			
		||||
    "PORT": 9050,
 | 
			
		||||
    "USERNAME": "",
 | 
			
		||||
    "PASSWORD": ""
 | 
			
		||||
  },
 | 
			
		||||
  "PRICENODE": {
 | 
			
		||||
    "TOR_URL": "http://wizpriceje6q5tdrxkyiazsgu7irquiqjy2dptezqhrtu7l2qelqktid.onion/getAllMarketPrices",
 | 
			
		||||
    "CLEARNET_URL": "https://price.bisq.wiz.biz/getAllMarketPrices"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
import logger from '../logger';
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
import axios, { AxiosResponse } from 'axios';
 | 
			
		||||
import { IConversionRates } from '../mempool.interfaces';
 | 
			
		||||
import config from '../config';
 | 
			
		||||
import backendInfo from './backend-info';
 | 
			
		||||
@ -20,7 +20,9 @@ class FiatConversion {
 | 
			
		||||
  public startService() {
 | 
			
		||||
    logger.info('Starting currency rates service');
 | 
			
		||||
    if (config.SOCKS5PROXY.ENABLED) {
 | 
			
		||||
      logger.info('Currency rates service will be queried over the Tor network');
 | 
			
		||||
      logger.info(`Currency rates service will be queried over the Tor network using ${config.PRICENODE.TOR_URL}`);
 | 
			
		||||
    } else {
 | 
			
		||||
      logger.info(`Currency rates service will be queried over clearnet using ${config.PRICENODE.CLEARNET_URL}`);
 | 
			
		||||
    }
 | 
			
		||||
    setInterval(this.updateCurrency.bind(this), 1000 * config.MEMPOOL.PRICE_FEED_UPDATE_INTERVAL);
 | 
			
		||||
    this.updateCurrency();
 | 
			
		||||
@ -32,9 +34,10 @@ class FiatConversion {
 | 
			
		||||
 | 
			
		||||
  private async updateCurrency(): Promise<void> {
 | 
			
		||||
    const headers = { 'User-Agent': `mempool/v${backendInfo.getBackendInfo().version}` };
 | 
			
		||||
    let response;
 | 
			
		||||
    let fiatConversionUrl: string;
 | 
			
		||||
    let response: AxiosResponse;
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      let fiatConversionUrl = 'https://price.bisq.wiz.biz/getAllMarketPrices';
 | 
			
		||||
      if (config.SOCKS5PROXY.ENABLED) {
 | 
			
		||||
        let socksOptions: any = {
 | 
			
		||||
          agentOptions: {
 | 
			
		||||
@ -43,20 +46,30 @@ class FiatConversion {
 | 
			
		||||
          host: config.SOCKS5PROXY.HOST,
 | 
			
		||||
          port: config.SOCKS5PROXY.PORT
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        if (config.SOCKS5PROXY.USERNAME && config.SOCKS5PROXY.PASSWORD) {
 | 
			
		||||
          socksOptions.username = config.SOCKS5PROXY.USERNAME;
 | 
			
		||||
          socksOptions.password = config.SOCKS5PROXY.PASSWORD;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const agent = new SocksProxyAgent(socksOptions);
 | 
			
		||||
        fiatConversionUrl = 'http://wizpriceje6q5tdrxkyiazsgu7irquiqjy2dptezqhrtu7l2qelqktid.onion/getAllMarketPrices';
 | 
			
		||||
        fiatConversionUrl = config.PRICENODE.TOR_URL;
 | 
			
		||||
        logger.info('Querying currency rates service...');
 | 
			
		||||
        response = await axios.get(fiatConversionUrl, { httpAgent: agent, headers: headers, timeout: 30000 });
 | 
			
		||||
      } else {
 | 
			
		||||
        fiatConversionUrl = config.PRICENODE.CLEARNET_URL;
 | 
			
		||||
        logger.info('Querying currency rates service...');
 | 
			
		||||
        response = await axios.get(fiatConversionUrl, { headers: headers, timeout: 10000 });
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      const usd = response.data.data.find((item: any) => item.currencyCode === 'USD');
 | 
			
		||||
 | 
			
		||||
      this.conversionRates = {
 | 
			
		||||
        'USD': usd.price,
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      logger.info(`USD Conversion Rate: ${usd.price}`);
 | 
			
		||||
 | 
			
		||||
      if (this.ratesChangedCallback) {
 | 
			
		||||
        this.ratesChangedCallback(this.conversionRates);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -69,6 +69,10 @@ interface IConfig {
 | 
			
		||||
    USERNAME: string;
 | 
			
		||||
    PASSWORD: string;
 | 
			
		||||
  };
 | 
			
		||||
  PRICENODE: {
 | 
			
		||||
    TOR_URL: string;
 | 
			
		||||
    CLEARNET_URL: string;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const defaults: IConfig = {
 | 
			
		||||
@ -141,6 +145,10 @@ const defaults: IConfig = {
 | 
			
		||||
    'PORT': 9050,
 | 
			
		||||
    'USERNAME': '',
 | 
			
		||||
    'PASSWORD': ''
 | 
			
		||||
  },
 | 
			
		||||
  "PRICENODE": {
 | 
			
		||||
    'TOR_URL': 'http://wizpriceje6q5tdrxkyiazsgu7irquiqjy2dptezqhrtu7l2qelqktid.onion/getAllMarketPrices',
 | 
			
		||||
    'CLEARNET_URL': 'https://price.bisq.wiz.biz/getAllMarketPrices'
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -155,6 +163,7 @@ class Config implements IConfig {
 | 
			
		||||
  STATISTICS: IConfig['STATISTICS'];
 | 
			
		||||
  BISQ: IConfig['BISQ'];
 | 
			
		||||
  SOCKS5PROXY: IConfig['SOCKS5PROXY'];
 | 
			
		||||
  PRICENODE: IConfig['PRICENODE'];
 | 
			
		||||
 | 
			
		||||
  constructor() {
 | 
			
		||||
    const configs = this.merge(configFile, defaults);
 | 
			
		||||
@ -168,6 +177,7 @@ class Config implements IConfig {
 | 
			
		||||
    this.STATISTICS = configs.STATISTICS;
 | 
			
		||||
    this.BISQ = configs.BISQ;
 | 
			
		||||
    this.SOCKS5PROXY = configs.SOCKS5PROXY;
 | 
			
		||||
    this.PRICENODE = configs.PRICENODE;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  merge = (...objects: object[]): IConfig => {
 | 
			
		||||
 | 
			
		||||
@ -65,5 +65,9 @@
 | 
			
		||||
    "PORT": "__SOCKS5PROXY_PORT__",
 | 
			
		||||
    "USERNAME": "__SOCKS5PROXY_USERNAME__",
 | 
			
		||||
    "PASSWORD": "__SOCKS5PROXY_PASSWORD__"
 | 
			
		||||
  },
 | 
			
		||||
  "PRICENODE": {
 | 
			
		||||
    "TOR_URL": "__PRICENODE_TOR_URL__",
 | 
			
		||||
    "CLEARNET_URL": "__PRICENODE_CLEARNET_URL__"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -68,6 +68,10 @@ __SOCKS5PROXY_PORT__=${SOCKS5PROXY_PORT:=9050}
 | 
			
		||||
__SOCKS5PROXY_USERNAME__=${SOCKS5PROXY_USERNAME:=""}
 | 
			
		||||
__SOCKS5PROXY_PASSWORD__=${SOCKS5PROXY_PASSWORD:=""}
 | 
			
		||||
 | 
			
		||||
# PRICENODE
 | 
			
		||||
__PRICENODE_TOR_URL__=${PRICENODE_TOR_URL:=http://wizpriceje6q5tdrxkyiazsgu7irquiqjy2dptezqhrtu7l2qelqktid.onion/getAllMarketPrices}
 | 
			
		||||
__PRICENODE_CLEARNET_URL__=${PRICENODE_CLEARNET_URL:=https://price.bisq.wiz.biz/getAllMarketPrices}
 | 
			
		||||
 | 
			
		||||
mkdir -p "${__MEMPOOL_CACHE_DIR__}"
 | 
			
		||||
 | 
			
		||||
sed -i "s/__MEMPOOL_NETWORK__/${__MEMPOOL_NETWORK__}/g" mempool-config.json
 | 
			
		||||
@ -128,4 +132,7 @@ sed -i "s/__SOCKS5PROXY_PORT__/${__SOCKS5PROXY_PORT__}/g" mempool-config.json
 | 
			
		||||
sed -i "s/__SOCKS5PROXY_USERNAME__/${__SOCKS5PROXY_USERNAME__}/g" mempool-config.json
 | 
			
		||||
sed -i "s/__SOCKS5PROXY_PASSWORD__/${__SOCKS5PROXY_PASSWORD__}/g" mempool-config.json
 | 
			
		||||
 | 
			
		||||
sed -i "s!__PRICENODE_TOR_URL__!${__PRICENODE_TOR_URL__}!g" mempool-config.json
 | 
			
		||||
sed -i "s!__PRICENODE_CLEARNET_URL__!${__PRICENODE_CLEARNET_URL__}!g" mempool-config.json
 | 
			
		||||
 | 
			
		||||
node /backend/dist/index.js
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user