forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
38 lines (33 loc) · 948 Bytes
/
Copy pathmod.rs
File metadata and controls
38 lines (33 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::fs;
use std::path::PathBuf;
use anyhow::Result;
pub fn get_config_dir() -> PathBuf {
let mut path = dirs_next::home_dir().unwrap_or_else(|| PathBuf::from("."));
path.push(".txio");
if !path.exists() {
fs::create_dir_all(&path).ok();
}
path
}
pub fn save_current_chain(chain: &str) -> Result<()> {
let mut path = get_config_dir();
path.push("current_chain");
fs::write(path, chain)?;
Ok(())
}
pub fn get_current_chain() -> Option<String> {
let mut path = get_config_dir();
path.push("current_chain");
fs::read_to_string(path).ok().map(|s| s.trim().to_string())
}
pub fn save_token(token: &str) -> Result<()> {
let mut path = get_config_dir();
path.push("token");
fs::write(path, token)?;
Ok(())
}
pub fn get_token() -> Option<String> {
let mut path = get_config_dir();
path.push("token");
fs::read_to_string(path).ok().map(|s| s.trim().to_string())
}