Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add create_remote_server macro #2033

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 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,57 @@ pub struct SequencerNodeServers {
wrapper_servers: WrapperServers,
}

/// A macro for creating a remote component server based on the component's execution mode.
/// Returns a remote server if the component is configured with Remote execution mode; otherwise,
/// returns None.
///
/// # Arguments
///
/// * `$execution_mode` - A reference to the component's execution mode, of type
/// `&ComponentExecutionMode`.
/// * `$local_client` - The local client to be used for the remote server initialization if the
/// execution mode is `Remote`.
/// * `$config` - The configuration for the remote server.
///
/// # Returns
///
/// An `Option<Box<RemoteComponentServer<LocalClientType, RequestType, ResponseType>>>` containing
/// the remote server if the execution mode is Remote, or None if the execution mode is Disabled,
/// LocalExecutionWithRemoteEnabled or LocalExecutionWithRemoteDisabled.
///
/// # Example
///
/// ```rust,ignore
/// let batcher_remote_server = create_remote_server!(
/// &config.components.batcher.execution_mode,
/// clients.get_gateway_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) => {
match *$execution_mode {
ComponentExecutionMode::Remote => {
let local_client = $local_client
.expect("Error: local client must be initialized in Remote execution mode.");
let config = $config
.as_ref()
.expect("Error: config must be initialized in Remote execution mode.");

Some(Box::new(RemoteComponentServer::new(local_client, config.clone())))
}
ComponentExecutionMode::LocalExecutionWithRemoteDisabled
| ComponentExecutionMode::LocalExecutionWithRemoteEnabled
| ComponentExecutionMode::Disabled => 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
Loading