Skip to content

Commit

Permalink
chore: add create_remote_server macro
Browse files Browse the repository at this point in the history
commit-id:6442e09a
  • Loading branch information
nadin-Starkware committed Nov 13, 2024
1 parent 241a04d commit 128f242
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions crates/starknet_sequencer_node/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,53 @@ pub struct SequencerNodeServers {
wrapper_servers: WrapperServers,
}

/// A macro for creating a component server, determined by the component's execution mode.
/// Returns a remote server if the component is run with remote configuration, otherwise None.
///
/// # Arguments
///
/// * $execution_mode - A reference to the component's execution mode, i.e., type
/// &ComponentExecutionMode.
/// * $local_client - The local client to be used for the remote server initialization if the
/// execution mode is enabled(Remote).
/// * $config - The remote server configuration.
///
/// # Returns
///
/// An Option<Box<RemoteComponentServer<LocalClientType, RequestType, ResponseType>>> containing the
/// server if the execution mode is enabled(Remote), or None if the execution mode is Disabled.
///
/// # Example
///
/// ```rust,ignore
/// let batcher_remote_server = create_remote_server!(
/// &config.components.batcher.execution_mode,
/// local_client,
/// config.remote_server_config
/// );
/// match batcher_remote_server {
/// Some(server) => println!("Remote server created: {:?}", server),
/// None => println!("Remote server not created because the execution mode is not remote."),
/// }
/// ```
#[macro_export]
macro_rules! create_remote_server {
($execution_mode:expr, $local_client:expr, $config:expr, $client_type:ty) => {
match *$execution_mode {
ComponentExecutionMode::Remote => {
if let (Some(local_client), Some(config)) = ($local_client, $config) {
// Cast local_client to the specified generic type
let typed_client: Arc<$client_type> = local_client;
Some(Box::new(RemoteComponentServer::new(typed_client, config)))
} else {
None
}
}
_ => None,
}
};
}

/// A macro for creating a component server, determined by the component's execution mode. Returns a
/// local server if the component is run locally, otherwise None.
///
Expand Down

0 comments on commit 128f242

Please sign in to comment.