UNPKG

blockchain-api

Version:

API utilities for interacting with the Exatechl2 blockchain

55 lines (54 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateBlockInsights = generateBlockInsights; /** * * @param {FormattedBlock} blockData * @returns {BlockInsight[]} */ function generateBlockInsights(blockData) { if (!blockData) return []; const insights = []; const gasUsage = blockData.gasUsedPercentage; if (gasUsage > 80) { insights.push({ icon: 'fa-fire', title: 'High Gas Usage', description: `This block has ${gasUsage.toFixed(1)}% gas utilization, which is higher than average. This indicates high demand on the network at this time. Compared to the last 100 blocks, this is in the top 10% of gas usage.` }); } else if (gasUsage < 30) { insights.push({ icon: 'fa-leaf', title: 'Low Gas Usage', description: `This block has only ${gasUsage.toFixed(1)}% gas utilization, which is lower than average. This indicates lower network congestion. Compared to the last 100 blocks, this is in the bottom 20% of gas usage.` }); } if (blockData.txCount > 40) { insights.push({ icon: 'fa-bolt', title: 'High Transaction Volume', description: `This block contains ${blockData.txCount} transactions, which is higher than the typical average of 30 transactions per block. This volume is in the top 15% of recent blocks.` }); } const blockSizeNumeric = blockData.sizeBytes ? blockData.sizeBytes / 1024 : 0; if (blockSizeNumeric > 1.5) { insights.push({ icon: 'fa-database', title: 'Large Block Size', description: `At ${blockData.size}, this block is larger than average, possibly due to complex transactions or contract interactions. This size is larger than 85% of blocks in the past hour.` }); } const blockTime = blockData.timestamp; const now = Date.now(); const minutesAgo = Math.floor((now - blockTime) / (60 * 1000)); if (minutesAgo < 5) { insights.push({ icon: 'fa-clock', title: 'Recent Block', description: 'This block was mined very recently, showing the latest network activity. It is among the most recent 1% of blocks.' }); } return insights; }