mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
found blocks services and tables
This commit is contained in:
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user