block template fix for NULL NODE_APP_INSTANCE

This commit is contained in:
Ben Wilson
2024-01-23 18:40:50 -05:00
parent e29caad377
commit a98ec3879e
+7
View File
@@ -30,7 +30,11 @@ export class BitcoinRpcService {
this.client = new RPCClient({ url, port, timeout, user, pass }); this.client = new RPCClient({ url, port, timeout, user, pass });
this.client.getrpcinfo().then((res) => {
console.log('Bitcoin RPC connected'); console.log('Bitcoin RPC connected');
}, () => {
console.error('Could not reach RPC host');
});
if (this.configService.get('BITCOIN_ZMQ_HOST')) { if (this.configService.get('BITCOIN_ZMQ_HOST')) {
// const sock = zmq.socket("sub"); // const sock = zmq.socket("sub");
@@ -77,12 +81,15 @@ export class BitcoinRpcService {
if (block != null && block.data != null) { if (block != null && block.data != null) {
return Promise.resolve(JSON.parse(block.data)); return Promise.resolve(JSON.parse(block.data));
} else if (block == null) { } else if (block == null) {
if (process.env.NODE_APP_INSTANCE != null) {
// There is a unique constraint on the block height so if another process tries to lock, it'll throw // There is a unique constraint on the block height so if another process tries to lock, it'll throw
try { try {
await this.rpcBlockService.lockBlock(blockHeight, process.env.NODE_APP_INSTANCE); await this.rpcBlockService.lockBlock(blockHeight, process.env.NODE_APP_INSTANCE);
} catch (e) { } catch (e) {
result = await this.waitForBlock(blockHeight); result = await this.waitForBlock(blockHeight);
} }
}
result = await this.client.getblocktemplate({ result = await this.client.getblocktemplate({
template_request: { template_request: {