From a019bc5059389baa569ddb1cccf6f125ff873f4d Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 28 Jul 2023 19:49:26 -0400 Subject: [PATCH 1/8] feat(cast): add JWT secret configuration --- Cargo.lock | 23 ++++++++++--------- crates/cli/src/opts/ethereum.rs | 17 ++++++++++++++ crates/cli/src/utils/mod.rs | 10 ++++++++- crates/common/Cargo.toml | 1 + crates/common/src/provider.rs | 40 +++++++++++++++++++++++++++++---- crates/config/src/lib.rs | 22 ++++++++++++++++++ 6 files changed, 97 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 96182a62a00d2..c0ab709f1ef55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1899,7 +1899,7 @@ dependencies = [ [[package]] name = "ethers" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1914,7 +1914,7 @@ dependencies = [ [[package]] name = "ethers-addressbook" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "ethers-core", "once_cell", @@ -1925,7 +1925,7 @@ dependencies = [ [[package]] name = "ethers-contract" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "const-hex", "ethers-contract-abigen", @@ -1943,7 +1943,7 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "Inflector", "const-hex", @@ -1966,7 +1966,7 @@ dependencies = [ [[package]] name = "ethers-contract-derive" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "Inflector", "const-hex", @@ -1981,7 +1981,7 @@ dependencies = [ [[package]] name = "ethers-core" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "arrayvec", "bytes", @@ -2010,7 +2010,7 @@ dependencies = [ [[package]] name = "ethers-etherscan" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "ethers-core", "ethers-solc", @@ -2025,7 +2025,7 @@ dependencies = [ [[package]] name = "ethers-middleware" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "async-trait", "auto_impl", @@ -2051,7 +2051,7 @@ dependencies = [ [[package]] name = "ethers-providers" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "async-trait", "auto_impl", @@ -2089,7 +2089,7 @@ dependencies = [ [[package]] name = "ethers-signers" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "async-trait", "coins-bip32", @@ -2116,7 +2116,7 @@ dependencies = [ [[package]] name = "ethers-solc" version = "2.0.8" -source = "git+https://github.com/gakonst/ethers-rs#179891d45cc7b50941f2b8c30b206355ab76d94c" +source = "git+https://github.com/gakonst/ethers-rs#7603af021be920ca39b610f88c0012328b337cd6" dependencies = [ "cfg-if", "const-hex", @@ -2498,6 +2498,7 @@ dependencies = [ "foundry-config", "foundry-macros", "globset", + "hex", "once_cell", "regex", "reqwest", diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index 4686925daac3d..100e630df2c4a 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -23,6 +23,10 @@ pub struct RpcOpts { /// Use the Flashbots RPC URL (https://rpc.flashbots.net). #[clap(long)] pub flashbots: bool, + + /// JWT Secret for the RPC endpoint. + #[clap(long, env = "ETH_RPC_JWT")] + pub jwt: Option, } impl_figment_convert_cast!(RpcOpts); @@ -49,11 +53,24 @@ impl RpcOpts { Ok(url) } + /// Returns the JWT secret. + pub fn jwt<'a>(&'a self, config: Option<&'a Config>) -> Result>> { + let jwt = match (self.jwt.as_deref(), config) { + (Some(jwt), _) => Some(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()); + } dict } } diff --git a/crates/cli/src/utils/mod.rs b/crates/cli/src/utils/mod.rs index d94119cd5ad62..6eff663231900 100644 --- a/crates/cli/src/utils/mod.rs +++ b/crates/cli/src/utils/mod.rs @@ -90,6 +90,7 @@ pub fn parse_u256(s: &str) -> Result { pub fn get_provider(config: &Config) -> Result { get_provider_builder(config)?.build() } + /// Returns a [ProviderBuilder](foundry_common::ProviderBuilder) instantiated using [Config]'s RPC /// URL and chain. /// @@ -97,7 +98,14 @@ pub fn get_provider(config: &Config) -> Result { pub fn get_provider_builder(config: &Config) -> Result { let url = config.get_rpc_url_or_localhost_http()?; let chain = config.chain_id.unwrap_or_default(); - Ok(foundry_common::ProviderBuilder::new(url.as_ref()).chain(chain)) + let mut builder = foundry_common::ProviderBuilder::new(url.as_ref()).chain(chain); + + let jwt = config.get_rpc_jwt_secret()?; + if let Some(jwt) = jwt { + builder = builder.jwt(jwt.as_ref()); + } + + builder.build() } pub async fn get_chain(chain: Option, provider: M) -> Result diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 0333b6d6b0950..c8eba0428989d 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -43,6 +43,7 @@ once_cell = "1" dunce = "1" regex = "1" globset = "0.4" +hex = "0.4" [dev-dependencies] tokio = { version = "1", features = ["rt-multi-thread", "macros"] } diff --git a/crates/common/src/provider.rs b/crates/common/src/provider.rs index f0322722cf6bf..1efd29bee63f2 100644 --- a/crates/common/src/provider.rs +++ b/crates/common/src/provider.rs @@ -4,11 +4,11 @@ use crate::{ALCHEMY_FREE_TIER_CUPS, REQUEST_TIMEOUT}; use ethers_core::types::{Chain, U256}; use ethers_middleware::gas_oracle::{GasCategory, GasOracle, Polygon}; use ethers_providers::{ - is_local_endpoint, Http, HttpRateLimitRetryPolicy, Middleware, Provider, RetryClient, - RetryClientBuilder, DEFAULT_LOCAL_POLL_INTERVAL, + is_local_endpoint, Authorization, Http, HttpRateLimitRetryPolicy, JwtAuth, JwtKey, Middleware, + Provider, RetryClient, RetryClientBuilder, DEFAULT_LOCAL_POLL_INTERVAL, }; use eyre::WrapErr; -use reqwest::{IntoUrl, Url}; +use reqwest::{header::HeaderValue, IntoUrl, Url}; use std::{borrow::Cow, time::Duration}; /// Helper type alias for a retry provider @@ -53,6 +53,8 @@ pub struct ProviderBuilder { timeout: Duration, /// available CUPS compute_units_per_second: u64, + /// JWT Secret + jwt: Option, } // === impl ProviderBuilder === @@ -76,6 +78,7 @@ impl ProviderBuilder { timeout: REQUEST_TIMEOUT, // alchemy max cpus compute_units_per_second: ALCHEMY_FREE_TIER_CUPS, + jwt: None, } } @@ -141,6 +144,12 @@ impl ProviderBuilder { self.max_retry(100).initial_backoff(100) } + /// Sets the JWT secret + pub fn jwt(mut self, jwt: impl Into) -> Self { + self.jwt = Some(jwt.into()); + self + } + /// Same as [`Self:build()`] but also retrieves the `chainId` in order to derive an appropriate /// interval pub async fn connect(self) -> eyre::Result { @@ -163,10 +172,33 @@ impl ProviderBuilder { initial_backoff, timeout, compute_units_per_second, + jwt, } = self; let url = url?; - let client = reqwest::Client::builder().timeout(timeout).build()?; + let mut client_builder = reqwest::Client::builder().timeout(timeout); + + // Set the JWT auth as a header if present + if let Some(jwt) = jwt { + // Decode jwt from hex, then generate claims (iat with current timestamp) + let jwt = hex::decode(jwt)?; + let secret = + JwtKey::from_slice(&jwt).map_err(|err| eyre::eyre!("Invalid JWT: {}", err))?; + let auth = JwtAuth::new(secret, None, None); + let token = auth.generate_token()?; + + // Essentially unrolled ethers-rs new_with_auth to accomodate the custom timeout + let auth = Authorization::Bearer(token); + let mut auth_value = HeaderValue::from_str(&auth.to_string())?; + auth_value.set_sensitive(true); + + let mut headers = reqwest::header::HeaderMap::new(); + headers.insert(reqwest::header::AUTHORIZATION, auth_value); + + client_builder = client_builder.default_headers(headers); + } + + let client = client_builder.build()?; let is_local = is_local_endpoint(url.as_str()); let provider = Http::new_with_client(url, client); diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 80899815fd1c9..ac30f3f22ae7f 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -205,6 +205,8 @@ pub struct Config { pub verbosity: u8, /// url of the rpc server that should be used for any rpc calls pub eth_rpc_url: Option, + /// JWT secret that should be used for any rpc calls + pub eth_rpc_jwt: Option, /// etherscan API key, or alias for an `EtherscanConfig` in `etherscan` table pub etherscan_api_key: Option, /// Multiple etherscan api configs and their aliases @@ -752,6 +754,25 @@ impl Config { self.remappings.iter().map(|m| m.clone().into()).collect() } + /// Returns the configured rpc jwt secret + /// + /// Returns: + /// - The jwt secret, if configured + /// + /// # Example + /// + /// ``` + /// + /// use foundry_config::Config; + /// # fn t() { + /// let config = Config::with_root("./"); + /// let rpc_jwt = config.get_rpc_jwt().unwrap().unwrap(); + /// # } + /// ``` + pub fn get_rpc_jwt_secret(&self) -> Result>, UnresolvedEnvVarError> { + Ok(self.eth_rpc_jwt.as_ref().map(|jwt| Cow::Borrowed(jwt.as_str()))) + } + /// Returns the configured rpc url /// /// Returns: @@ -1774,6 +1795,7 @@ impl Default for Config { block_gas_limit: None, memory_limit: 2u64.pow(25), eth_rpc_url: None, + eth_rpc_jwt: None, etherscan_api_key: None, verbosity: 0, remappings: vec![], From 4ce83c5de7d5314aafdd2741a2799cc6df0844eb Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:32:37 -0400 Subject: [PATCH 2/8] set patches to branch --- Cargo.lock | 18 +++++++++--------- crates/cli/src/utils/mod.rs | 2 +- crates/forge/tests/cli/config.rs | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0ab709f1ef55..e9fc995dd1c96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -850,9 +850,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "jobserver", "libc", @@ -1513,9 +1513,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" +checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" [[package]] name = "derivative" @@ -3113,9 +3113,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -4674,12 +4674,12 @@ dependencies = [ [[package]] name = "petgraph" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 1.9.3", + "indexmap 2.0.0", ] [[package]] diff --git a/crates/cli/src/utils/mod.rs b/crates/cli/src/utils/mod.rs index 6eff663231900..5215b88562b77 100644 --- a/crates/cli/src/utils/mod.rs +++ b/crates/cli/src/utils/mod.rs @@ -105,7 +105,7 @@ pub fn get_provider_builder(config: &Config) -> Result(chain: Option, provider: M) -> Result diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index e4912732bbcd9..08ad780a9c210 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -115,6 +115,7 @@ forgetest!(can_extract_config_values, |prj: TestProject, mut cmd: TestCommand| { fs_permissions: Default::default(), __non_exhaustive: (), __warnings: vec![], + eth_rpc_jwt: None, }; prj.write_config(input.clone()); let config = cmd.config(); From d402c6d3ee8d4e0fe8ae702228429175dc909e55 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:33:59 -0400 Subject: [PATCH 3/8] fix cli test --- crates/forge/tests/cli/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index 08ad780a9c210..de767c0f5f0ba 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -84,6 +84,7 @@ forgetest!(can_extract_config_values, |prj: TestProject, mut cmd: TestCommand| { block_gas_limit: Some(100u64.into()), memory_limit: 2u64.pow(25), eth_rpc_url: Some("localhost".to_string()), + eth_rpc_jwt: None, etherscan_api_key: None, etherscan: Default::default(), verbosity: 4, From 0ab2e43b2b3a6b1953514c8df79f4a0eb0917f26 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Mon, 21 Aug 2023 12:29:52 -0400 Subject: [PATCH 4/8] remove patches --- Cargo.lock | 26 ++++++++++++-------------- crates/forge/tests/cli/config.rs | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9fc995dd1c96..a78296a9051a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5256,9 +5256,9 @@ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "20b9b67e2ca7dd9e9f9285b759de30ff538aab981abaaf7bc9bd90b84a0126c3" dependencies = [ "base64 0.21.2", "bytes", @@ -5293,7 +5293,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.22.6", + "webpki-roots 0.25.2", "winreg", ] @@ -7424,21 +7424,18 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" dependencies = [ - "webpki", + "rustls-webpki 0.100.1", ] [[package]] name = "webpki-roots" -version = "0.23.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" -dependencies = [ - "rustls-webpki 0.100.1", -] +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" [[package]] name = "which" @@ -7634,11 +7631,12 @@ dependencies = [ [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if", + "windows-sys 0.48.0", ] [[package]] diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index de767c0f5f0ba..ba85a509b989a 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -116,7 +116,6 @@ forgetest!(can_extract_config_values, |prj: TestProject, mut cmd: TestCommand| { fs_permissions: Default::default(), __non_exhaustive: (), __warnings: vec![], - eth_rpc_jwt: None, }; prj.write_config(input.clone()); let config = cmd.config(); From 447e725c30869d8c18f2ac18f46edf6e603a96c1 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:11:40 -0400 Subject: [PATCH 5/8] change `jwt` to `jwt-secret` --- crates/cli/src/opts/ethereum.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index 100e630df2c4a..a0a1f3a681bdf 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -25,8 +25,8 @@ pub struct RpcOpts { pub flashbots: bool, /// JWT Secret for the RPC endpoint. - #[clap(long, env = "ETH_RPC_JWT")] - pub jwt: Option, + #[clap(long, env = "ETH_RPC_JWT_SECRET")] + pub jwt_secret: Option, } impl_figment_convert_cast!(RpcOpts); From 59f8a7919751405efa88eddba30d330591119756 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:17:09 -0400 Subject: [PATCH 6/8] change usages oops --- crates/cli/src/opts/ethereum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index a0a1f3a681bdf..481bc1343478a 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -55,7 +55,7 @@ impl RpcOpts { /// Returns the JWT secret. pub fn jwt<'a>(&'a self, config: Option<&'a Config>) -> Result>> { - let jwt = match (self.jwt.as_deref(), config) { + let jwt = match (self.jwt_secret.as_deref(), config) { (Some(jwt), _) => Some(Cow::Borrowed(jwt)), (None, Some(config)) => config.get_rpc_jwt_secret()?, (None, None) => None, From 36e9638d4285bff2bf4411dd387e8cf302fd6ecb Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:35:45 -0400 Subject: [PATCH 7/8] fix rpc_jwt_secret docs, add usage docs --- crates/cli/src/opts/ethereum.rs | 8 ++++++++ crates/config/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/opts/ethereum.rs b/crates/cli/src/opts/ethereum.rs index 481bc1343478a..96a82c31e1a8f 100644 --- a/crates/cli/src/opts/ethereum.rs +++ b/crates/cli/src/opts/ethereum.rs @@ -25,6 +25,14 @@ pub struct RpcOpts { pub flashbots: bool, /// JWT Secret for the RPC endpoint. + /// + /// The JWT secret will be used to create a JWT for a RPC. For example, the following can be + /// used to simulate a CL `engine_forkchoiceUpdated` call: + /// + /// cast rpc --jwt-secret engine_forkchoiceUpdatedV2 + /// '["0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc", + /// "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc", + /// "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc"]' #[clap(long, env = "ETH_RPC_JWT_SECRET")] pub jwt_secret: Option, } diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index ac30f3f22ae7f..a3cac6b3e18bf 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -766,7 +766,7 @@ impl Config { /// use foundry_config::Config; /// # fn t() { /// let config = Config::with_root("./"); - /// let rpc_jwt = config.get_rpc_jwt().unwrap().unwrap(); + /// let rpc_jwt = config.get_rpc_jwt_secret().unwrap().unwrap(); /// # } /// ``` pub fn get_rpc_jwt_secret(&self) -> Result>, UnresolvedEnvVarError> { From 94fe775d5bfd73e5ce437a72efe340357fa5623c Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Mon, 21 Aug 2023 17:16:21 -0400 Subject: [PATCH 8/8] chore: use const-hex --- Cargo.lock | 2 +- crates/common/Cargo.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a78296a9051a1..949d33496f888 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2488,6 +2488,7 @@ dependencies = [ "auto_impl", "clap", "comfy-table", + "const-hex", "dunce", "ethers-core", "ethers-etherscan", @@ -2498,7 +2499,6 @@ dependencies = [ "foundry-config", "foundry-macros", "globset", - "hex", "once_cell", "regex", "reqwest", diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index c8eba0428989d..e945b45ce0947 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -43,7 +43,8 @@ once_cell = "1" dunce = "1" regex = "1" globset = "0.4" -hex = "0.4" +# Using const-hex instead of hex for speed +hex.workspace = true [dev-dependencies] tokio = { version = "1", features = ["rt-multi-thread", "macros"] }