getBlockTemplate improvements

This commit is contained in:
Benjamin Wilson
2024-07-04 16:41:15 -04:00
parent ad1f32cc2c
commit fc96b9ea45
+9 -3
View File
@@ -93,10 +93,10 @@ export class BitcoinRpcService implements OnModuleInit {
const block = await this.rpcBlockService.getBlock(blockHeight); const block = await this.rpcBlockService.getBlock(blockHeight);
if (block != null && block.data != null) { if (block != null && block.data != null) {
console.log('promise loop resolved'); console.log(`promise loop resolved, block height ${blockHeight}`);
return Promise.resolve(JSON.parse(block.data)); return Promise.resolve(JSON.parse(block.data));
} }
console.log('promise loop'); console.log(`promise loop, block height ${blockHeight}`);
} }
} }
@@ -128,7 +128,13 @@ export class BitcoinRpcService implements OnModuleInit {
} }
}); });
} }
await this.rpcBlockService.saveBlock(blockHeight, JSON.stringify(result));
let saved = false;
while(!saved){
let saveResult = await this.rpcBlockService.saveBlock(blockHeight, JSON.stringify(result));
saved = saveResult.affected > 0;
}
} else { } else {
//wait for block //wait for block