diff --git a/src/serve/builder.rs b/src/serve/builder.rs index e1d0bd0..f78987d 100644 --- a/src/serve/builder.rs +++ b/src/serve/builder.rs @@ -4,9 +4,7 @@ use serde::Serialize; use sqlx::{PgPool, Row}; use std::collections::HashMap; -use crate::env::ToNetwork; - -use super::{env::APP_CONFIG, internal_error, ApiResponse, AppState}; +use super::{internal_error, ApiResponse, AppState}; #[derive(Serialize, Clone)] #[serde(rename_all = "camelCase")] @@ -27,20 +25,17 @@ pub struct PubkeyBlockCount { } async fn fetch_pubkey_block_counts(relay_pool: &PgPool) -> Result> { - let query = format!( - " + let query = " SELECT builder_pubkey AS pubkey, COUNT(*) AS block_count FROM - {}_payload_delivered + payload_delivered GROUP BY builder_pubkey - ", - &APP_CONFIG.env.to_network().to_string() - ); + "; - sqlx::query(&query) + sqlx::query(query) .fetch_all(relay_pool) .await .map(|rows| { diff --git a/src/serve/payload.rs b/src/serve/payload.rs index 606dc38..592fc40 100644 --- a/src/serve/payload.rs +++ b/src/serve/payload.rs @@ -3,9 +3,7 @@ use chrono::{DateTime, TimeZone, Utc}; use serde::Serialize; use sqlx::Row; -use crate::env::ToNetwork; - -use super::{internal_error, ApiResponse, AppState, APP_CONFIG}; +use super::{internal_error, ApiResponse, AppState}; #[derive(Serialize)] #[serde(rename_all = "camelCase")] @@ -29,17 +27,14 @@ pub struct PayloadStatsBody { } pub async fn delivered_payloads(State(state): State) -> ApiResponse { - let query = format!( - " + let query = " select inserted_at, block_number, (value / 10^18) as value - from {}_payload_delivered + from payload_delivered order by inserted_at desc limit 30 - ", - &APP_CONFIG.env.to_network().to_string() - ); + "; - sqlx::query(&query) + sqlx::query(query) .fetch_all(&state.relay_db_pool) .await .map(|rows| { @@ -58,17 +53,14 @@ pub async fn delivered_payloads(State(state): State) -> ApiResponse) -> ApiResponse { - let query = format!( - " - select count(*) as count, - sum(value) / 10^18 as value, - (select min(inserted_at) from {network}_payload_delivered) as first_payload_at - from {network}_payload_delivered - ", - network = &APP_CONFIG.env.to_network().to_string(), - ); + let query = " + select count(*) as count, + sum(value) / 10^18 as value, + (select min(inserted_at) from payload_delivered) as first_payload_at + from payload_delivered + "; - sqlx::query(&query) + sqlx::query(query) .fetch_one(&state.relay_db_pool) .await .map(|row| { @@ -82,19 +74,16 @@ pub async fn payload_stats(State(state): State) -> ApiResponse) -> ApiResponse { - let query = format!( - " + let query = " select inserted_at, - block_number, - (value / 10^18) as value - from {}_payload_delivered + block_number, + (value / 10^18) as value + from payload_delivered order by value desc limit 10 - ", - &APP_CONFIG.env.to_network().to_string() - ); + "; - sqlx::query(&query) + sqlx::query(query) .fetch_all(&state.relay_db_pool) .await .map(|rows| { diff --git a/src/serve/validator.rs b/src/serve/validator.rs index d02953f..a71fa69 100644 --- a/src/serve/validator.rs +++ b/src/serve/validator.rs @@ -21,13 +21,12 @@ pub struct ValidatorStatsBody { } async fn get_registered_validator_count(relay_pool: &PgPool) -> Result { - sqlx::query(&format!( + sqlx::query( " - select count(*) as validator_count - from (select distinct pubkey from {}_validator_registration) as sq + select count(*) as validator_count + from (select distinct pubkey from validator_registration) as sq ", - &APP_CONFIG.env.to_network().to_string() - )) + ) .fetch_one(relay_pool) .await .map(|row| row.get::("validator_count")) @@ -56,16 +55,13 @@ pub async fn check_validator_registration( State(state): State, Path(pubkey): Path, ) -> ApiResponse { - let query = format!( - " - select exists ( - select pubkey from {}_validator_registration where pubkey = $1 - ) - ", - &APP_CONFIG.env.to_network().to_string() - ); + let query = " + select exists ( + select pubkey from validator_registration where pubkey = $1 + ) + "; - sqlx::query(&query) + sqlx::query(query) .bind(pubkey) .fetch_one(&state.relay_db_pool) .await