-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CIL): add directories crate and data
This allows for logging transaction data including budgets/costs for later inspection.
- Loading branch information
1 parent
e0e104e
commit f528cc0
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use chrono::prelude::*; | ||
use directories::ProjectDirs; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("Failed to find project directories")] | ||
FiledToFindProjectDirs, | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
} | ||
|
||
pub fn project_dir() -> Result<directories::ProjectDirs, Error> { | ||
ProjectDirs::from("com", "stellar", "soroban-cli").ok_or(Error::FiledToFindProjectDirs) | ||
} | ||
|
||
pub fn write(prefix: &str, suffix: &str, data: impl AsRef<[u8]>) -> Result<(), Error> { | ||
let timestamp = Utc::now().format("%Y%m%d_%H%M%S"); | ||
let name = format!("{prefix}_{timestamp}{suffix}"); | ||
let file = project_dir()?.data_local_dir().join(name); | ||
Ok(std::fs::write(file, data)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters