Skip to content

Commit

Permalink
feat: support mesc (#8760)
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Aug 29, 2024
1 parent 41198f3 commit 98ab45e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ itertools = "0.13"
jsonpath_lib = "0.3"
k256 = "0.13"
parking_lot = "0.12"
mesc = "0.2.1"
rand = "0.8"
rustc-hash = "2.0"
semver = "1"
Expand Down
1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ globset = "0.4"
glob = "0.3"
Inflector = "0.11"
number_prefix = "0.4"
mesc.workspace = true
regex = "1"
reqwest.workspace = true
semver = { workspace = true, features = ["serde"] }
Expand Down
25 changes: 21 additions & 4 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,18 @@ impl Config {

/// Resolves the given alias to a matching rpc url
///
/// Returns:
/// - the matching, resolved url of `rpc_endpoints` if `maybe_alias` is an alias
/// - None otherwise
/// # Returns
///
/// In order of resolution:
///
/// - the matching, resolved url of `rpc_endpoints` if `maybe_alias` is an alias
/// - a mesc resolved url if `maybe_alias` is a known alias in mesc
/// - `None` otherwise
///
/// # Note on mesc
///
/// The endpoint is queried for in mesc under the `foundry` profile, allowing users to customize
/// endpoints for Foundry specifically.
///
/// # Example
///
Expand All @@ -1093,7 +1102,15 @@ impl Config {
maybe_alias: &str,
) -> Option<Result<Cow<'_, str>, UnresolvedEnvVarError>> {
let mut endpoints = self.rpc_endpoints.clone().resolved();
Some(endpoints.remove(maybe_alias)?.map(Cow::Owned))
if let Some(endpoint) = endpoints.remove(maybe_alias) {
return Some(endpoint.map(Cow::Owned))
}

if let Ok(Some(endpoint)) = mesc::get_endpoint_by_query(maybe_alias, Some("foundry")) {
return Some(Ok(Cow::Owned(endpoint.url)))
}

None
}

/// Returns the configured rpc, or the fallback url
Expand Down

0 comments on commit 98ab45e

Please sign in to comment.