RPC load reduction

This commit is contained in:
Ben
2023-11-24 14:56:35 -05:00
parent 2aa0ebe587
commit b9af79978f
8 changed files with 122 additions and 22 deletions
+14
View File
@@ -0,0 +1,14 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';
@Entity()
export class RpcBlockEntity {
@PrimaryColumn()
blockHeight: number;
@Column({ nullable: true })
lockedBy?: string;
@Column({ nullable: true })
data?: string;
}
+14
View File
@@ -0,0 +1,14 @@
import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RpcBlockEntity } from './rpc-block.entity';
import { RpcBlockService } from './rpc-block.service';
@Global()
@Module({
imports: [TypeOrmModule.forFeature([RpcBlockEntity])],
providers: [RpcBlockService],
exports: [TypeOrmModule, RpcBlockService],
})
export class RpcBlocksModule { }
+28
View File
@@ -0,0 +1,28 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { RpcBlockEntity } from './rpc-block.entity';
@Injectable()
export class RpcBlockService {
constructor(
@InjectRepository(RpcBlockEntity)
private rpcBlockRepository: Repository<RpcBlockEntity>
) {
}
public getBlock(blockHeight: number) {
return this.rpcBlockRepository.findOne({
where: { blockHeight }
});
}
public lockBlock(blockHeight: number, process: string) {
return this.rpcBlockRepository.save({ blockHeight, data: null, lockedBy: process });
}
public saveBlock(blockHeight: number, data: string) {
return this.rpcBlockRepository.update(blockHeight, { data })
}
}