-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: master
Are you sure you want to change the base?
feat(cast storage): allow exporting the JSON layout #9332
Conversation
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.
The default value is accessible via `cast storage --help`
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.
thank you! left some comments, please also add a test similar with
foundry/crates/cast/tests/cli/main.rs
Line 1116 in a79dfae
casttest!(storage_layout_simple, |_prj, cmd| { |
/// 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, |
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.
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(()); |
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.
let's keep current format
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 tocast storage
. If--slot
is omitted and this flag is provided, the storage layout JSON is saved to the specified location.