parent
371433b2da
commit
c94f004425
@ -138,7 +138,7 @@ class Bisq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updatePrice() {
|
private updatePrice() {
|
||||||
axios.get<BisqTrade[]>('https://bisq.markets/api/trades/?market=bsq_btc')
|
axios.get<BisqTrade[]>('https://bisq.markets/api/trades/?market=bsq_btc', { timeout: 10000 })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const prices: number[] = [];
|
const prices: number[] = [];
|
||||||
response.data.forEach((trade) => {
|
response.data.forEach((trade) => {
|
||||||
|
@ -1,39 +1,42 @@
|
|||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import axios from 'axios';
|
import axios, { AxiosRequestConfig } from 'axios';
|
||||||
import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory';
|
import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory';
|
||||||
import { IEsploraApi } from './esplora-api.interface';
|
import { IEsploraApi } from './esplora-api.interface';
|
||||||
|
|
||||||
class ElectrsApi implements AbstractBitcoinApi {
|
class ElectrsApi implements AbstractBitcoinApi {
|
||||||
|
axiosConfig: AxiosRequestConfig = {
|
||||||
|
timeout: 10000,
|
||||||
|
};
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
$getRawMempool(): Promise<IEsploraApi.Transaction['txid'][]> {
|
$getRawMempool(): Promise<IEsploraApi.Transaction['txid'][]> {
|
||||||
return axios.get<IEsploraApi.Transaction['txid'][]>(config.ESPLORA.REST_API_URL + '/mempool/txids')
|
return axios.get<IEsploraApi.Transaction['txid'][]>(config.ESPLORA.REST_API_URL + '/mempool/txids', this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getRawTransaction(txId: string): Promise<IEsploraApi.Transaction> {
|
$getRawTransaction(txId: string): Promise<IEsploraApi.Transaction> {
|
||||||
return axios.get<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId)
|
return axios.get<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId, this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getBlockHeightTip(): Promise<number> {
|
$getBlockHeightTip(): Promise<number> {
|
||||||
return axios.get<number>(config.ESPLORA.REST_API_URL + '/blocks/tip/height')
|
return axios.get<number>(config.ESPLORA.REST_API_URL + '/blocks/tip/height', this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getTxIdsForBlock(hash: string): Promise<string[]> {
|
$getTxIdsForBlock(hash: string): Promise<string[]> {
|
||||||
return axios.get<string[]>(config.ESPLORA.REST_API_URL + '/block/' + hash + '/txids')
|
return axios.get<string[]>(config.ESPLORA.REST_API_URL + '/block/' + hash + '/txids', this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getBlockHash(height: number): Promise<string> {
|
$getBlockHash(height: number): Promise<string> {
|
||||||
return axios.get<string>(config.ESPLORA.REST_API_URL + '/block-height/' + height)
|
return axios.get<string>(config.ESPLORA.REST_API_URL + '/block-height/' + height, this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$getBlock(hash: string): Promise<IEsploraApi.Block> {
|
$getBlock(hash: string): Promise<IEsploraApi.Block> {
|
||||||
return axios.get<IEsploraApi.Block>(config.ESPLORA.REST_API_URL + '/block/' + hash)
|
return axios.get<IEsploraApi.Block>(config.ESPLORA.REST_API_URL + '/block/' + hash, this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +49,7 @@ class ElectrsApi implements AbstractBitcoinApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$getRawTransactionBitcoind(txId: string): Promise<IEsploraApi.Transaction> {
|
$getRawTransactionBitcoind(txId: string): Promise<IEsploraApi.Transaction> {
|
||||||
return axios.get<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId)
|
return axios.get<IEsploraApi.Transaction>(config.ESPLORA.REST_API_URL + '/tx/' + txId, this.axiosConfig)
|
||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ class Donations {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': config.SPONSORS.BTCPAY_AUTH,
|
'Authorization': config.SPONSORS.BTCPAY_AUTH,
|
||||||
},
|
},
|
||||||
|
timeout: 10000,
|
||||||
};
|
};
|
||||||
|
|
||||||
sponsorsCache: any[] = [];
|
sponsorsCache: any[] = [];
|
||||||
@ -169,7 +170,8 @@ class Donations {
|
|||||||
const res = await axios.get(`https://api.twitter.com/1.1/users/show.json?screen_name=${handle}`, {
|
const res = await axios.get(`https://api.twitter.com/1.1/users/show.json?screen_name=${handle}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: 'Bearer ' + config.SPONSORS.TWITTER_BEARER_AUTH
|
Authorization: 'Bearer ' + config.SPONSORS.TWITTER_BEARER_AUTH
|
||||||
}
|
},
|
||||||
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
logger.debug('Twitter user data fetched:' + JSON.stringify(res.data));
|
logger.debug('Twitter user data fetched:' + JSON.stringify(res.data));
|
||||||
return res.data;
|
return res.data;
|
||||||
@ -177,7 +179,7 @@ class Donations {
|
|||||||
|
|
||||||
private async $downloadProfileImageBlob(url: string): Promise<string> {
|
private async $downloadProfileImageBlob(url: string): Promise<string> {
|
||||||
logger.debug('Fetching image blob...');
|
logger.debug('Fetching image blob...');
|
||||||
const res = await axios.get(url, { responseType: 'arraybuffer' });
|
const res = await axios.get(url, { responseType: 'arraybuffer', timeout: 10000 });
|
||||||
logger.debug('Image downloaded.');
|
logger.debug('Image downloaded.');
|
||||||
return Buffer.from(res.data, 'utf8').toString('base64');
|
return Buffer.from(res.data, 'utf8').toString('base64');
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class FiatConversion {
|
|||||||
|
|
||||||
private async updateCurrency(): Promise<void> {
|
private async updateCurrency(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('https://price.bisq.wiz.biz/getAllMarketPrices');
|
const response = await axios.get('https://price.bisq.wiz.biz/getAllMarketPrices', { timeout: 10000 });
|
||||||
const usd = response.data.data.find((item: any) => item.currencyCode === 'USD');
|
const usd = response.data.data.find((item: any) => item.currencyCode === 'USD');
|
||||||
this.conversionRates = {
|
this.conversionRates = {
|
||||||
'USD': usd.price,
|
'USD': usd.price,
|
||||||
|
@ -202,7 +202,7 @@ class Server {
|
|||||||
this.app
|
this.app
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => {
|
.get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream' });
|
const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream', timeout: 10000 });
|
||||||
response.data.pipe(res);
|
response.data.pipe(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).end();
|
res.status(500).end();
|
||||||
@ -210,7 +210,9 @@ class Server {
|
|||||||
})
|
})
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => {
|
.get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, { responseType: 'stream' });
|
const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, {
|
||||||
|
responseType: 'stream', timeout: 10000
|
||||||
|
});
|
||||||
response.data.pipe(res);
|
response.data.pipe(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(500).end();
|
res.status(500).end();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user