Skip to content

Commit

Permalink
Add relayers endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 11, 2023
1 parent 1b9b407 commit b0d0a0b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
38 changes: 34 additions & 4 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,46 @@ impl Database {
Ok(())
}

pub async fn get_relayers(&self) -> eyre::Result<Vec<RelayerInfo>> {
Ok(sqlx::query_as(
r#"
SELECT
id,
name,
chain_id,
key_id,
address,
nonce,
current_nonce,
max_inflight_txs,
gas_limits
FROM relayers
"#,
)
.fetch_all(&self.pool)
.await?)
}

pub async fn get_relayer(&self, id: &str) -> eyre::Result<RelayerInfo> {
Ok(sqlx::query_as(
r#"
SELECT id, name, chain_id, key_id, address, nonce, current_nonce, max_inflight_txs, gas_limits
SELECT
id,
name,
chain_id,
key_id,
address,
nonce,
current_nonce,
max_inflight_txs,
gas_limits
FROM relayers
WHERE id = $1
"#)
.bind(id)
.fetch_one(&self.pool).await?
"#,
)
.bind(id)
.fetch_one(&self.pool)
.await?)
}

pub async fn create_transaction(
Expand Down
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use thiserror::Error;
use tower_http::validate_request::ValidateRequestHeaderLayer;

use self::routes::relayer::{
create_relayer, create_relayer_api_key, get_relayer, relayer_rpc,
update_relayer,
create_relayer, create_relayer_api_key, get_relayer, get_relayers,
relayer_rpc, update_relayer,
};
use self::routes::transaction::{get_tx, get_txs, send_tx};
use crate::app::App;
Expand Down Expand Up @@ -77,6 +77,7 @@ pub async fn spawn_server(

let mut admin_routes = Router::new()
.route("/relayer", post(create_relayer))
.route("/relayers", get(get_relayers))
.route(
"/relayer/:relayer_id",
post(update_relayer).get(get_relayer),
Expand Down
10 changes: 10 additions & 0 deletions src/server/routes/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ pub async fn update_relayer(
Ok(())
}

#[tracing::instrument(skip(app))]
pub async fn get_relayers(
State(app): State<Arc<App>>,
Path(relayer_id): Path<String>,
) -> Result<Json<Vec<RelayerInfo>>, ApiError> {
let relayer_info = app.db.get_relayers().await?;

Ok(Json(relayer_info))
}

#[tracing::instrument(skip(app))]
pub async fn get_relayer(
State(app): State<Arc<App>>,
Expand Down

0 comments on commit b0d0a0b

Please sign in to comment.