Skip to content

Commit

Permalink
fix: perform status endpoint sql inside transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Aug 16, 2024
1 parent a0df9fb commit b23445c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/api/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,25 @@ export const StatusRoutes: FastifyPluginAsync<
status: 'ready',
};
try {
const poxForceUnlockHeights = await fastify.db.getPoxForceUnlockHeights();
if (poxForceUnlockHeights.found) {
response.pox_v1_unlock_height = poxForceUnlockHeights.result.pox1UnlockHeight as number;
response.pox_v2_unlock_height = poxForceUnlockHeights.result.pox2UnlockHeight as number;
response.pox_v3_unlock_height = poxForceUnlockHeights.result.pox3UnlockHeight as number;
}
const chainTip = await fastify.db.getChainTip(fastify.db.sql);
if (chainTip.block_height > 0) {
response.chain_tip = {
block_height: chainTip.block_height,
block_hash: chainTip.block_hash,
index_block_hash: chainTip.index_block_hash,
microblock_hash: chainTip.microblock_hash,
microblock_sequence: chainTip.microblock_sequence,
burn_block_height: chainTip.burn_block_height,
};
}
await fastify.db.sqlTransaction(async sql => {
const poxForceUnlockHeights = await fastify.db.getPoxForcedUnlockHeightsInternal(sql);
if (poxForceUnlockHeights.found) {
response.pox_v1_unlock_height = poxForceUnlockHeights.result.pox1UnlockHeight as number;
response.pox_v2_unlock_height = poxForceUnlockHeights.result.pox2UnlockHeight as number;
response.pox_v3_unlock_height = poxForceUnlockHeights.result.pox3UnlockHeight as number;
}
const chainTip = await fastify.db.getChainTip(sql);
if (chainTip.block_height > 0) {
response.chain_tip = {
block_height: chainTip.block_height,
block_hash: chainTip.block_hash,
index_block_hash: chainTip.index_block_hash,
microblock_hash: chainTip.microblock_hash,
microblock_sequence: chainTip.microblock_sequence,
burn_block_height: chainTip.burn_block_height,
};
}
});
} catch (error) {
// ignore error
}
Expand Down

0 comments on commit b23445c

Please sign in to comment.