diff --git a/apps/indexer/src/handlers/requests.rs b/apps/indexer/src/handlers/requests.rs index 8b3a06e5..2729561f 100644 --- a/apps/indexer/src/handlers/requests.rs +++ b/apps/indexer/src/handlers/requests.rs @@ -3,16 +3,18 @@ use axum::{ http::StatusCode, Json, }; -use serde::{Deserialize, Serialize}; use serde::ser::SerializeStruct; +use serde::{Deserialize, Serialize}; use super::AppState; -use crate::{storage::{ - protocol::ProtocolParser, - store::{EventStore, RequestStore}, - Event, Request, -}, utils::{denormalize_hex, normalize_hex}}; - +use crate::{ + storage::{ + protocol::ProtocolParser, + store::{EventStore, RequestStore}, + Event, Request, + }, + utils::{denormalize_hex, normalize_hex}, +}; #[derive(Debug, Deserialize)] pub struct RequestWrapper(pub Request); @@ -20,22 +22,35 @@ pub struct RequestWrapper(pub Request); impl Serialize for RequestWrapper { fn serialize(&self, serializer: S) -> Result where - S: serde::Serializer { + S: serde::Serializer, + { let RequestWrapper(ref inner) = *self; let mut state = serializer.serialize_struct("Request", 7)?; state.serialize_field("hash", &inner.hash)?; state.serialize_field("chain_src", &inner.chain_src)?; - state.serialize_field("from", &denormalize_hex(&inner.from).expect("Failed to denormalize 'from'"))?; - state.serialize_field("to", &denormalize_hex(&inner.to).expect("Failed to denormalize 'to'"))?; - state.serialize_field("collection_src", &denormalize_hex(&inner.collection_src).expect("Failed to denormalize 'collection_src'"))?; - state.serialize_field("collection_dst", &denormalize_hex(&inner.collection_dst).expect("Failed to denormalize 'collection_dst'"))?; + state.serialize_field( + "from", + &denormalize_hex(&inner.from).expect("Failed to denormalize 'from'"), + )?; + state.serialize_field( + "to", + &denormalize_hex(&inner.to).expect("Failed to denormalize 'to'"), + )?; + state.serialize_field( + "collection_src", + &denormalize_hex(&inner.collection_src) + .expect("Failed to denormalize 'collection_src'"), + )?; + state.serialize_field( + "collection_dst", + &denormalize_hex(&inner.collection_dst) + .expect("Failed to denormalize 'collection_dst'"), + )?; state.serialize_field("content", &inner.content)?; state.end() } } - - #[derive(Debug, Serialize, Deserialize)] pub struct RequestInfo { req: RequestWrapper, @@ -108,9 +123,12 @@ pub async fn contract_stats( Path(eth_contract_address): Path, state: State, ) -> Result, (StatusCode, String)> { + let contract_address = normalize_hex(ð_contract_address) + .expect("Contract address shall be an hexadecimal string"); + let total_tokens_bridged_on_starknet = state .store - .get_total_tokens_bridged_on_starknet(ð_contract_address) + .get_total_tokens_bridged_on_starknet(&contract_address) .await .unwrap_or(0);