mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-03-27 02:02:10 +01:00
found blocks services and tables
This commit is contained in:
parent
cf3f414475
commit
ddc7907919
@ -0,0 +1,26 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
||||
|
||||
@Entity()
|
||||
export class BlocksEntity extends TrackedEntity {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
height: number;
|
||||
|
||||
@Column({ length: 62, type: 'varchar' })
|
||||
minerAddress: string;
|
||||
|
||||
@Column()
|
||||
worker: string;
|
||||
|
||||
@Column({ length: 8, type: 'varchar' })
|
||||
sessionId: string;
|
||||
|
||||
@Column()
|
||||
blockData: string;
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { BlocksEntity } from './blocks.entity';
|
||||
import { BlocksService } from './blocks.service';
|
||||
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([BlocksEntity])],
|
||||
providers: [BlocksService],
|
||||
exports: [TypeOrmModule, BlocksService],
|
||||
})
|
||||
export class BlocksModule { }
|
@ -0,0 +1,49 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
|
||||
import { BlocksEntity } from './blocks.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class BlocksService {
|
||||
|
||||
constructor(
|
||||
|
||||
private dataSource: DataSource,
|
||||
@InjectRepository(BlocksEntity)
|
||||
private blocksRepository: Repository<BlocksEntity>,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async save(block: Partial<BlocksEntity>) {
|
||||
await this.blocksRepository.save(block);
|
||||
}
|
||||
|
||||
public async getFoundBlocks() {
|
||||
return await this.blocksRepository.find({
|
||||
select: {
|
||||
height: true,
|
||||
minerAddress: true,
|
||||
worker: true,
|
||||
sessionId: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async getFoundBlocksByAddress(address: string) {
|
||||
return await this.blocksRepository.find({
|
||||
select: {
|
||||
height: true,
|
||||
minerAddress: true,
|
||||
worker: true,
|
||||
sessionId: true
|
||||
},
|
||||
where: {
|
||||
minerAddress: address
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { Controller, Get, Inject } from '@nestjs/common';
|
||||
import { Cache } from 'cache-manager';
|
||||
|
||||
import { BlocksService } from './ORM/blocks/blocks.service';
|
||||
import { ClientStatisticsService } from './ORM/client-statistics/client-statistics.service';
|
||||
import { ClientService } from './ORM/client/client.service';
|
||||
|
||||
@ -10,7 +11,8 @@ export class AppController {
|
||||
constructor(
|
||||
@Inject(CACHE_MANAGER) private cacheManager: Cache,
|
||||
private clientService: ClientService,
|
||||
private clientStatisticsService: ClientStatisticsService
|
||||
private clientStatisticsService: ClientStatisticsService,
|
||||
private blocksService: BlocksService
|
||||
) { }
|
||||
|
||||
@Get('info')
|
||||
@ -26,10 +28,13 @@ export class AppController {
|
||||
|
||||
const chartData = await this.clientStatisticsService.getChartDataForSite();
|
||||
|
||||
await this.cacheManager.set(CACHE_KEY, chartData, 600)
|
||||
await this.cacheManager.set(CACHE_KEY, chartData, 600);
|
||||
|
||||
const blockData = await this.blocksService.getFoundBlocks();
|
||||
|
||||
return {
|
||||
chartData
|
||||
chartData,
|
||||
blockData
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import { AppController } from './app.controller';
|
||||
import { AddressController } from './controllers/address/address.controller';
|
||||
import { ClientController } from './controllers/client/client.controller';
|
||||
import { AddressSettingsModule } from './ORM/address-settings/address-settings.module';
|
||||
import { BlocksModule } from './ORM/blocks/blocks.module';
|
||||
import { ClientStatisticsModule } from './ORM/client-statistics/client-statistics.module';
|
||||
import { ClientModule } from './ORM/client/client.module';
|
||||
import { TelegramSubscriptionsModule } from './ORM/telegram-subscriptions/telegram-subscriptions.module';
|
||||
@ -23,7 +24,8 @@ const ORMModules = [
|
||||
ClientStatisticsModule,
|
||||
ClientModule,
|
||||
AddressSettingsModule,
|
||||
TelegramSubscriptionsModule
|
||||
TelegramSubscriptionsModule,
|
||||
BlocksModule
|
||||
]
|
||||
|
||||
@Module({
|
||||
|
@ -8,6 +8,7 @@ import PromiseSocket from 'promise-socket';
|
||||
import { combineLatest, firstValueFrom, interval, startWith, takeUntil } from 'rxjs';
|
||||
import { NotificationService } from 'src/services/notification.service';
|
||||
|
||||
import { BlocksService } from '../ORM/blocks/blocks.service';
|
||||
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
|
||||
import { ClientEntity } from '../ORM/client/client.entity';
|
||||
import { ClientService } from '../ORM/client/client.service';
|
||||
@ -50,7 +51,8 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
private readonly bitcoinRpcService: BitcoinRpcService,
|
||||
private readonly clientService: ClientService,
|
||||
private readonly clientStatisticsService: ClientStatisticsService,
|
||||
private readonly notificationService: NotificationService
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly blocksService: BlocksService
|
||||
) {
|
||||
super();
|
||||
|
||||
@ -359,6 +361,13 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
console.log('!!! BLOCK FOUND !!!');
|
||||
const blockHex = updatedJobBlock.toHex(false);
|
||||
const result = await this.bitcoinRpcService.SUBMIT_BLOCK(blockHex);
|
||||
await this.blocksService.save({
|
||||
height: job.blockTemplate.height,
|
||||
minerAddress: this.clientAuthorization.address,
|
||||
worker: this.clientAuthorization.worker,
|
||||
sessionId: this.extraNonce,
|
||||
blockData: blockHex
|
||||
})
|
||||
await this.notificationService.notifySubscribersBlockFound(this.clientAuthorization.address, job.blockTemplate.height, updatedJobBlock, result);
|
||||
}
|
||||
try {
|
||||
|
@ -3,6 +3,7 @@ import { Server, Socket } from 'net';
|
||||
import { PromiseSocket } from 'promise-socket';
|
||||
|
||||
import { StratumV1Client } from '../models/StratumV1Client';
|
||||
import { BlocksService } from '../ORM/blocks/blocks.service';
|
||||
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
|
||||
import { ClientService } from '../ORM/client/client.service';
|
||||
import { BitcoinRpcService } from './bitcoin-rpc.service';
|
||||
@ -19,7 +20,8 @@ export class StratumV1Service implements OnModuleInit {
|
||||
private readonly blockTemplateService: BlockTemplateService,
|
||||
private readonly clientService: ClientService,
|
||||
private readonly clientStatisticsService: ClientStatisticsService,
|
||||
private readonly notificationService: NotificationService
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly blocksService: BlocksService
|
||||
) {
|
||||
}
|
||||
|
||||
@ -44,7 +46,8 @@ export class StratumV1Service implements OnModuleInit {
|
||||
this.bitcoinRpcService,
|
||||
this.clientService,
|
||||
this.clientStatisticsService,
|
||||
this.notificationService
|
||||
this.notificationService,
|
||||
this.blocksService
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user