mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
block save => upsert
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { InsertResult, Repository } from 'typeorm';
|
||||||
|
|
||||||
import { RpcBlockEntity } from './rpc-block.entity';
|
import { RpcBlockEntity } from './rpc-block.entity';
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ export class RpcBlockService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveBlock(blockHeight: number, data: string) {
|
public saveBlock(blockHeight: number, data: string): Promise<InsertResult> {
|
||||||
return this.rpcBlockRepository.save( {blockHeight, data });
|
return this.rpcBlockRepository.upsert({ blockHeight, data }, ['blockHeight']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteOldBlocks() {
|
public async deleteOldBlocks() {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ export class BitcoinRpcService implements OnModuleInit {
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
console.log(`Saving block ${blockHeight}`);
|
console.log(`Saving block ${blockHeight}`);
|
||||||
const result = await this.rpcBlockService.saveBlock(blockHeight, JSON.stringify(blockTemplate));
|
await this.rpcBlockService.saveBlock(blockHeight, JSON.stringify(blockTemplate));
|
||||||
console.log('block saved');
|
console.log('block saved');
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.error('Error saving block', e);
|
console.error('Error saving block', e);
|
||||||
|
|||||||
Reference in New Issue
Block a user