Skip to content

Commit

Permalink
feat: support mesc
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Aug 27, 2024
1 parent 2442e7a commit 9a4586f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 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.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ itertools = "0.13"
jsonpath_lib = "0.3"
k256 = "0.13"
parking_lot = "0.12"
mesc = "0.2.1"
pretty_assertions = "1.4"
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
17 changes: 14 additions & 3 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,16 @@ 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
///
/// - a mesc resolved url if `maybe_alias` is a known alias in mesc
/// - the matching, resolved url of `rpc_endpoints` if `maybe_alias` is an alias
/// - `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 @@ -1092,6 +1099,10 @@ impl Config {
&self,
maybe_alias: &str,
) -> Option<Result<Cow<'_, str>, UnresolvedEnvVarError>> {
if let Ok(Some(endpoint)) = mesc::get_endpoint_by_query(maybe_alias, Some("foundry")) {
return Some(Ok(Cow::Owned(endpoint.url)))
}

let mut endpoints = self.rpc_endpoints.clone().resolved();
Some(endpoints.remove(maybe_alias)?.map(Cow::Owned))
}
Expand Down

0 comments on commit 9a4586f

Please sign in to comment.