-
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
#1718 - adds option to write anvil config to json file #1854
Conversation
because the whole point is to make it easy to interact with the config programatically
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.
Minor nits to make it more idiomatic - lgtm otherwise!
nice first issue, almost joined the Citadel ✅
anvil/src/config.rs
Outdated
let mut available_accounts = Vec::with_capacity(self.genesis_accounts.len()); | ||
let mut private_keys = Vec::with_capacity(self.genesis_accounts.len()); | ||
|
||
for (_, wallet) in self.genesis_accounts.iter().enumerate() { |
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.
Don't need the iter/enumerate, can just do "for wallet in &self.genesis_accounts"
anvil/src/config.rs
Outdated
wallet_description.insert("mnemonic".to_string(), phrase); | ||
}; | ||
|
||
if let Some(fork) = fork { |
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.
Instead of declaring it at the beginning of the function, you can do:
let config_as_json = if foo { 1 } else { 2};.
More idiomatic, saves you from having to declare the type too and more compact
Also given we know it's a json from the type, you can just call it "config "
anvil/src/config.rs
Outdated
@@ -272,6 +438,13 @@ impl NodeConfig { | |||
self | |||
} | |||
|
|||
/// Sets file to write config info to |
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.
/// Sets file to write config info to | |
/// Sets the file path to write the Anvil node's config info to. |
anvil/src/config.rs
Outdated
let config_out = self.config_out.as_deref().unwrap(); | ||
let f = | ||
File::create(config_out).expect("Unable to create anvil config description file"); | ||
let mut f = BufWriter::new(f); |
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.
I think you probably can instead avoid the "serde_json::to string" in as_json, and return the serde_json::Value type and here do serde_json::to_writer. Basically same thing but without you needing to manage the file descriptor and do write_all.
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.
💯
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.
💯
Adds the
--config-out <out_file>
option to anvil. This writes the same info that anvil writes to stdout, in a more machine-friendly format, as json to the file specified by the user.Motivation
#1718
Solution
pretty straightforward, if you include
--config-out <out_file>
it writes the relevant config info to <out_file>. note: it will still write the file itsilent
and--config-out
are provided since i assumed silent is really referring to stdout/err