-
Couldn't load subscription status.
- Fork 2.2k
refactor: unify RpcOpts and EvmArgs common fields #11964
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
Open
hawkadrian
wants to merge
27
commits into
foundry-rs:master
Choose a base branch
from
hawkadrian:refactor/unify-rpc-opts-and-evm-args
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−146
Open
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8e403a6
Create rpc_common.rs
hawkadrian bfc681b
Update mod.rs
hawkadrian 963de14
Update rpc.rs
hawkadrian 0634631
Update evm.rs
hawkadrian 8803851
Update rpc_common.rs
hawkadrian 6d0e993
Update evm.rs
hawkadrian e16b63c
Update rpc_common.rs
hawkadrian 0754649
Update rpc.rs
hawkadrian f08d7fb
Update evm.rs
hawkadrian 6f8bbb4
Merge branch 'master' into refactor/unify-rpc-opts-and-evm-args
hawkadrian 4294083
Update rpc.rs
hawkadrian 3f3b780
Merge branch 'master' into refactor/unify-rpc-opts-and-evm-args
hawkadrian 80052e9
Update rpc.rs
hawkadrian a094625
Merge branch 'master' into refactor/unify-rpc-opts-and-evm-args
grandizzy dd52b7f
Update run.rs
hawkadrian 0b775d1
Update evm.rs
hawkadrian 8de6524
Update rpc_common.rs
hawkadrian 0a77ce3
Update script.rs
hawkadrian 1a7396b
Update lib.rs
hawkadrian 8fe2ac8
Update build.rs
hawkadrian e609eea
Update mod.rs
hawkadrian a39036b
Update script.rs
hawkadrian e2e2f38
Update backtrace.rs
hawkadrian 1b5a6fb
Update evm.rs
hawkadrian e6a7021
Update cmd.rs
hawkadrian afbc327
Update README.md
hawkadrian c30b14e
Merge branch 'master' into refactor/unify-rpc-opts-and-evm-args
hawkadrian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| //! Common RPC options shared between different CLI commands. | ||
| use clap::Parser; | ||
| use foundry_config::{ | ||
| figment::{ | ||
| self, Metadata, Profile, | ||
| value::{Dict, Map}, | ||
| }, | ||
| Config, | ||
| }; | ||
| use serde::Serialize; | ||
|
|
||
| /// Common RPC-related options that can be shared across different CLI commands. | ||
| #[derive(Clone, Debug, Default, Serialize, Parser)] | ||
| pub struct RpcCommonOpts { | ||
| /// The RPC endpoint URL. | ||
| #[arg(long, short, visible_alias = "rpc-url", value_name = "URL")] | ||
| #[serde(rename = "eth_rpc_url", skip_serializing_if = "Option::is_none")] | ||
| pub url: Option<String>, | ||
|
|
||
| /// Allow insecure RPC connections (accept invalid HTTPS certificates). | ||
| #[arg(short = 'k', long = "insecure", default_value = "false")] | ||
| pub accept_invalid_certs: bool, | ||
|
|
||
| /// JWT Secret for the RPC endpoint. | ||
| #[arg(long, env = "ETH_RPC_JWT_SECRET")] | ||
| pub jwt_secret: Option<String>, | ||
|
|
||
| /// Timeout for the RPC request in seconds. | ||
| #[arg(long, env = "ETH_RPC_TIMEOUT")] | ||
| pub rpc_timeout: Option<u64>, | ||
|
|
||
| /// Specify custom headers for RPC requests. | ||
| #[arg(long, alias = "headers", env = "ETH_RPC_HEADERS", value_delimiter(','))] | ||
| pub rpc_headers: Option<Vec<String>>, | ||
|
|
||
| /// Sets the number of assumed available compute units per second for this provider. | ||
| #[arg(long, alias = "cups", value_name = "CUPS")] | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub compute_units_per_second: Option<u64>, | ||
|
|
||
| /// Disables rate limiting for this node's provider. | ||
| #[arg(long, value_name = "NO_RATE_LIMITS", visible_alias = "no-rate-limit")] | ||
| #[serde(skip)] | ||
| pub no_rpc_rate_limit: bool, | ||
| } | ||
|
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. While we do want |
||
|
|
||
| impl figment::Provider for RpcCommonOpts { | ||
| fn metadata(&self) -> Metadata { | ||
| Metadata::named("RpcCommonOpts") | ||
| } | ||
|
|
||
| fn data(&self) -> Result<Map<Profile, Dict>, figment::Error> { | ||
| Ok(Map::from([(Config::selected_profile(), self.dict())])) | ||
| } | ||
| } | ||
|
|
||
| impl RpcCommonOpts { | ||
| /// Returns the RPC endpoint. | ||
| pub fn url<'a>(&'a self, config: Option<&'a Config>) -> Result<Option<std::borrow::Cow<'a, str>>, eyre::Error> { | ||
| let url = match (self.url.as_deref(), config) { | ||
| (Some(url), _) => Some(std::borrow::Cow::Borrowed(url)), | ||
| (None, Some(config)) => config.get_rpc_url().transpose()?, | ||
| (None, None) => None, | ||
| }; | ||
| Ok(url) | ||
| } | ||
|
|
||
| /// Returns the JWT secret. | ||
| pub fn jwt<'a>(&'a self, config: Option<&'a Config>) -> Result<Option<std::borrow::Cow<'a, str>>, eyre::Error> { | ||
| let jwt = match (self.jwt_secret.as_deref(), config) { | ||
| (Some(jwt), _) => Some(std::borrow::Cow::Borrowed(jwt)), | ||
| (None, Some(config)) => config.get_rpc_jwt_secret()?, | ||
| (None, None) => None, | ||
| }; | ||
| Ok(jwt) | ||
| } | ||
|
|
||
| pub fn dict(&self) -> Dict { | ||
| let mut dict = Dict::new(); | ||
| if let Ok(Some(url)) = self.url(None) { | ||
| dict.insert("eth_rpc_url".into(), url.into_owned().into()); | ||
| } | ||
| if let Ok(Some(jwt)) = self.jwt(None) { | ||
| dict.insert("eth_rpc_jwt".into(), jwt.into_owned().into()); | ||
| } | ||
| if let Some(rpc_timeout) = self.rpc_timeout { | ||
| dict.insert("eth_rpc_timeout".into(), rpc_timeout.into()); | ||
| } | ||
| if let Some(headers) = &self.rpc_headers { | ||
| dict.insert("eth_rpc_headers".into(), headers.clone().into()); | ||
| } | ||
| if self.accept_invalid_certs { | ||
| dict.insert("eth_rpc_accept_invalid_certs".into(), true.into()); | ||
| } | ||
| if let Some(cups) = self.compute_units_per_second { | ||
| dict.insert("compute_units_per_second".into(), cups.into()); | ||
| } | ||
| if self.no_rpc_rate_limit { | ||
| dict.insert("no_rpc_rate_limit".into(), self.no_rpc_rate_limit.into()); | ||
| } | ||
| dict | ||
| } | ||
| } | ||
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.
As you added
url()method toRpcCommonOpts, this may be simplified by just checking flashbots flag to either set FLASHBOTS_URL or call inner url() method.