1#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
2pub struct Config {
3 pub credentials_home_dir: std::path::PathBuf,
4 pub network_connection: linked_hash_map::LinkedHashMap<String, NetworkConfig>,
5}
6
7impl Default for Config {
8 fn default() -> Self {
9 let home_dir = dirs::home_dir().expect("Impossible to get your home dir!");
10 let mut credentials_home_dir = std::path::PathBuf::from(&home_dir);
11 credentials_home_dir.push(".unc-credentials");
12
13 let mut network_connection = linked_hash_map::LinkedHashMap::new();
14 network_connection.insert(
15 "mainnet".to_string(),
16 NetworkConfig {
17 network_name: "mainnet".to_string(),
18 rpc_url: "http://16.78.8.159:3030".parse().unwrap(),
19 wallet_url: "https://app.wallet.com/".parse().unwrap(),
20 explorer_transaction_url: "https://explorer.unc.org/transactions/".parse().unwrap(),
21 rpc_api_key: None,
22 linkdrop_account_id: Some("unc".parse().unwrap()),
23 faucet_url: None,
24 meta_transaction_relayer_url: None,
25 },
26 );
27 network_connection.insert(
28 "testnet".to_string(),
29 NetworkConfig {
30 network_name: "testnet".to_string(),
31 rpc_url: "http://108.136.139.238:3030".parse().unwrap(),
32 wallet_url: "https://testnet.wallet.com/".parse().unwrap(),
33 explorer_transaction_url: "https://explorer.testnet.unc.org/transactions/"
34 .parse()
35 .unwrap(),
36 rpc_api_key: None,
37 linkdrop_account_id: Some("testnet".parse().unwrap()),
38 faucet_url: Some("https://helper.unc.com/account".parse().unwrap()),
39 meta_transaction_relayer_url: None,
40 },
41 );
42 network_connection.insert(
43 "custom".to_string(),
44 NetworkConfig {
45 network_name: "betanet".to_string(),
46 rpc_url: "http://127.0.0.1:3034".parse().unwrap(),
47 wallet_url: "https://testnet.wallet.com/".parse().unwrap(),
48 explorer_transaction_url: "https://explorer.testnet.unc.org/transactions/"
49 .parse()
50 .unwrap(),
51 rpc_api_key: None,
52 linkdrop_account_id: Some("testnet".parse().unwrap()),
53 faucet_url: Some("https://helper.unc.com/account".parse().unwrap()),
54 meta_transaction_relayer_url: None,
55 },
56 );
57 Self {
58 credentials_home_dir,
59 network_connection,
60 }
61 }
62}
63
64impl Config {
65 pub fn network_names(&self) -> Vec<String> {
66 self.network_connection
67 .iter()
68 .map(|(_, network_config)| network_config.network_name.clone())
69 .collect()
70 }
71}
72
73#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
74pub struct NetworkConfig {
75 pub network_name: String,
76 pub rpc_url: url::Url,
77 pub rpc_api_key: Option<crate::types::api_key::ApiKey>,
78 pub wallet_url: url::Url,
79 pub explorer_transaction_url: url::Url,
80 pub linkdrop_account_id: Option<unc_primitives::types::AccountId>,
81 pub faucet_url: Option<url::Url>,
82 pub meta_transaction_relayer_url: Option<url::Url>,
83}
84
85impl NetworkConfig {
86 pub fn json_rpc_client(&self) -> unc_jsonrpc_client::JsonRpcClient {
87 let mut json_rpc_client = unc_jsonrpc_client::JsonRpcClient::connect(self.rpc_url.as_ref());
88 if let Some(rpc_api_key) = &self.rpc_api_key {
89 json_rpc_client =
90 json_rpc_client.header(unc_jsonrpc_client::auth::ApiKey::from(rpc_api_key.clone()))
91 };
92 json_rpc_client
93 }
94}