blueprint_manager/sdk/
entry.rs1use futures::Future;
2use gadget_io::{KeystoreConfig, SupportedChains};
3use tracing_subscriber::EnvFilter;
4
5pub fn keystore_from_base_path(
6 base_path: &std::path::Path,
7 chain: SupportedChains,
8 keystore_password: Option<String>,
9) -> KeystoreConfig {
10 KeystoreConfig::Path {
11 path: base_path
12 .join("chains")
13 .join(chain.to_string())
14 .join("keystore"),
15 password: keystore_password.map(|s| s.into()),
16 }
17}
18
19pub trait SendFuture<'a, T>: Send + Future<Output = T> + 'a {}
20impl<'a, F: Send + Future<Output = T> + 'a, T> SendFuture<'a, T> for F {}
21
22pub fn setup_blueprint_manager_logger(
24 verbose: u8,
25 pretty: bool,
26 filter: &str,
27) -> color_eyre::Result<()> {
28 use tracing::Level;
29 let log_level = match verbose {
30 0 => Level::ERROR,
31 1 => Level::WARN,
32 2 => Level::INFO,
33 3 => Level::DEBUG,
34 _ => Level::TRACE,
35 };
36 let env_filter =
37 EnvFilter::from_default_env().add_directive(format!("{filter}={log_level}").parse()?);
38 let logger = tracing_subscriber::fmt()
39 .with_target(false)
40 .with_level(true)
41 .with_line_number(false)
42 .without_time()
43 .with_max_level(log_level)
44 .with_env_filter(env_filter);
45 if pretty {
46 let _ = logger.pretty().try_init();
47 } else {
48 let _ = logger.compact().try_init();
49 }
50
51 Ok(())
54}