2020-12-28 04:47:22 +07:00
|
|
|
import config from '../../config';
|
|
|
|
import * as bitcoin from '@mempool/bitcoin';
|
|
|
|
import { IBitcoinApi } from './bitcoin-api.interface';
|
|
|
|
|
|
|
|
class BitcoinBaseApi {
|
|
|
|
bitcoindClient: any;
|
2021-01-15 22:23:32 +07:00
|
|
|
bitcoindClientMempoolInfo: any;
|
2020-12-28 04:47:22 +07:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.bitcoindClient = new bitcoin.Client({
|
2021-01-11 14:53:18 +07:00
|
|
|
host: config.CORE_RPC.HOST,
|
|
|
|
port: config.CORE_RPC.PORT,
|
|
|
|
user: config.CORE_RPC.USERNAME,
|
|
|
|
pass: config.CORE_RPC.PASSWORD,
|
2020-12-28 04:47:22 +07:00
|
|
|
timeout: 60000,
|
|
|
|
});
|
2021-01-15 22:23:32 +07:00
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
2020-12-28 04:47:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
$getMempoolInfo(): Promise<IBitcoinApi.MempoolInfo> {
|
2021-01-15 22:23:32 +07:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
2020-12-28 04:47:22 +07:00
|
|
|
return this.bitcoindClient.getMempoolInfo();
|
|
|
|
}
|
2021-08-01 15:49:26 +03:00
|
|
|
|
|
|
|
$getBlockchainInfo(): Promise<IBitcoinApi.BlockchainInfo> {
|
|
|
|
return this.bitcoindClient.getBlockchainInfo();
|
|
|
|
}
|
2020-12-28 04:47:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new BitcoinBaseApi();
|