Skip to content
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

feat(cast storage): allow exporting the JSON layout #9332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MaxMustermann2
Copy link

@MaxMustermann2 MaxMustermann2 commented Nov 15, 2024

Motivation

Prior to this change, cast storage $ADDRESS --rpc-url $RPC_URL --etherscan-api-key $ETHERSCAN_API_KEY always provided a prettified output. There was no way to obtain the JSON storage layout.

Solution

This change adds a --output-json flag to cast storage. If --slot is omitted and this flag is provided, the storage layout JSON is saved to the specified location.

Prior to this change, `cast storage $ADDRESS --rpc-url $RPC_URL
--etherscan-api-key $ETHERSCAN_API_KEY` always provided a prettified
output.

This change adds a `--pretty` flag to `cast storage` which defaults to
`true` thus retaining backwards compatibility. Passing `--pretty=false`
to `cast storage` results in the json output of the storage layout being
produced instead.
@MaxMustermann2 MaxMustermann2 changed the title feat(cast storage): allow ugly printing of layout feat(cast storage): allow exporting the JSON layout Nov 15, 2024
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! left some comments, please also add a test similar with

casttest!(storage_layout_simple, |_prj, cmd| {
but for json format

/// is not provided. The formatted (pretty) storage layout is shown even if this value
/// is provided.
#[arg(long, default_value = "", value_name = "output_json")]
pub output_json: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have the global --json flag you could use, just check shell::is_json() to see if cast storage was called with it. then one could just redirect output to desired file, I don't think this new arg is needed.

@@ -256,7 +276,7 @@ async fn fetch_storage_slots<P: Provider<T, AnyNetwork>, T: Transport + Clone>(
fn print_storage(layout: StorageLayout, values: Vec<StorageValue>, pretty: bool) -> Result<()> {
if !pretty {
sh_println!("{}", serde_json::to_string_pretty(&serde_json::to_value(layout)?)?)?;
return Ok(())
return Ok(());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep current format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants