From de939a9dbc1624110ab3439632076149dd611907 Mon Sep 17 00:00:00 2001 From: Danial Mehrjerdi Date: Fri, 6 Dec 2024 13:09:19 +0100 Subject: [PATCH] Add simple searcher schema --- Cargo.lock | 9 +++++++++ Cargo.toml | 2 ++ auction-server/Cargo.toml | 2 +- sdk/rust/Cargo.toml | 1 + sdk/rust/simple-searcher/Cargo.toml | 8 ++++++++ sdk/rust/simple-searcher/src/main.rs | 16 ++++++++++++++++ sdk/rust/src/lib.rs | 23 ++++++++++++++++------- 7 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 sdk/rust/simple-searcher/Cargo.toml create mode 100644 sdk/rust/simple-searcher/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 4899f091..9498554a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2584,6 +2584,15 @@ name = "express-relay-client" version = "0.1.1" dependencies = [ "express-relay-api-types", + "url", +] + +[[package]] +name = "express-relay-simple-searcher" +version = "0.1.0" +dependencies = [ + "anyhow", + "express-relay-client", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6c91a8bf..785f195b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ resolver = "2" members = [ "auction-server", "gas-oracle", + "sdk/rust/simple-searcher", "sdk/rust", ] exclude = ["vault-simulator", "contracts/svm"] @@ -23,6 +24,7 @@ solana-rpc-client = "2.0.13" solana-transaction-status = "2.0.13" solana-client = "2.0.13" email_address = "0.2.4" +anyhow = "1.0.75" # The curve25519-dalek crate is a dependency of solana-sdk. # This crate relies on a specific version of zeroize that is incompatible with many other packages. diff --git a/auction-server/Cargo.toml b/auction-server/Cargo.toml index 02494941..05399e3a 100644 --- a/auction-server/Cargo.toml +++ b/auction-server/Cargo.toml @@ -19,7 +19,7 @@ axum = { version = "0.7.5", features = ["ws", "tracing"] } axum-streams = { version = "0.10.0", features = ["json", "text"] } clap = { version = "4.4.4", features = ["derive", "env", "cargo"] } tracing = { version = "0.1.40", features = ["log"] } -anyhow = "1.0.75" +anyhow = { workspace = true } tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] } async-stream = "0.3.5" utoipa = { workspace = true, features = ["axum_extras"] } diff --git a/sdk/rust/Cargo.toml b/sdk/rust/Cargo.toml index d7169d62..efc3697e 100644 --- a/sdk/rust/Cargo.toml +++ b/sdk/rust/Cargo.toml @@ -8,3 +8,4 @@ license = "Apache-2.0" [dependencies] express-relay-api-types = { version = "0.0.0", path = "../../auction-server/api-types" } +url = "2.5.4" diff --git a/sdk/rust/simple-searcher/Cargo.toml b/sdk/rust/simple-searcher/Cargo.toml new file mode 100644 index 00000000..f72421b3 --- /dev/null +++ b/sdk/rust/simple-searcher/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "express-relay-simple-searcher" +version = "0.1.0" +edition = "2021" + +[dependencies] +express-relay-client = { path = ".." } +anyhow = { workspace = true } diff --git a/sdk/rust/simple-searcher/src/main.rs b/sdk/rust/simple-searcher/src/main.rs new file mode 100644 index 00000000..ec796007 --- /dev/null +++ b/sdk/rust/simple-searcher/src/main.rs @@ -0,0 +1,16 @@ +use { + anyhow::{ + anyhow, + Result, + }, + express_relay_client::Client, +}; + +fn main() -> Result<()> { + let client = Client::try_new("http://127.0.0.1:9000", Some("test")).map_err(|e| { + eprintln!("Failed to create client: {:?}", e); + anyhow!("Failed to create client") + })?; + client.test(); + Ok(()) +} diff --git a/sdk/rust/src/lib.rs b/sdk/rust/src/lib.rs index fdf01dd1..7dcfb558 100644 --- a/sdk/rust/src/lib.rs +++ b/sdk/rust/src/lib.rs @@ -1,15 +1,24 @@ +use url::Url; + pub struct Client { - pub host: String, + pub host: Url, + pub api_key: Option, +} + +#[derive(Debug)] +pub enum ClientError { + InvalidHost(String), } impl Client { - pub fn new(host: &str) -> Self { - Self { - host: host.to_string(), - } + pub fn try_new(host: &str, api_key: Option<&str>) -> Result { + Ok(Self { + host: Url::parse(host).map_err(|e| ClientError::InvalidHost(e.to_string()))?, + api_key: api_key.map(|s| s.to_string()), + }) } - pub fn test() { - println!("test"); + pub fn test(&self) { + println!("Testing client with host: {:?}", self.host); } }