Skip to content

Commit

Permalink
fix: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
butonium committed Feb 14, 2024
1 parent 9b75b8e commit e05c11b
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 42 deletions.
17 changes: 6 additions & 11 deletions api/src/api_docs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{dto::ValidatorBondRecord, handlers::{
bonds, docs
}};
use crate::{
dto::ValidatorBondRecord,
handlers::{bonds, docs},
};
use utoipa::OpenApi;

#[derive(OpenApi)]
Expand All @@ -13,13 +14,7 @@ use utoipa::OpenApi;
url = "https://www.apache.org/licenses/LICENSE-2.0"
)
),
components(
schemas(ValidatorBondRecord),
schemas(bonds::BondsResponse),
),
paths(
docs::handler,
bonds::handler,
)
components(schemas(ValidatorBondRecord), schemas(bonds::BondsResponse),),
paths(docs::handler, bonds::handler,)
)]
pub struct ApiDoc;
4 changes: 1 addition & 3 deletions api/src/bin/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ async fn main() -> anyhow::Result<()> {
}
});

let context = Arc::new(RwLock::new(Context::new(
psql_client,
)?));
let context = Arc::new(RwLock::new(Context::new(psql_client)?));

let cors = warp::cors()
.allow_any_origin()
Expand Down
8 changes: 2 additions & 6 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ pub struct Context {
}

impl Context {
pub fn new(
psql_client: Client,
) -> anyhow::Result<Self> {
Ok(Self {
psql_client,
})
pub fn new(psql_client: Client) -> anyhow::Result<Self> {
Ok(Self { psql_client })
}
}

Expand Down
6 changes: 2 additions & 4 deletions api/src/data/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use tokio_postgres::Client;

use crate::dto::ValidatorBondRecord;

pub async fn get_bonds(
psql_client: &Client,
) -> anyhow::Result<Vec<ValidatorBondRecord>> {
pub async fn get_bonds(psql_client: &Client) -> anyhow::Result<Vec<ValidatorBondRecord>> {
let rows = psql_client
.query(
"
Expand All @@ -29,4 +27,4 @@ pub async fn get_bonds(
}

Ok(bonds)
}
}
2 changes: 1 addition & 1 deletion api/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod data;
pub mod data;
2 changes: 1 addition & 1 deletion api/src/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub struct ValidatorBondRecord {
pub authority: String,
pub revenue_share: Decimal,
pub epoch: u64,
}
}
18 changes: 9 additions & 9 deletions api/src/handlers/bonds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{context::WrappedContext, data::data::get_bonds, dto::ValidatorBondRecord};
use serde::{Deserialize, Serialize};
use warp::{reject::Reject, reply::{json, Reply}};
use warp::{
reject::Reject,
reply::{json, Reply},
};

#[derive(Serialize, Debug, utoipa::ToSchema)]
pub struct BondsResponse {
Expand All @@ -9,8 +12,7 @@ pub struct BondsResponse {

#[derive(Deserialize, Serialize, Debug, utoipa::IntoParams)]
#[into_params(parameter_in = Query)]
pub struct QueryParams {
}
pub struct QueryParams {}

#[derive(Debug)]
struct CustomError {
Expand All @@ -33,11 +35,9 @@ pub async fn handler(
context: WrappedContext,
) -> Result<impl Reply, warp::Rejection> {
match get_bonds(&context.read().await.psql_client).await {
Ok(bonds) => {
Ok(json(&BondsResponse { bonds }))
},
Err(_) => {
Err(warp::reject::custom(CustomError { message: "Failed to fetch bonds".into() }))
}
Ok(bonds) => Ok(json(&BondsResponse { bonds })),
Err(_) => Err(warp::reject::custom(CustomError {
message: "Failed to fetch bonds".into(),
})),
}
}
2 changes: 1 addition & 1 deletion api/src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod bonds;
pub mod docs;
pub mod docs;
6 changes: 3 additions & 3 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod handlers;
pub mod api_docs;
pub mod context;
pub mod data;
pub mod api_docs;
pub mod dto;
pub mod dto;
pub mod handlers;
4 changes: 1 addition & 3 deletions store/src/commands/bonds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use super::common::CommonStoreOptions;

const DEFAULT_CHUNK_SIZE: usize = 500;

pub async fn store_bonds(
options: CommonStoreOptions,
) -> anyhow::Result<()> {
pub async fn store_bonds(options: CommonStoreOptions) -> anyhow::Result<()> {
let (mut psql_client, psql_conn) =
tokio_postgres::connect(&options.postgres_url, NoTls).await?;

Expand Down

0 comments on commit e05c11b

Please sign in to comment.