data persistance init

This commit is contained in:
Ben Wilson
2023-06-23 22:30:54 -04:00
parent b963eaa514
commit 080471e52d
16 changed files with 2760 additions and 188 deletions
+34 -19
View File
@@ -1,44 +1,59 @@
import { Controller, Get, Param } from '@nestjs/common';
import { AppService } from './app.service';
import { ClientStatisticsService } from './ORM/client-statistics/client-statistics.service';
import { ClientService } from './ORM/client/client.service';
import { StratumV1Service } from './stratum-v1.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService, private readonly stratumV1Service: StratumV1Service) { }
constructor(
private readonly appService: AppService,
private readonly stratumV1Service: StratumV1Service,
private readonly clientService: ClientService,
private readonly clientStatisticsService: ClientStatisticsService
) { }
@Get()
getInfo() {
async getInfo() {
return {
clients: this.stratumV1Service.clients.length
clients: await this.clientService.connectedClientCount()
}
}
@Get('client/:clientId')
getClientInfo(@Param('clientId') clientId: string) {
const workers = this.stratumV1Service.clients.filter(client => client.clientAuthorization.address === clientId);
async getClientInfo(@Param('clientId') clientId: string) {
const workers = await this.clientService.getByAddress(clientId);
//const workers = this.stratumV1Service.clients.filter(client => client.clientAuthorization.address === clientId);
return {
workersCount: workers.length,
workers: workers.map(worker => {
return {
id: worker.id,
name: worker.clientAuthorization.worker,
bestDifficulty: Math.floor(worker.statistics.bestDifficulty),
hashRate: Math.floor(worker.statistics.getHashRate()),
startTime: worker.startTime
}
})
workers: await Promise.all(
workers.map(async (worker) => {
return {
id: worker.id,
name: worker.clientName,
bestDifficulty: Math.floor(worker.bestDifficulty),
hashRate: Math.floor(await this.clientStatisticsService.getHashRate(worker.id)),
startTime: worker.startTime
};
})
)
}
}
@Get('client/:clientId/:workerId')
getWorkerInfo(@Param('clientId') clientId: string, @Param('workerId') workerId: string) {
const worker = this.stratumV1Service.clients.find(client => client.clientAuthorization.address === clientId && client.id === workerId);
async getWorkerInfo(@Param('clientId') clientId: string, @Param('workerId') workerId: string) {
const worker = await this.clientService.getByAddressAndName(clientId, workerId);
//const worker = this.stratumV1Service.clients.find(client => client.clientAuthorization.address === clientId && client.id === workerId);
return {
id: worker.id,
name: worker.clientAuthorization.worker,
bestDifficulty: Math.floor(worker.statistics.bestDifficulty),
hashData: worker.statistics.historicSubmissions,
name: worker.clientName,
bestDifficulty: Math.floor(worker.bestDifficulty),
//hashData: worker.statistics.historicSubmissions,
startTime: worker.startTime
}
}