add option to conect to Bitcoin RPC with cookie file (#40)

This commit is contained in:
Marcel Hernandez
2024-06-10 07:43:47 -04:00
committed by GitHub
parent 098fe2867a
commit 76e2426c30
2 changed files with 15 additions and 2 deletions
+12 -2
View File
@@ -7,6 +7,7 @@ import * as zmq from 'zeromq';
import { IBlockTemplate } from '../models/bitcoin-rpc/IBlockTemplate';
import { IMiningInfo } from '../models/bitcoin-rpc/IMiningInfo';
import * as fs from 'node:fs';
@Injectable()
export class BitcoinRpcService implements OnModuleInit {
@@ -24,11 +25,20 @@ export class BitcoinRpcService implements OnModuleInit {
async onModuleInit() {
const url = this.configService.get('BITCOIN_RPC_URL');
const user = this.configService.get('BITCOIN_RPC_USER');
const pass = this.configService.get('BITCOIN_RPC_PASSWORD');
let user = this.configService.get('BITCOIN_RPC_USER');
let pass = this.configService.get('BITCOIN_RPC_PASSWORD');
const port = parseInt(this.configService.get('BITCOIN_RPC_PORT'));
const timeout = parseInt(this.configService.get('BITCOIN_RPC_TIMEOUT'));
const cookiefile = this.configService.get('BITCOIN_RPC_COOKIEFILE')
if (cookiefile != undefined && cookiefile != '') {
const cookie = fs.readFileSync(cookiefile).toString().split(':')
user = cookie[0]
pass = cookie[1]
}
this.client = new RPCClient({ url, port, timeout, user, pass });
this.client.getrpcinfo().then((res) => {