Skip to content

Commit 5a4bf28

Browse files
committed
Create default config.toml
1 parent 21f24db commit 5a4bf28

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tuktuk-crank-turner/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod cache;
3232
mod metrics;
3333
pub mod profitability;
3434
pub mod settings;
35+
pub mod setup;
3536
mod sync;
3637
pub mod task_completion_processor;
3738
pub mod task_context;
@@ -309,6 +310,9 @@ impl Cli {
309310

310311
#[tokio::main]
311312
async fn main() -> anyhow::Result<()> {
313+
// Create default config if it doesn't exist
314+
setup::create_config_if_missing()?;
315+
312316
let cli = Cli::parse();
313317
cli.run().await
314318
}

tuktuk-crank-turner/src/setup.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use anyhow::Result;
2+
use std::fs;
3+
use std::path::PathBuf;
4+
5+
const DEFAULT_CONFIG: &str = r#"# RPC endpoint URL
6+
rpc_url = "https://api.mainnet-beta.solana.com"
7+
8+
# Path to your Solana keypair file
9+
key_path = "~/.config/solana/id.json"
10+
11+
# Minimum crank fee in lamports
12+
min_crank_fee = 10000
13+
"#;
14+
15+
pub fn get_default_config_path() -> Option<PathBuf> {
16+
let home_dir = std::env::var("HOME")
17+
.or_else(|_| std::env::var("USERPROFILE"))
18+
.ok()?;
19+
20+
Some(
21+
PathBuf::from(home_dir)
22+
.join(".config")
23+
.join("helium")
24+
.join("cli")
25+
.join("tuktuk-crank-turner")
26+
.join("config.toml"),
27+
)
28+
}
29+
30+
fn write_default_config(config_path: &PathBuf) -> Result<()> {
31+
if let Some(parent) = config_path.parent() {
32+
fs::create_dir_all(parent)?;
33+
}
34+
35+
fs::write(config_path, DEFAULT_CONFIG)?;
36+
37+
Ok(())
38+
}
39+
40+
pub fn create_config_if_missing() -> Result<()> {
41+
let Some(config_path) = get_default_config_path() else {
42+
eprintln!("Warning: Could not determine home directory. Skipping config creation.");
43+
return Ok(());
44+
};
45+
46+
if !config_path.exists() {
47+
write_default_config(&config_path)?;
48+
}
49+
50+
Ok(())
51+
}

0 commit comments

Comments
 (0)