mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
client unit tests
This commit is contained in:
@@ -15,11 +15,11 @@ export class BitcoinRpcService {
|
||||
public newBlock$ = this._newBlock$.pipe(filter(block => block != null));
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
const url = configService.get('BITCOIN_RPC_URL');
|
||||
const user = configService.get('BITCOIN_RPC_USER');
|
||||
const pass = configService.get('BITCOIN_RPC_PASSWORD');
|
||||
const port = parseInt(configService.get('BITCOIN_RPC_PORT'));
|
||||
const timeout = parseInt(configService.get('BITCOIN_RPC_TIMEOUT'));
|
||||
const url = this.configService.get('BITCOIN_RPC_URL');
|
||||
const user = this.configService.get('BITCOIN_RPC_USER');
|
||||
const 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'));
|
||||
|
||||
this.client = new RPCClient({ url, port, timeout, user, pass });
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { from, map, Observable, shareReplay, switchMap, tap } from 'rxjs';
|
||||
import { from, map, Observable, shareReplay, switchMap } from 'rxjs';
|
||||
|
||||
import { IBlockTemplate } from '../models/bitcoin-rpc/IBlockTemplate';
|
||||
import { BitcoinRpcService } from './bitcoin-rpc.service';
|
||||
@@ -7,14 +7,12 @@ import { BitcoinRpcService } from './bitcoin-rpc.service';
|
||||
@Injectable()
|
||||
export class BlockTemplateService {
|
||||
|
||||
public currentBlockTemplate: IBlockTemplate;
|
||||
|
||||
public currentBlockTemplate$: Observable<{ blockTemplate: IBlockTemplate }>;
|
||||
|
||||
constructor(private readonly bitcoinRpcService: BitcoinRpcService) {
|
||||
this.currentBlockTemplate$ = this.bitcoinRpcService.newBlock$.pipe(
|
||||
switchMap((miningInfo) => from(this.bitcoinRpcService.getBlockTemplate()).pipe(map(blockTemplate => { return { miningInfo, blockTemplate } }))),
|
||||
tap(({ blockTemplate }) => this.currentBlockTemplate = blockTemplate),
|
||||
shareReplay({ refCount: true, bufferSize: 1 })
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,16 +62,20 @@ export class StratumV1Service implements OnModuleInit {
|
||||
promiseSocket.socket.on('end', async (error: Error) => {
|
||||
// Handle socket disconnection
|
||||
client.destroy();
|
||||
await this.clientService.delete(client.extraNonce);
|
||||
promiseSocket.destroy();
|
||||
await this.clientService.delete(client.extraNonceAndSessionId);
|
||||
|
||||
const clientCount = await this.clientService.connectedClientCount();
|
||||
|
||||
console.log(`Client disconnected: ${promiseSocket.socket.remoteAddress}, ${clientCount} total clients`);
|
||||
});
|
||||
|
||||
promiseSocket.socket.on('error', async (error: Error) => {
|
||||
|
||||
client.destroy();
|
||||
await this.clientService.delete(client.extraNonce);
|
||||
promiseSocket.destroy();
|
||||
await this.clientService.delete(client.extraNonceAndSessionId);
|
||||
|
||||
const clientCount = await this.clientService.connectedClientCount();
|
||||
console.error(`Socket error:`, error);
|
||||
console.log(`Client disconnected: ${promiseSocket.socket.remoteAddress}, ${clientCount} total clients`);
|
||||
|
||||
Reference in New Issue
Block a user