11//! Agent's indexer module - uses planetscale to index
22//! metadata about the Ethereum blobs stored as ANS-104 offchain
33//! DataItems on Load's HyperBEAM S3 node.
4- //!
4+ //!
55//! Functionalities:
66//! - Map a blob versioned hash to the corresponding offchain ANS-104 DataItem ID
77//! - Get the DataItem ID for a given blob versioned hash
@@ -14,19 +14,25 @@ use planetscale_driver::{query, Database, PSConnection};
1414use serde:: { Deserialize , Serialize } ;
1515use serde_json:: Value ;
1616
17+ /// Structure used by the indexer to parse the metadata's pair.
1718#[ derive( Debug , Default , Database , Serialize , Deserialize ) ]
1819pub ( crate ) struct GetVersionedHash {
20+ /// Blob's versioned hash
1921 pub versioned_hash : String ,
22+ /// ~s3@1.0 ANS-104 DataItem ID
2023 pub arweave_txid : String ,
2124}
22-
25+ /// Structure to parse the indexer's stats response.
2326#[ derive( Debug , Default , Database , Serialize , Deserialize ) ]
2427pub ( crate ) struct GetIndexerStats {
28+ /// Latest processed blob's versioned hash
2529 pub versioned_hash : String ,
30+ /// Latest processed blob's DataItem ID
2631 pub arweave_txid : String ,
32+ /// Latest processed Etehreum block number containing blobs
2733 pub ethereum_block_number : u64 ,
2834}
29-
35+ /// Initialize Planetscale connection
3036async fn ps_init ( ) -> PSConnection {
3137 let host = get_env_var ( "DATABASE_HOST" ) . unwrap ( ) ;
3238 let username = get_env_var ( "DATABASE_USERNAME" ) . unwrap ( ) ;
@@ -36,7 +42,8 @@ async fn ps_init() -> PSConnection {
3642
3743 conn
3844}
39-
45+ /// Insert the pair of metadata consisting of blob's versioned hash, its
46+ /// corresponding offchain DataItem ID, and the carrier ethereum block number.
4047pub async fn insert_kv (
4148 versioned_hash : & str ,
4249 arweave_txid : & str ,
@@ -53,7 +60,7 @@ pub async fn insert_kv(
5360
5461 Ok ( res)
5562}
56-
63+ /// Get the metadata pair (versioned hash, DataItem ID) for a given blob's versioned hash.
5764pub async fn get_versioned_hash_value ( versioned_hash : & str ) -> Result < Value , Error > {
5865 let client = ps_init ( ) . await ;
5966
@@ -66,7 +73,7 @@ pub async fn get_versioned_hash_value(versioned_hash: &str) -> Result<Value, Err
6673
6774 Ok ( serde_json:: to_value ( res) ?)
6875}
69-
76+ /// Get the latest processed Ethereum block number that contains an EIP-4844 tx.
7077pub async fn get_latest_block_id ( ) -> u64 {
7178 let client = ps_init ( ) . await ;
7279 let res: u64 =
@@ -76,7 +83,8 @@ pub async fn get_latest_block_id() -> u64 {
7683 . unwrap_or ( FIRST_ETH_L1_EIP4844_BLOCK ) ;
7784 return res;
7885}
79-
86+ /// Get the indexer's stats - it returns the latest fields that contains
87+ /// a blob (a block with EIP-4844 tx).
8088pub async fn get_indexer_stats ( ) -> Result < Value , Error > {
8189 let client = ps_init ( ) . await ;
8290 let res: GetIndexerStats = query ( "SELECT versioned_hash, arweave_txid, ethereum_block_number FROM blobscan_arweave_mapping WHERE ethereum_block_number = (SELECT MAX(ethereum_block_number) FROM blobscan_arweave_mapping) LIMIT 1;" ) . fetch_one ( & client) . await . unwrap ( ) ;
0 commit comments