Skip to content

Commit

Permalink
feat: normalize contract addr
Browse files Browse the repository at this point in the history
  • Loading branch information
remiroyc committed Apr 12, 2024
1 parent a29fbf0 commit 4d9dcad
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions apps/indexer/src/handlers/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,54 @@ 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);

impl Serialize for RequestWrapper {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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,
Expand Down Expand Up @@ -108,9 +123,12 @@ pub async fn contract_stats(
Path(eth_contract_address): Path<String>,
state: State<AppState>,
) -> Result<Json<Stats>, (StatusCode, String)> {
let contract_address = normalize_hex(&eth_contract_address)
.expect("Contract address shall be an hexadecimal string");

let total_tokens_bridged_on_starknet = state
.store
.get_total_tokens_bridged_on_starknet(&eth_contract_address)
.get_total_tokens_bridged_on_starknet(&contract_address)
.await
.unwrap_or(0);

Expand Down

0 comments on commit 4d9dcad

Please sign in to comment.