* Perform a blockchain sync check before updating initial difficulty adjustment. fixes #603 * Updating logger messages.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import config from '../../config';
|
|
import * as bitcoin from '@mempool/bitcoin';
|
|
import { IBitcoinApi } from './bitcoin-api.interface';
|
|
|
|
class BitcoinBaseApi {
|
|
bitcoindClient: any;
|
|
bitcoindClientMempoolInfo: any;
|
|
|
|
constructor() {
|
|
this.bitcoindClient = new bitcoin.Client({
|
|
host: config.CORE_RPC.HOST,
|
|
port: config.CORE_RPC.PORT,
|
|
user: config.CORE_RPC.USERNAME,
|
|
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();
|
|
}
|
|
|
|
$getBlockchainInfo(): Promise<IBitcoinApi.BlockchainInfo> {
|
|
return this.bitcoindClient.getBlockchainInfo();
|
|
}
|
|
}
|
|
|
|
export default new BitcoinBaseApi();
|