Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 0 additions & 191 deletions scripts/populate-native-tokens.js

This file was deleted.

54 changes: 54 additions & 0 deletions src/routes/cumulativeTxCountRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,60 @@ router.get('/chains/:chainId/cumulativeTxCount/latest', validate(validators.getC
}
});

// Get latest cumulative tx count for all chains in a single call
router.get('/cumulativeTxCount/all/latest', async (req, res) => {
try {
// Get all chains with valid numeric IDs
const chains = await Chain.find({
evmChainId: { $exists: true, $ne: null }
}).select('evmChainId chainName subnetId').lean();

const chainIds = chains.map(c => String(c.evmChainId));

// Fetch latest cumulative tx count for all chains in one aggregation
const txCountRecords = await CumulativeTxCount.aggregate([
{ $match: { chainId: { $in: chainIds } } },
{ $sort: { chainId: 1, timestamp: -1 } },
{
$group: {
_id: '$chainId',
value: { $first: '$value' },
timestamp: { $first: '$timestamp' }
}
}
]);

// Create a map for O(1) lookup
const txCountMap = new Map(txCountRecords.map(r => [r._id, r]));

// Build response with chain info
const data = chains.map(chain => {
const txCount = txCountMap.get(String(chain.evmChainId));
return {
evmChainId: chain.evmChainId,
subnetId: chain.subnetId,
chainName: chain.chainName,
cumulativeTxCount: txCount ? {
value: txCount.value,
timestamp: txCount.timestamp
} : null
};
});

res.json({
success: true,
count: data.length,
data
});
} catch (error) {
logger.error('All CumulativeTxCount Error:', { error: error.message });
res.status(500).json({
success: false,
error: error.message
});
}
});

// Health check endpoint
router.get('/cumulativeTxCount/health', async (req, res) => {
try {
Expand Down
54 changes: 54 additions & 0 deletions src/routes/tpsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,60 @@ router.get('/chains/:chainId/tps/latest', validate(validators.getLatestTps), asy
}
});

// Get latest TPS for all chains in a single call
router.get('/tps/all/latest', async (req, res) => {
try {
// Get all chains with valid numeric IDs
const chains = await Chain.find({
evmChainId: { $exists: true, $ne: null }
}).select('evmChainId chainName subnetId').lean();

const chainIds = chains.map(c => String(c.evmChainId));

// Fetch latest TPS for all chains in one aggregation
const tpsRecords = await TPS.aggregate([
{ $match: { chainId: { $in: chainIds } } },
{ $sort: { chainId: 1, timestamp: -1 } },
{
$group: {
_id: '$chainId',
value: { $first: '$value' },
timestamp: { $first: '$timestamp' }
}
}
]);

// Create a map for O(1) lookup
const tpsMap = new Map(tpsRecords.map(r => [r._id, r]));

// Build response with chain info
const data = chains.map(chain => {
const tps = tpsMap.get(String(chain.evmChainId));
return {
evmChainId: chain.evmChainId,
subnetId: chain.subnetId,
chainName: chain.chainName,
tps: tps ? {
value: parseFloat(tps.value).toFixed(2),
timestamp: tps.timestamp
} : null
};
});

res.json({
success: true,
count: data.length,
data
});
} catch (error) {
logger.error('All TPS Error:', { error: error.message });
res.status(500).json({
success: false,
error: error.message
});
}
});

// Add new route for total network TPS
router.get('/tps/network/latest', async (req, res) => {
try {
Expand Down
Loading