feat: Added default config creation if not present
00b9a8ad
1 file(s) · +35 −3
| 74 | 74 | ||
| 75 | 75 | fn read_config() -> Result<Config, Box<dyn Error>> { |
|
| 76 | 76 | let home_dir = dirs::home_dir().ok_or("Could not find home directory")?; |
|
| 77 | + | let config_dir = home_dir.join(".config").join("walletfetch"); |
|
| 78 | + | let config_path = config_dir.join("config.toml"); |
|
| 79 | + | ||
| 80 | + | if !config_path.exists(){ |
|
| 81 | + | ||
| 82 | + | std::fs::create_dir_all(&config_dir)?; |
|
| 83 | + | ||
| 84 | + | let default_config = r#"# WalletFetch Configuration |
|
| 85 | + | # You can set a default address here (optional) |
|
| 86 | + | # address = "0x..." |
|
| 77 | 87 | ||
| 78 | - | let config_path = home_dir.join(".config").join("walletfetch").join("config.toml"); |
|
| 88 | + | [networks.1] |
|
| 89 | + | name = "Mainnet" |
|
| 90 | + | rpc_url = "https://eth.drpc.org" |
|
| 91 | + | ||
| 92 | + | [networks.1.tokens] |
|
| 93 | + | USDC = { address = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", decimals = 6 } |
|
| 79 | 94 | ||
| 80 | - | if !config_path.exists(){ |
|
| 81 | - | return Err(format!("Config file not found at {}", config_path.display()).into()); |
|
| 95 | + | [networks.42161] |
|
| 96 | + | name = "Arbitrum" |
|
| 97 | + | rpc_url = "https://arbitrum.drpc.org" |
|
| 98 | + | ||
| 99 | + | [networks.42161.tokens] |
|
| 100 | + | USDC = { address = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", decimals = 6 } |
|
| 101 | + | ||
| 102 | + | [networks.8453] |
|
| 103 | + | name = "Base" |
|
| 104 | + | rpc_url = "https://base.drpc.org" |
|
| 105 | + | ||
| 106 | + | [networks.8453.tokens] |
|
| 107 | + | USDC = { address = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", decimals = 6 } |
|
| 108 | + | "#; |
|
| 109 | + | ||
| 110 | + | std::fs::write(&config_path, default_config)?; |
|
| 111 | + | ||
| 112 | + | println!("Created default config at: {}", config_path.display()); |
|
| 113 | + | println!("You can edit this file to customize your networks and tokens."); |
|
| 82 | 114 | } |
|
| 83 | 115 | ||
| 84 | 116 | let config_content = std::fs::read_to_string(config_path)?; |