loadBlockTemplate

This commit is contained in:
Benjamin Wilson 2024-09-16 19:28:00 -04:00
parent 717a5c7878
commit c1ab6a152e

View File

@ -118,6 +118,8 @@ export class BitcoinRpcService implements OnModuleInit {
private async loadBlockTemplate(blockHeight: number) {
console.log(`Master fetching block ${blockHeight}`);
let blockTemplate: IBlockTemplate;
while (blockTemplate == null) {
blockTemplate = await this.client.getblocktemplate({
@ -129,8 +131,13 @@ export class BitcoinRpcService implements OnModuleInit {
});
}
try{
console.log(`Saving block ${blockHeight}`);
await this.rpcBlockService.saveBlock(blockHeight, JSON.stringify(blockTemplate));
await this.rpcBlockService.saveBlock(blockHeight, JSON.stringify(blockTemplate));
}catch(e){
console.log('Error saving block', e.message);
}
return blockTemplate;
}