mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
add option to conect to Bitcoin RPC with cookie file (#40)
This commit is contained in:
@@ -10,6 +10,9 @@ BITCOIN_RPC_PASSWORD=
|
|||||||
BITCOIN_RPC_PORT=8332
|
BITCOIN_RPC_PORT=8332
|
||||||
BITCOIN_RPC_TIMEOUT=10000
|
BITCOIN_RPC_TIMEOUT=10000
|
||||||
|
|
||||||
|
# You can use this instead of BITCOIN_RPC_USER and BITCOIN_RPC_PASSWORD
|
||||||
|
BITCOIN_RPC_COOKIEFILE=
|
||||||
|
|
||||||
# Enable in bitcoin.conf with
|
# Enable in bitcoin.conf with
|
||||||
# zmqpubrawblock=tcp://*:3000
|
# zmqpubrawblock=tcp://*:3000
|
||||||
# BITCOIN_ZMQ_HOST="tcp://192.168.1.100:3000"
|
# BITCOIN_ZMQ_HOST="tcp://192.168.1.100:3000"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import * as zmq from 'zeromq';
|
|||||||
|
|
||||||
import { IBlockTemplate } from '../models/bitcoin-rpc/IBlockTemplate';
|
import { IBlockTemplate } from '../models/bitcoin-rpc/IBlockTemplate';
|
||||||
import { IMiningInfo } from '../models/bitcoin-rpc/IMiningInfo';
|
import { IMiningInfo } from '../models/bitcoin-rpc/IMiningInfo';
|
||||||
|
import * as fs from 'node:fs';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BitcoinRpcService implements OnModuleInit {
|
export class BitcoinRpcService implements OnModuleInit {
|
||||||
@@ -24,11 +25,20 @@ export class BitcoinRpcService implements OnModuleInit {
|
|||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
const url = this.configService.get('BITCOIN_RPC_URL');
|
const url = this.configService.get('BITCOIN_RPC_URL');
|
||||||
const user = this.configService.get('BITCOIN_RPC_USER');
|
let user = this.configService.get('BITCOIN_RPC_USER');
|
||||||
const pass = this.configService.get('BITCOIN_RPC_PASSWORD');
|
let pass = this.configService.get('BITCOIN_RPC_PASSWORD');
|
||||||
const port = parseInt(this.configService.get('BITCOIN_RPC_PORT'));
|
const port = parseInt(this.configService.get('BITCOIN_RPC_PORT'));
|
||||||
const timeout = parseInt(this.configService.get('BITCOIN_RPC_TIMEOUT'));
|
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 = new RPCClient({ url, port, timeout, user, pass });
|
||||||
|
|
||||||
this.client.getrpcinfo().then((res) => {
|
this.client.getrpcinfo().then((res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user