Merge branch 'master' into regtest-1
This commit is contained in:
@@ -96,14 +96,20 @@ class Blocks {
|
||||
*/
|
||||
private getBlockExtended(block: IEsploraApi.Block, transactions: TransactionExtended[]): BlockExtended {
|
||||
const blockExtended: BlockExtended = Object.assign({}, block);
|
||||
blockExtended.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0);
|
||||
blockExtended.coinbaseTx = transactionUtils.stripCoinbaseTransaction(transactions[0]);
|
||||
|
||||
blockExtended.extras = {
|
||||
reward: transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0),
|
||||
coinbaseTx: transactionUtils.stripCoinbaseTransaction(transactions[0]),
|
||||
};
|
||||
|
||||
const transactionsTmp = [...transactions];
|
||||
transactionsTmp.shift();
|
||||
transactionsTmp.sort((a, b) => b.effectiveFeePerVsize - a.effectiveFeePerVsize);
|
||||
blockExtended.medianFee = transactionsTmp.length > 0 ? Common.median(transactionsTmp.map((tx) => tx.effectiveFeePerVsize)) : 0;
|
||||
blockExtended.feeRange = transactionsTmp.length > 0 ? Common.getFeesInRange(transactionsTmp, 8) : [0, 0];
|
||||
|
||||
blockExtended.extras.medianFee = transactionsTmp.length > 0 ?
|
||||
Common.median(transactionsTmp.map((tx) => tx.effectiveFeePerVsize)) : 0;
|
||||
blockExtended.extras.feeRange = transactionsTmp.length > 0 ?
|
||||
Common.getFeesInRange(transactionsTmp, 8) : [0, 0];
|
||||
|
||||
return blockExtended;
|
||||
}
|
||||
@@ -197,7 +203,14 @@ class Blocks {
|
||||
const block = await bitcoinApi.$getBlock(blockHash);
|
||||
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true);
|
||||
const blockExtended = this.getBlockExtended(block, transactions);
|
||||
const miner = await this.$findBlockMiner(blockExtended.coinbaseTx);
|
||||
|
||||
let miner: PoolTag;
|
||||
if (blockExtended?.extras?.coinbaseTx) {
|
||||
miner = await this.$findBlockMiner(blockExtended.extras.coinbaseTx);
|
||||
} else {
|
||||
miner = await poolsRepository.$getUnknownPool();
|
||||
}
|
||||
|
||||
const coinbase: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(transactions[0].txid, true);
|
||||
await blocksRepository.$saveBlockInDatabase(blockExtended, blockHash, coinbase.hex, miner);
|
||||
} catch (e) {
|
||||
@@ -264,7 +277,12 @@ class Blocks {
|
||||
const coinbase: IEsploraApi.Transaction = await bitcoinApi.$getRawTransaction(transactions[0].txid, true);
|
||||
|
||||
if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === true) {
|
||||
const miner = await this.$findBlockMiner(blockExtended.coinbaseTx);
|
||||
let miner: PoolTag;
|
||||
if (blockExtended?.extras?.coinbaseTx) {
|
||||
miner = await this.$findBlockMiner(blockExtended.extras.coinbaseTx);
|
||||
} else {
|
||||
miner = await poolsRepository.$getUnknownPool();
|
||||
}
|
||||
await blocksRepository.$saveBlockInDatabase(blockExtended, blockHash, coinbase.hex, miner);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
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';
|
||||
import { SocksProxyAgent } from 'socks-proxy-agent';
|
||||
|
||||
class FiatConversion {
|
||||
private conversionRates: IConversionRates = {
|
||||
@@ -17,6 +19,11 @@ 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 using ${config.PRICE_DATA_SERVER.TOR_URL}`);
|
||||
} else {
|
||||
logger.info(`Currency rates service will be queried over clearnet using ${config.PRICE_DATA_SERVER.CLEARNET_URL}`);
|
||||
}
|
||||
setInterval(this.updateCurrency.bind(this), 1000 * config.MEMPOOL.PRICE_FEED_UPDATE_INTERVAL);
|
||||
this.updateCurrency();
|
||||
}
|
||||
@@ -26,12 +33,43 @@ class FiatConversion {
|
||||
}
|
||||
|
||||
private async updateCurrency(): Promise<void> {
|
||||
const headers = { 'User-Agent': `mempool/v${backendInfo.getBackendInfo().version}` };
|
||||
let fiatConversionUrl: string;
|
||||
let response: AxiosResponse;
|
||||
|
||||
try {
|
||||
const response = await axios.get('https://price.bisq.wiz.biz/getAllMarketPrices', { timeout: 10000 });
|
||||
if (config.SOCKS5PROXY.ENABLED) {
|
||||
let socksOptions: any = {
|
||||
agentOptions: {
|
||||
keepAlive: true,
|
||||
},
|
||||
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 = config.PRICE_DATA_SERVER.TOR_URL;
|
||||
logger.debug('Querying currency rates service...');
|
||||
response = await axios.get(fiatConversionUrl, { httpAgent: agent, headers: headers, timeout: 30000 });
|
||||
} else {
|
||||
fiatConversionUrl = config.PRICE_DATA_SERVER.CLEARNET_URL;
|
||||
logger.debug('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.debug(`USD Conversion Rate: ${usd.price}`);
|
||||
|
||||
if (this.ratesChangedCallback) {
|
||||
this.ratesChangedCallback(this.conversionRates);
|
||||
}
|
||||
|
||||
@@ -380,7 +380,9 @@ class WebsocketHandler {
|
||||
mBlocks = mempoolBlocks.getMempoolBlocks();
|
||||
}
|
||||
|
||||
block.matchRate = matchRate;
|
||||
if (block.extras) {
|
||||
block.extras.matchRate = matchRate;
|
||||
}
|
||||
|
||||
this.wss.clients.forEach((client) => {
|
||||
if (client.readyState !== WebSocket.OPEN) {
|
||||
|
||||
Reference in New Issue
Block a user