Skip to content

Commit

Permalink
Introduce basic service endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Nov 22, 2023
1 parent b8558b7 commit 2977384
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub async fn serve(state: GlobalState) {
let app = Router::new()
.route("/", get(root))
.route("/gateway", post(crate::gateway::endpoint::route))
.route("/update", post(crate::selfservice::endpoint::route))
.with_state(Arc::new(state))
.layer(CorsLayer::very_permissive());

Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use dotenvy::dotenv;
use ethers::signers::{LocalWallet, Signer};
use tracing::info;

pub mod ccip;
pub mod database;
pub mod gateway;
mod http;
pub mod ccip;
pub mod state;
pub mod utils;
pub mod gateway;
pub mod database;
pub mod selfservice;

#[tokio::main]
async fn main() {
Expand Down
44 changes: 44 additions & 0 deletions src/selfservice/endpoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::{collections::HashMap, sync::Arc};

use axum::{
extract::{Path, State},
response::IntoResponse,
Json,
};
use ethers::providers::namehash;
use tracing::info;

use crate::state::GlobalState;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateNamePayload {
name: String,
records: HashMap<String, Option<String>>,
addresses: HashMap<String, Option<String>>,
// Arbitrary auth payload
auth: String,
}

pub async fn route(
State(state): State<Arc<GlobalState>>,
Json(payload): Json<UpdateNamePayload>,
) -> impl IntoResponse {
info!("Update name: {:?}", payload);

if payload.auth != "yes" {
return "auth error";
}

let hash = namehash(&payload.name);

state
.db
.upsert(&hash.to_fixed_bytes().to_vec(), &payload.records, &payload.addresses)
.await;

// handle(request_payload, state)
// .await
// .map_err(|x| x.into_response())
"ok"
}
1 change: 1 addition & 0 deletions src/selfservice/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod endpoint;

0 comments on commit 2977384

Please sign in to comment.