Optionally support second CoreRPC instance as source for the minimum fee.
This commit is contained in:
		
							parent
							
								
									d49c347413
								
							
						
					
					
						commit
						eff4d2c8cd
					
				@ -22,6 +22,13 @@
 | 
			
		||||
  "ESPLORA": {
 | 
			
		||||
    "REST_API_URL": "http://127.0.0.1:3000"
 | 
			
		||||
  },
 | 
			
		||||
  "CORE_RPC_MINFEE": {
 | 
			
		||||
    "ENABLED": false,
 | 
			
		||||
    "HOST": "127.0.0.1",
 | 
			
		||||
    "PORT": 8332,
 | 
			
		||||
    "USERNAME": "mempool",
 | 
			
		||||
    "PASSWORD": "mempool"
 | 
			
		||||
  },
 | 
			
		||||
  "DATABASE": {
 | 
			
		||||
    "ENABLED": true,
 | 
			
		||||
    "HOST": "127.0.0.1",
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ import { IBitcoinApi } from './bitcoin-api.interface';
 | 
			
		||||
 | 
			
		||||
class BitcoinBaseApi {
 | 
			
		||||
  bitcoindClient: any;
 | 
			
		||||
  bitcoindClientMempoolInfo: any;
 | 
			
		||||
 | 
			
		||||
  constructor() {
 | 
			
		||||
    this.bitcoindClient = new bitcoin.Client({
 | 
			
		||||
@ -13,9 +14,30 @@ class BitcoinBaseApi {
 | 
			
		||||
      pass: config.CORE_RPC.PASSWORD,
 | 
			
		||||
      timeout: 60000,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (config.CORE_RPC_MINFEE.ENABLED) {
 | 
			
		||||
      this.bitcoindClientMempoolInfo = new bitcoin.Client({
 | 
			
		||||
        host: config.CORE_RPC_MINFEE.HOST,
 | 
			
		||||
        port: config.CORE_RPC_MINFEE.PORT,
 | 
			
		||||
        user: config.CORE_RPC_MINFEE.USERNAME,
 | 
			
		||||
        pass: config.CORE_RPC_MINFEE.PASSWORD,
 | 
			
		||||
        timeout: 60000,
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $getMempoolInfo(): Promise<IBitcoinApi.MempoolInfo> {
 | 
			
		||||
    if (config.CORE_RPC_MINFEE.ENABLED) {
 | 
			
		||||
      return Promise.all([
 | 
			
		||||
        this.bitcoindClient.getMempoolInfo(),
 | 
			
		||||
        this.bitcoindClientMempoolInfo.getMempoolInfo()
 | 
			
		||||
      ]).then(([mempoolInfo, secondMempoolInfo]) => {
 | 
			
		||||
        mempoolInfo.maxmempool = secondMempoolInfo.maxmempool;
 | 
			
		||||
        mempoolInfo.mempoolminfee = secondMempoolInfo.mempoolminfee;
 | 
			
		||||
        mempoolInfo.minrelaytxfee = secondMempoolInfo.minrelaytxfee;
 | 
			
		||||
        return mempoolInfo;
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
    return this.bitcoindClient.getMempoolInfo();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,13 @@ interface IConfig {
 | 
			
		||||
    USERNAME: string;
 | 
			
		||||
    PASSWORD: string;
 | 
			
		||||
  };
 | 
			
		||||
  CORE_RPC_MINFEE: {
 | 
			
		||||
    ENABLED: boolean;
 | 
			
		||||
    HOST: string;
 | 
			
		||||
    PORT: number;
 | 
			
		||||
    USERNAME: string;
 | 
			
		||||
    PASSWORD: string;
 | 
			
		||||
  };
 | 
			
		||||
  DATABASE: {
 | 
			
		||||
    ENABLED: boolean;
 | 
			
		||||
    HOST: string,
 | 
			
		||||
@ -77,6 +84,13 @@ const defaults: IConfig = {
 | 
			
		||||
    'USERNAME': 'mempool',
 | 
			
		||||
    'PASSWORD': 'mempool'
 | 
			
		||||
  },
 | 
			
		||||
  'CORE_RPC_MINFEE': {
 | 
			
		||||
    'ENABLED': false,
 | 
			
		||||
    'HOST': '127.0.0.1',
 | 
			
		||||
    'PORT': 8332,
 | 
			
		||||
    'USERNAME': 'mempool',
 | 
			
		||||
    'PASSWORD': 'mempool'
 | 
			
		||||
  },
 | 
			
		||||
  'DATABASE': {
 | 
			
		||||
    'ENABLED': true,
 | 
			
		||||
    'HOST': 'localhost',
 | 
			
		||||
@ -111,6 +125,7 @@ class Config implements IConfig {
 | 
			
		||||
  ESPLORA: IConfig['ESPLORA'];
 | 
			
		||||
  ELECTRUM: IConfig['ELECTRUM'];
 | 
			
		||||
  CORE_RPC: IConfig['CORE_RPC'];
 | 
			
		||||
  CORE_RPC_MINFEE: IConfig['CORE_RPC_MINFEE'];
 | 
			
		||||
  DATABASE: IConfig['DATABASE'];
 | 
			
		||||
  STATISTICS: IConfig['STATISTICS'];
 | 
			
		||||
  BISQ_BLOCKS: IConfig['BISQ_BLOCKS'];
 | 
			
		||||
@ -123,6 +138,7 @@ class Config implements IConfig {
 | 
			
		||||
    this.ESPLORA = configs.ESPLORA;
 | 
			
		||||
    this.ELECTRUM = configs.ELECTRUM;
 | 
			
		||||
    this.CORE_RPC = configs.CORE_RPC;
 | 
			
		||||
    this.CORE_RPC_MINFEE = configs.CORE_RPC_MINFEE;
 | 
			
		||||
    this.DATABASE = configs.DATABASE;
 | 
			
		||||
    this.STATISTICS = configs.STATISTICS;
 | 
			
		||||
    this.BISQ_BLOCKS = configs.BISQ_BLOCKS;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user