-
Notifications
You must be signed in to change notification settings - Fork 73
feat: add new report cmd #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new report command to generate comprehensive blockchain analysis reports for Ethereum-compatible chains. The command fetches block and transaction data via RPC, calculates statistics, and outputs results in JSON, HTML, or PDF format with support for concurrent requests and rate limiting.
Key changes:
- New report command with JSON/HTML/PDF output formats
- Concurrent block fetching (configurable, default 10 workers) with rate limiting (default 4 req/s)
- Comprehensive metrics including transaction counts, gas usage, unique addresses, and top-10 analyses
- HTML visualizations with SVG charts and interactive tooltips
- PDF generation using chromedp for headless browser rendering
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod / go.sum | Added chromedp dependencies for PDF generation and viper v1.19.0 (moved from direct to indirect dependency) with related transitive dependency version adjustments |
| cmd/root.go | Registered the new report command in the CLI |
| cmd/report/report.go | Core implementation: flag validation, concurrent RPC fetching with rate limiting, block/transaction data processing, and output generation |
| cmd/report/types.go | Data structures for report, summary statistics, block info, transaction info, and top-10 analyses |
| cmd/report/html.go | HTML generation functions including stat cards, SVG line charts for transactions and gas usage, and top-10 tables |
| cmd/report/pdf.go | PDF generation using chromedp to render HTML to PDF with page settings |
| cmd/report/template.html | HTML template with embedded CSS for styling and JavaScript for chart tooltips |
| cmd/report/usage.md | Documentation covering features, usage examples, and report contents |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace time.After() with time.NewTimer() in the PDF generation sleep logic to prevent goroutine leaks when the context is cancelled before the timer expires. The timer is now properly stopped via defer.
Restructure the error message to put context before the wrapped error (%w) instead of after it. The previous format with newlines after %w would produce malformed output. The new single-line format properly wraps the error while providing clear context about Chrome/Chromium requirements.
Move github.com/spf13/viper from a separate require block back to the main require block where it belongs. This restores consistency with the go.mod structure in the main branch. The viper dependency is a direct dependency used for configuration management and should be grouped with other direct dependencies like cobra and pflag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for blockNum := report.StartBlock; blockNum <= report.EndBlock; blockNum++ { | ||
| blockChan <- blockNum | ||
| } |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential infinite loop if report.EndBlock is math.MaxUint64. The loop condition checks blockNum less than or equal to report.EndBlock, so if report.EndBlock is math.MaxUint64, the loop will continue indefinitely when blockNum wraps around after incrementing from math.MaxUint64. Consider validating that the block range is reasonable before entering this loop, or add overflow checking to the loop increment.
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| // Allocate a new browser context | ||
| ctx, cancelChrome := chromedp.NewContext(ctx) | ||
| defer cancelChrome() | ||
|
|
||
| var buf []byte | ||
| err := chromedp.Run(ctx, |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context shadowing issue: the variable 'ctx' is reassigned on line 26, which shadows the parent context created on line 22. This means the timeout context from line 22 is no longer directly accessible. While the new context is derived from the timeout context (so the timeout still applies), this pattern can be confusing and error-prone. Consider using different variable names to make the relationship clearer, such as 'timeoutCtx' and 'chromeCtx'.
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | |
| defer cancel() | |
| // Allocate a new browser context | |
| ctx, cancelChrome := chromedp.NewContext(ctx) | |
| defer cancelChrome() | |
| var buf []byte | |
| err := chromedp.Run(ctx, | |
| timeoutCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | |
| defer cancel() | |
| // Allocate a new browser context derived from the timeout context | |
| chromeCtx, cancelChrome := chromedp.NewContext(timeoutCtx) | |
| defer cancelChrome() | |
| var buf []byte | |
| err := chromedp.Run(chromeCtx, |
closes https://github.com/0xPolygon/devtools/issues/479
Adds a new report command to generate comprehensive blockchain analysis reports for Ethereum-compatible chains. Supports JSON, HTML, and PDF output formats with statistics, visualizations, and performance optimizations.
Features
Usage
JSON
HTML
PDF