trident_explorer/
config.rs1use solana_cli_config::{Config, CONFIG_FILE};
2use solana_client::rpc_client::RpcClient;
3use solana_sdk::commitment_config::CommitmentConfig;
4
5pub struct ExplorerConfig {
6 json_rpc_url: String,
7 rpc_client: RpcClient,
8}
9
10impl ExplorerConfig {
11 pub fn new() -> Self {
12 let json_rpc_url = if let Some(ref config_file) = *CONFIG_FILE {
13 Config::load(config_file).unwrap_or_default().json_rpc_url
14 } else {
15 Config::default().json_rpc_url
16 };
17
18 let rpc_client =
19 RpcClient::new_with_commitment(json_rpc_url.clone(), CommitmentConfig::confirmed());
20
21 ExplorerConfig {
24 json_rpc_url,
25 rpc_client,
26 }
27 }
28
29 pub fn json_rpc_url(&self) -> &String {
30 &self.json_rpc_url
31 }
32
33 pub fn rpc_client(&self) -> &RpcClient {
34 &self.rpc_client
35 }
36}
37
38impl Default for ExplorerConfig {
39 fn default() -> Self {
40 Self::new()
41 }
42}
43
44pub enum LogLevel {
45 ERROR,
46 WARN,
47 INFO,
48 DEBUG,
49 TRACE,
50}
51
52pub fn setup_logging(level: LogLevel) {
53 match level {
54 LogLevel::ERROR => solana_logger::setup_with_default("error"),
55 LogLevel::WARN => solana_logger::setup_with_default("warn"),
56 LogLevel::INFO => solana_logger::setup_with_default("info"),
57 LogLevel::DEBUG => solana_logger::setup_with_default("debug"),
58 LogLevel::TRACE => solana_logger::setup_with_default("trace"),
59 }
60}
61
62pub fn reset_logging() {
63 setup_logging(LogLevel::ERROR);
64}