From 22a6195eca28fd3c638e2f77ffa9cec59743327c Mon Sep 17 00:00:00 2001 From: Daniil Polyakov Date: Thu, 29 Jan 2026 22:34:27 +0300 Subject: [PATCH] Move BasicAuth to common::config and remove SequencerClient from IndexerCore --- common/src/communication/indexer.rs | 6 ---- common/src/config.rs | 55 +++++++++++++++++++++++++++++ common/src/lib.rs | 1 + common/src/sequencer_client.rs | 55 ++--------------------------- indexer/core/src/config.rs | 10 +++--- indexer/core/src/lib.rs | 13 +++---- sequencer_core/src/config.rs | 2 +- wallet/src/config.rs | 2 +- 8 files changed, 69 insertions(+), 75 deletions(-) delete mode 100644 common/src/communication/indexer.rs create mode 100644 common/src/config.rs diff --git a/common/src/communication/indexer.rs b/common/src/communication/indexer.rs deleted file mode 100644 index a0edc176..00000000 --- a/common/src/communication/indexer.rs +++ /dev/null @@ -1,6 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Message { - L2BlockFinalized { l2_block_height: u64 }, -} diff --git a/common/src/config.rs b/common/src/config.rs new file mode 100644 index 00000000..3850f08c --- /dev/null +++ b/common/src/config.rs @@ -0,0 +1,55 @@ +//! Common configuration structures and utilities. + +use std::str::FromStr; + +use logos_blockchain_common_http_client::BasicAuthCredentials; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BasicAuth { + pub username: String, + pub password: Option, +} + +impl std::fmt::Display for BasicAuth { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.username)?; + if let Some(password) = &self.password { + write!(f, ":{password}")?; + } + + Ok(()) + } +} + +impl FromStr for BasicAuth { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + let parse = || { + let mut parts = s.splitn(2, ':'); + let username = parts.next()?; + let password = parts.next().filter(|p| !p.is_empty()); + if parts.next().is_some() { + return None; + } + + Some((username, password)) + }; + + let (username, password) = parse().ok_or_else(|| { + anyhow::anyhow!("Invalid auth format. Expected 'user' or 'user:password'") + })?; + + Ok(Self { + username: username.to_string(), + password: password.map(|p| p.to_string()), + }) + } +} + +impl From for BasicAuthCredentials { + fn from(value: BasicAuth) -> Self { + BasicAuthCredentials::new(value.username, value.password) + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index b64e6ef9..21c0796d 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,4 +1,5 @@ pub mod block; +pub mod config; pub mod error; pub mod rpc_primitives; pub mod sequencer_client; diff --git a/common/src/sequencer_client.rs b/common/src/sequencer_client.rs index f25b451f..ee197a37 100644 --- a/common/src/sequencer_client.rs +++ b/common/src/sequencer_client.rs @@ -1,10 +1,9 @@ -use std::{collections::HashMap, ops::RangeInclusive, str::FromStr}; +use std::{collections::HashMap, ops::RangeInclusive}; use anyhow::Result; -use logos_blockchain_common_http_client::BasicAuthCredentials; use nssa_core::program::ProgramId; use reqwest::Client; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use serde_json::Value; use url::Url; @@ -13,6 +12,7 @@ use super::rpc_primitives::requests::{ GetGenesisIdRequest, GetGenesisIdResponse, GetInitialTestnetAccountsRequest, }; use crate::{ + config::BasicAuth, error::{SequencerClientError, SequencerRpcError}, rpc_primitives::{ self, @@ -28,55 +28,6 @@ use crate::{ transaction::{EncodedTransaction, NSSATransaction}, }; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BasicAuth { - pub username: String, - pub password: Option, -} - -impl std::fmt::Display for BasicAuth { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.username)?; - if let Some(password) = &self.password { - write!(f, ":{password}")?; - } - - Ok(()) - } -} - -impl FromStr for BasicAuth { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - let parse = || { - let mut parts = s.splitn(2, ':'); - let username = parts.next()?; - let password = parts.next().filter(|p| !p.is_empty()); - if parts.next().is_some() { - return None; - } - - Some((username, password)) - }; - - let (username, password) = parse().ok_or_else(|| { - anyhow::anyhow!("Invalid auth format. Expected 'user' or 'user:password'") - })?; - - Ok(Self { - username: username.to_string(), - password: password.map(|p| p.to_string()), - }) - } -} - -impl From for BasicAuthCredentials { - fn from(value: BasicAuth) -> Self { - BasicAuthCredentials::new(value.username, value.password) - } -} - #[derive(Clone)] pub struct SequencerClient { pub client: reqwest::Client, diff --git a/indexer/core/src/config.rs b/indexer/core/src/config.rs index 784f5840..486a00ac 100644 --- a/indexer/core/src/config.rs +++ b/indexer/core/src/config.rs @@ -2,25 +2,23 @@ use std::{fs::File, io::BufReader, path::Path}; use anyhow::{Context, Result}; use bedrock_client::BackoffConfig; -use common::sequencer_client::BasicAuth; +use common::config::BasicAuth; use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; use url::Url; #[derive(Debug, Clone, Serialize, Deserialize)] -/// ToDo: Expand if necessary -pub struct ClientConfig { +pub struct BedrockClientConfig { pub addr: Url, pub auth: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] -/// Note: For individual RPC requests we use Fibonacci backoff retry strategy pub struct IndexerConfig { pub resubscribe_interval_millis: u64, + /// For individual RPC requests we use Fibonacci backoff retry strategy. pub backoff: BackoffConfig, - pub bedrock_client_config: ClientConfig, - pub sequencer_client_config: ClientConfig, + pub bedrock_client_config: BedrockClientConfig, pub channel_id: ChannelId, } diff --git a/indexer/core/src/lib.rs b/indexer/core/src/lib.rs index 23909e29..e88f2057 100644 --- a/indexer/core/src/lib.rs +++ b/indexer/core/src/lib.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use anyhow::Result; use bedrock_client::BedrockClient; -use common::{block::HashableBlockData, sequencer_client::SequencerClient}; +use common::block::HashableBlockData; use futures::StreamExt; use log::info; use logos_blockchain_core::mantle::{ @@ -17,10 +17,9 @@ pub mod config; pub mod state; pub struct IndexerCore { - pub bedrock_client: BedrockClient, - pub sequencer_client: SequencerClient, - pub config: IndexerConfig, - pub state: IndexerState, + bedrock_client: BedrockClient, + config: IndexerConfig, + state: IndexerState, } impl IndexerCore { @@ -30,10 +29,6 @@ impl IndexerCore { config.bedrock_client_config.auth.clone().map(Into::into), config.bedrock_client_config.addr.clone(), )?, - sequencer_client: SequencerClient::new_with_auth( - config.sequencer_client_config.addr.clone(), - config.sequencer_client_config.auth.clone(), - )?, config, // No state setup for now, future task. state: IndexerState { diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 3d69e8af..b0dda3e6 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -5,7 +5,7 @@ use std::{ }; use anyhow::Result; -use common::sequencer_client::BasicAuth; +use common::config::BasicAuth; use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 8da28bce..2784267b 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -4,7 +4,7 @@ use std::{ }; use anyhow::{Context as _, Result}; -use common::sequencer_client::BasicAuth; +use common::common::BasicAuth; use key_protocol::key_management::{ KeyChain, key_tree::{