Skip to content

Commit

Permalink
Introduce view route
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Nov 22, 2023
1 parent fc812fa commit 9479799
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ This is a Rust implementation of the CCIP gateway. It allows you to issue unlimi
### Run the gateway
The gateway is just a docker container / standalone binary. You can run it with docker-compose or just run the binary.

```yaml
todo: running the gateway
```
### Deploy a Resolver
Expand Down
16 changes: 16 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,20 @@ impl Database {
map
})
}

pub async fn get_all(&self, node: &[u8]) -> (HashMap<String, Option<String>>, HashMap<String, Option<String>>) {
let x = self
.client
.query_one(
"SELECT records, addresses FROM ens_data WHERE node = $1",
&[&node],
)
.await
.unwrap();

let records = x.get::<_, HashMap<String, Option<String>>>(0);
let addresses = x.get::<_, HashMap<String, Option<String>>>(1);

(records, addresses)
}
}
1 change: 1 addition & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub async fn serve(state: GlobalState) {
.route("/", get(root))
.route("/gateway", post(crate::gateway::endpoint::route))
.route("/update", post(crate::selfservice::endpoint::route))
.route("/view/:name", get(crate::selfservice::view::route))
.with_state(Arc::new(state))
.layer(CorsLayer::very_permissive());

Expand Down
1 change: 1 addition & 0 deletions src/selfservice/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod endpoint;
pub mod view;
33 changes: 33 additions & 0 deletions src/selfservice/view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::{collections::HashMap, sync::Arc};

use crate::state::GlobalState;
use axum::{
extract::{Path, State},
response::IntoResponse,
Json,
};
use ethers::providers::namehash;
use serde::{Deserialize, Serialize};
use tracing::info;

#[derive(Debug, Serialize, Deserialize)]
pub struct ViewPayload {
name: String,
records: HashMap<String, Option<String>>,
addresses: HashMap<String, Option<String>>,
}

pub async fn route(
Path(name): Path<String>,
State(state): State<Arc<GlobalState>>,
) -> impl IntoResponse {
let hash = namehash(&name);

let (records, addresses) = state.db.get_all(hash.to_fixed_bytes().as_ref()).await;

Json(ViewPayload {
name,
records,
addresses,
})
}

0 comments on commit 9479799

Please sign in to comment.