Skip to content

Commit

Permalink
Merge pull request #78 from Jon-Becker/feat/dump
Browse files Browse the repository at this point in the history
feat: `heimdall dump`
  • Loading branch information
Jon-Becker authored Mar 16, 2023
2 parents d2feb1c + 1cc8523 commit 23c8956
Show file tree
Hide file tree
Showing 39 changed files with 1,706 additions and 28 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/pull_request_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Compile

- name: Build Binaries
working-directory: ./heimdall
run: cargo build --verbose
run: |
cargo clean
cargo build
- name: Run Tests
working-directory: ./heimdall
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Build Binaries
run: cargo build --release
run: |
cargo clean
cargo build --release
- name: Upload Binaries
uses: svenstaro/upload-release-action@v2
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/rust_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ env:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Compile
working-directory: ./heimdall
run: cargo build --verbose
Expand Down
95 changes: 91 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cache/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heimdall-cache"
version = "0.3.4"
version = "0.4.0"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
21 changes: 19 additions & 2 deletions cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub enum Subcommands {

#[clap(name = "ls", about = "Lists all cached objects in ~/.bifrost/cache")]
Ls(NoArguments),

#[clap(name = "size", about = "Prints the size of the cache in ~/.bifrost/cache")]
Size(NoArguments),
}


Expand Down Expand Up @@ -188,7 +191,7 @@ pub fn store_cache<T>(key: &str, value: T, expiry: Option<u64>) where T: Seriali
write_file(&cache_file.to_str().unwrap().to_string(), &binary_string);
}


#[allow(deprecated)]
pub fn cache(args: CacheArgs) -> Result<(), Box<dyn std::error::Error>> {
match args.sub {
Subcommands::Clean(_) => {
Expand All @@ -202,8 +205,22 @@ pub fn cache(args: CacheArgs) -> Result<(), Box<dyn std::error::Error>> {
for (i, key) in keys.iter().enumerate() {
println!("{i:>5} : {}", key);
}

},
Subcommands::Size(_) => {
let home = home_dir().unwrap();
let cache_dir = home.join(".bifrost").join("cache");
let mut size = 0;

for entry in cache_dir.read_dir().unwrap() {
let entry = entry.unwrap();
let path = entry.path();
let metadata = std::fs::metadata(path).unwrap();
size += metadata.len();
}

println!("Cached objects: {}", keys("*").len());
println!("Cache size: {}", prettify_bytes(size));
}
}

Ok(())
Expand Down
15 changes: 15 additions & 0 deletions cache/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ use std::{
io::{Write, Read}, process::Command, num::ParseIntError
};

pub fn prettify_bytes(bytes: u64) -> String {
if bytes < 1024 {
return format!("{} B", bytes);
} else if bytes < 1024 * 1024 {
let kb = bytes / 1024;
return format!("{} KB", kb);
} else if bytes < 1024 * 1024 * 1024 {
let mb = bytes / (1024 * 1024);
return format!("{} MB", mb);
} else {
let gb = bytes / (1024 * 1024 * 1024);
return format!("{} GB", gb);
}
}


pub fn write_file(_path: &String, contents: &String) -> Option<String> {
let path = std::path::Path::new(_path);
Expand Down
5 changes: 3 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heimdall-common"
version = "0.3.4"
version = "0.4.0"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand All @@ -19,4 +19,5 @@ ethers = { version = "=2.0.0" }
reqwest = { version = "0.11.11", features = ["blocking"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
heimdall-cache = { path = "./../cache" }
heimdall-cache = { path = "./../cache" }
crossbeam-channel = "0.5.7"
4 changes: 2 additions & 2 deletions common/src/ether/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod evm;
pub mod signatures;
pub mod solidity;
pub mod solidity;
pub mod evm;
4 changes: 4 additions & 0 deletions common/src/io/clipboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

pub fn copy_to_clipboard(_text: &str) {

}
4 changes: 2 additions & 2 deletions common/src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod logging;
pub mod file;

mod tests;
mod tests;
pub mod clipboard;
3 changes: 2 additions & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod ether;
pub mod constants;
pub mod io;
pub mod utils;
pub mod testing;
pub mod testing;
pub mod resources;
1 change: 1 addition & 0 deletions common/src/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod transpose;
Loading

0 comments on commit 23c8956

Please sign in to comment.