info.rs
Overview
The info.rs file defines a data structure representing server information in a GraphQL API context. This structure encapsulates various server metrics such as version, timestamps, latencies related to blocks, messages, and transactions, as well as configuration details like batch size and endpoint alternatives. The primary purpose is to provide clients with detailed status and metadata about the server's state and performance.
Structs
Info
A GraphQL SimpleObject struct designed to expose server information fields to API clients. It uses camelCase naming for GraphQL fields via the #[graphql(rename_fields = "camelCase")] attribute.
Fields
version: Option<String>The server's version string.
Example:
"0.68.0"
time: Option<f64>The current server time expressed as Unix time in milliseconds.
Calculated using
SystemTime::now()converted to milliseconds since the Unix epoch.
blocks_latency: Option<f64>Latency in milliseconds between the server's current time and the most recent block generation time.
Calculated as
server time - max(blocks.gen_utime * 1000).
messages_latency: Option<f64>Latency in milliseconds between the server's current time and the most recent message creation time.
Calculated as
server time - max(messages.created_at * 1000).
transactions_latency: Option<f64>Latency in milliseconds between the server's current time and the most recent transaction timestamp.
Calculated as
server time - max(transactions.now * 1000).
latency: Option<f64>The overall latency, defined as the maximum of
blocks_latency,messages_latency, andtransactions_latency.
last_block_time: Option<f64>Timestamp in milliseconds representing the most recent block time.
Defined as
max(blocks.gen_utime * 1000).
endpoints: Option<Vec<Option<String>>>A list of alternative server endpoints (URLs) that clients can connect to.
chain_order_boundary: Option<String>EXPERIMENTAL field representing a reliable upper boundary for pagination by the
chain_orderfield.This boundary helps ensure data consistency by marking a point before which data inserts are unlikely.
Marked as a work-in-progress feature.
remp_enabled: Option<bool>Indicates whether the
rempReceiptssubscription is enabled.Marked with GraphQL deprecation because it is unused in the AckiNacki network.
batch_size: Option<u16>Specifies the maximum number of records returned per request.
Defaults to a constant defined in the
defaultsmodule (defaults::QUERY_BATCH_SIZE).
Implementation Details
The
Infostruct derivesSimpleObjectfromasync_graphqlto automatically expose all fields in the GraphQL schema.It also derives
Cloneto allow duplication of instances.The Default trait is implemented to provide sensible default values:
versiondefaults to"0.68.0".timeis set to the current system time at the moment of instantiation.latencyis preset with a default value of5773.0ms.Other latency and time-related fields default to None.
endpointsdefaults to an empty vector.remp_enableddefaults tofalse.batch_sizeuses a default batch size constant from thedefaultsmodule.
Usage Example
use info::Info;
let server_info = Info::default();
println!("Server version: {:?}", server_info.version);
println!("Current time (ms): {:?}", server_info.time);
This struct is typically returned in GraphQL queries to provide clients with the server's current status and performance metrics.
Interaction with Other Modules
The
defaultsmodule is imported to obtain the default batch size constant (defaults::QUERY_BATCH_SIZE).The
async_graphqlcrate is used for GraphQL schema generation and serialization.System time utilities from Rust's standard library (
std::time::SystemTimeandUNIX_EPOCH) are used to compute current timestamps.This file acts as a data model layer for GraphQL endpoints that expose server metadata to clients, likely consumed by API resolvers or handlers elsewhere in the application.
Diagram
classDiagram
class Info {
+version: Option<String>
+time: Option<f64>
+blocks_latency: Option<f64>
+messages_latency: Option<f64>
+transactions_latency: Option<f64>
+latency: Option<f64>
+last_block_time: Option<f64>
+endpoints: Option<Vec<Option<String>>>
+chain_order_boundary: Option<String>
+remp_enabled: Option<bool>
+batch_size: Option<u16>
+default()
}
This diagram illustrates the Info struct with all its fields and the default constructor.
Notes on Implementation
Time fields are represented as floating-point numbers (f64) to accommodate millisecond precision.
Latency fields are optional, reflecting that these metrics might not always be available.
The
chain_order_boundaryis marked experimental, indicating ongoing development and potential future changes.The
remp_enabledfield is deprecated, signaling planned removal or lack of support in certain network contexts.The use of
Optionfor most fields allows partial information to be conveyed without requiring all data to be present.