-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to clear etherscan cache #1807
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b19431
Separate cache layout into "rpc" and "etherscan" subdirectories for b…
jaeaster ef4f1aa
Add option --etherscan to "forge cache clean" which results in only d…
jaeaster 7b7e3e3
Display the etherscan cache with 'forge cache ls'
jaeaster 89a6ec6
--etherscan and --blocks options are mutually exclusive when running …
jaeaster File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -193,14 +193,24 @@ pub struct Cache { | |
impl fmt::Display for Cache { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
for chain in &self.chains { | ||
match NumberPrefix::decimal(chain.blocks.iter().map(|x| x.1).sum::<u64>() as f32) { | ||
match NumberPrefix::decimal( | ||
chain.block_explorer as f32 + chain.blocks.iter().map(|x| x.1).sum::<u64>() as f32, | ||
) { | ||
NumberPrefix::Standalone(size) => { | ||
writeln!(f, "-️ {} ({:.1} B)", chain.name, size)?; | ||
} | ||
NumberPrefix::Prefixed(prefix, size) => { | ||
writeln!(f, "-️ {} ({:.1} {}B)", chain.name, size, prefix)?; | ||
} | ||
} | ||
match NumberPrefix::decimal(chain.block_explorer as f32) { | ||
NumberPrefix::Standalone(size) => { | ||
writeln!(f, "\t-️ Block Explorer ({:.1} B)\n", size)?; | ||
} | ||
NumberPrefix::Prefixed(prefix, size) => { | ||
writeln!(f, "\t-️ Block Explorer ({:.1} {}B)\n", size, prefix)?; | ||
} | ||
} | ||
for block in &chain.blocks { | ||
match NumberPrefix::decimal(block.1 as f32) { | ||
NumberPrefix::Standalone(size) => { | ||
|
@@ -216,18 +226,23 @@ impl fmt::Display for Cache { | |
} | ||
} | ||
|
||
/// A chain folder in the foundry cache | ||
/// A representation of data for a given chain in the foundry cache | ||
#[derive(Debug)] | ||
pub struct ChainCache { | ||
/// The name of the chain | ||
pub name: String, | ||
|
||
/// A tuple containing block number and the block directory size in bytes | ||
pub blocks: Vec<(String, u64)>, | ||
|
||
/// The size of the block explorer directory in bytes | ||
pub block_explorer: u64, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this could be |
||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use pretty_assertions::assert_str_eq; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
|
@@ -260,4 +275,51 @@ mod tests { | |
} | ||
) | ||
} | ||
|
||
#[test] | ||
fn cache_to_string() { | ||
let cache = Cache { | ||
chains: vec![ | ||
ChainCache { | ||
name: "mainnet".to_string(), | ||
blocks: vec![("1".to_string(), 1), ("2".to_string(), 2)], | ||
block_explorer: 500, | ||
}, | ||
ChainCache { | ||
name: "ropsten".to_string(), | ||
blocks: vec![("1".to_string(), 1), ("2".to_string(), 2)], | ||
block_explorer: 4567, | ||
}, | ||
ChainCache { | ||
name: "rinkeby".to_string(), | ||
blocks: vec![("1".to_string(), 1032), ("2".to_string(), 2000000)], | ||
block_explorer: 4230000, | ||
}, | ||
ChainCache { | ||
name: "mumbai".to_string(), | ||
blocks: vec![("1".to_string(), 1), ("2".to_string(), 2)], | ||
block_explorer: 0, | ||
}, | ||
], | ||
}; | ||
|
||
let expected = "\ | ||
-️ mainnet (503.0 B)\n\t\ | ||
-️ Block Explorer (500.0 B)\n\n\t\ | ||
-️ Block 1 (1.0 B)\n\t\ | ||
-️ Block 2 (2.0 B)\n\ | ||
-️ ropsten (4.6 kB)\n\t\ | ||
-️ Block Explorer (4.6 kB)\n\n\t\ | ||
-️ Block 1 (1.0 B)\n\t\ | ||
-️ Block 2 (2.0 B)\n\ | ||
-️ rinkeby (6.2 MB)\n\t\ | ||
-️ Block Explorer (4.2 MB)\n\n\t\ | ||
-️ Block 1 (1.0 kB)\n\t\ | ||
-️ Block 2 (2.0 MB)\n\ | ||
-️ mumbai (3.0 B)\n\t\ | ||
-️ Block Explorer (0.0 B)\n\n\t\ | ||
-️ Block 1 (1.0 B)\n\t\ | ||
-️ Block 2 (2.0 B)\n"; | ||
assert_str_eq!(format!("{cache}"), expected); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the additional newline - it was cleaner to my eye to add an additional line to separate the etherscan data and the block data