Blocks data retrieval with Insight [v0.2.2-beta]

Blocks data retrieval with Insight [v0.2.2-beta]

What's Changed

TL;DR
Added a new /blocks endpoint to retrieve block data with filtering, sorting, and aggregation capabilities.

What changed?

  • Created a new /blocks endpoint in the API
  • Implemented block data retrieval with support for:
    • Filtering by chain ID and other block parameters
    • Sorting and pagination
    • Aggregation functions
    • Group by operations
  • Updated the storage interface to return QueryResult for block operations
  • Added block scanning functionality to handle database rows

How to test?

  1. Start the API server
  2. Make GET requests to /blocks with optional query parameters:
    • chainId: Specify the blockchain network
    • filter: Apply filters to block data
    • sort_by: Sort results by specific fields
    • sort_order: Choose ascending or descending order
    • page and limit: Control pagination
    • aggregate: Apply aggregation functions
    • group_by: Group results by specific fields

Why make this change?
To provide a standardized way to query and analyze block data from the blockchain, enabling users to retrieve block information with flexible filtering and aggregation options. This enhancement aligns with the existing transaction and event query capabilities of the API.

Why is this useful?
As an example, this feature allows users to easily fetch the earliest block number that meets a specific timestamp criterion. For instance, when constructing block ranges based on timestamps, this can help in determining the precise blocks that fall within certain time windows. This functionality is crucial for tasks such as historical data analysis, event tracking, or aligning blockchain queries with specific real-world dates.

Learn more about Insight and how to use it.
Insight is open source.