By TxPipe

Querying the Backend API

Project Asteria provides a GraphQL API to query the state of the game. The primary query used is objectsInRadius, which retrieves objects within a specified radius around a given point.

Example Query

Below is an example of a query to get objects around the center point (0,0) with a radius of 10:

Example Response

A preview testnet GraphQL endpoint is available at https://dmtr_scrolls_v0_preview_1t9nhgnmxtpzrzm2gwv0723cu.scrolls-m0.demeter.run/graphql.

Implementation Details

The backend uses a SQL query with a Manhattan distance calculation to find objects within the specified radius. The query ensures that the objects are within the bounds defined by the radius and the center point.

Database and Projection

The database consists of UTXOs in the smart contract validators. These UTXOs are projected into a materialized view using Mumak, a PostgreSQL extension that allows developers to project or filter CBOR data within PostgreSQL. The generated materialized view is queried by the backend API as if it were a regular table. This enables efficient distance queries over CBOR data directly within PostgreSQL.