-
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
fix: unify names of supported chains #1581
fix: unify names of supported chains #1581
Conversation
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.
thanks,
I was wondering since we have a Chain enum on ethers-rs already, can we instead use that?
cli/src/cmd/forge/cache.rs
Outdated
#[derive(Debug, EnumString, EnumVariantNames)] | ||
#[strum(serialize_all = "kebab-case")] | ||
pub enum PossibleChains { | ||
All, | ||
Mainnet, | ||
Ropsten, | ||
Rinkeby, | ||
Goerli, | ||
Kovan, | ||
Xdai, | ||
Polygon, | ||
PolygonMumbai, | ||
Avalanche, | ||
AvalancheFuji, | ||
Sepolia, | ||
Moonbeam, | ||
MoonbeamDev, | ||
Moonriver, | ||
Optimism, | ||
OptimismKovan, | ||
Fantom, | ||
FantomTestnet, | ||
Arbitrum, | ||
ArbitrumTestnet, | ||
Bsc, | ||
BscTestnet, | ||
Cronos, | ||
CronosTestnet, | ||
} |
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.
can we even replace this with the native ethers-rs
Chain
?
I'm having a lot of trouble figuring out how to use the Chain enum from instead of foundry/cli/src/cmd/forge/cache.rs Lines 42 to 68 in 62c728a
Do you have any pointers/search terms for google fu? I will keep on at it until I grok it |
looks like the https://docs.rs/strum/latest/strum/derive.EnumVariantNames.html macro simply creates a we probably should add this here instead: https://github.com/gakonst/ethers-rs/blob/842f4d260f7f1f7479eaadd7ebf7f98b329d0da5/ethers-core/src/types/chain.rs#L16 so we don't have duplicate Chain types, you can test changes to ethers-rs by patching the ethers-rs dependency against a local checkout: Line 52 in b11b776
|
awesome will try that I may have run into a blocker Getting build error when making these updates here - updated with pr ➜ ethers-rs git:(add-strum-for-chain) cargo build
Compiling ethers-core v0.6.0 (/Users/m1/CLionProjects/ethers-rs/ethers-core)
warning: unused import: `VariantNames`
--> ethers-core/src/types/chain.rs:6:43
|
6 | use strum::{EnumString, EnumVariantNames, VariantNames};
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0119]: conflicting implementations of trait `std::str::FromStr` for type `types::chain::Chain`
--> ethers-core/src/types/chain.rs:15:64
|
15 | #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize, EnumString, EnumVariantNames)]
| ^^^^^^^^^^ conflicting implementation for `types::chain::Chain`
...
132 | impl FromStr for Chain {
| ---------------------- first implementation here
|
= note: this error originates in the derive macro `EnumString` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0119`.
warning: `ethers-core` (lib) generated 1 warning
error: could not compile `ethers-core` due to previous error; 1 warning emitted
warning: build failed, waiting for other jobs to finish...
warning: `ethers-core` (lib) generated 1 warning (1 duplicate)
error: build failed
➜ ethers-rs git:(add-strum-for-chain)
I will lookup adding |
Tests should pass after |
"optimism-kovan" | ||
])] | ||
possible_value = "all", | ||
possible_values = Chain::VARIANTS |
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.
Hmm, AFAIK we already have a ClapChain
enum somewhere that does this without strum - we should just use that. Also, we should do that everywhere we accept a chain name.
Edit: Found it:
Line 33 in eb98846
pub struct ClapChain { |
But there is also a Chain
enum in the config
crate.. https://github.com/foundry-rs/foundry/blob/eb9884639c4fb2b976f34f033d60b2cc0432e3f3/config/src/chain.rs
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.
oh whoops, will take a look at using this
I am a bit hard stuck here and would appreciate some guidance From what I understand the solution should be
pub enum Chain {
/// Contains a known chain
#[serde(serialize_with = "super::from_str_lowercase::serialize")]
Named(ethers_core::types::Chain),
/// Contains the id of a chain
Id(u64),
} onewhere I am stuck is If I try to get a use foundry_config::{cache, Chain as FoundryConfigChain, Config};
#[derive(Debug, Parser)]
pub struct LsArgs {
// TODO refactor to dedup shared logic with ClapChain in opts/mod
#[clap(
env = "CHAIN",
default_value = "all",
possible_value = "all",
possible_value = FoundryConfigChain::Named(Chain::Mainnet)
)]
chains: Vec<ChainOrAll>,
} I get the error below error[E0277]: the trait bound `PossibleValue<'_>: std::convert::From<foundry_config::Chain>` is not satisfied
--> cli/src/cmd/forge/cache.rs:67:26
|
67 | possible_value = FoundryConfigChain::Named(Chain::Mainnet)
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<foundry_config::Chain>` is not implemented for `PossibleValue<'_>`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<PossibleValue<'help> as std::convert::From<&'help &'help str>>
<PossibleValue<'help> as std::convert::From<&'help str>>
= note: required because of the requirements on the impl of `Into<PossibleValue<'_>>` for `foundry_config::Chain`
note: required by a bound in `Arg::<'help>::possible_value`
--> /Users/m1/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-3.1.12/src/build/arg.rs:1720:12
|
1720 | T: Into<PossibleValue<'help>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Arg::<'help>::possible_value`
For more information about this error, try `rustc --explain E0277`.
warning: `foundry-cli` (bin "forge") generated 2 warnings
error: could not compile `foundry-cli` due to previous error; 2 warnings emitted
warning: build failed, waiting for other jobs to finish...
warning: `foundry-cli` (bin "cast") generated 2 warnings (2 duplicates)
error: build failed twoOr trying with possible_value = FoundryConfigChain::from_str("mainnet") getting error error[E0277]: the trait bound `PossibleValue<'_>: std::convert::From<Result<foundry_config::Chain, std::string::String>>` is not satisfied
--> cli/src/cmd/forge/cache.rs:67:26
|
67 | possible_value = FoundryConfigChain::from_str("mainnet")
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<Result<foundry_config::Chain, std::string::String>>` is not implemented for `PossibleValue<'_>`
| |
| required by a bound introduced by this call
|
= help: the following implementations were found:
<PossibleValue<'help> as std::convert::From<&'help &'help str>>
<PossibleValue<'help> as std::convert::From<&'help str>>
= note: required because of the requirements on the impl of `Into<PossibleValue<'_>>` for `Result<foundry_config::Chain, std::string::String>`
note: required by a bound in `Arg::<'help>::possible_value`
--> /Users/m1/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-3.1.12/src/build/arg.rs:1720:12
|
1720 | T: Into<PossibleValue<'help>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Arg::<'help>::possible_value`
For more information about this error, try `rustc --explain E0277`.
warning: `foundry-cli` (bin "forge") generated 2 warnings
error: could not compile `foundry-cli` due to previous error; 2 warnings emitted
warning: build failed, waiting for other jobs to finish...
warning: `foundry-cli` (bin "cast") generated 2 warnings (2 duplicates)
error: build failed |
@shawnharmsen I think using #[derive(ArgEnum)]
pub enum MyEnum {
OptionOne,
OptionTwo
} If you use the one in the Doing that it just automagically kind of works. See the |
Apologies but ran into another problem Latest commit I see how argEnum workspub struct LsArgs {
\\ ...
#[clap(long, arg_enum, default_value = "all", help = "Name of chain")]
chains2: ChainOptions,
}
#[derive(Debug, Clone, ArgEnum)]
pub enum ChainOptions {
All,
Mainnet,
Goerli,
} and the foundry git:(feat-unify-names-supported-chains) target/debug/forge cache ls -h
forge-cache-ls
Shows cached data from ~/.foundry.
USAGE:
forge cache ls [OPTIONS] [CHAINS]...
ARGS:
<CHAINS>... [env: CHAIN=] [default: all] [possible values: all, mainnet, ropsten, rinkeby, goerli, kovan, xdai, polygon, polygon-mumbai, avalanche, avalanche-fuji, sepolia,
moonbeam, moonbeam-dev, moonriver, optimism, optimism-kovan, fantom, fantom-testnet, arbitrum, arbitrum-testnet, bsc, bsc-testnet, cronos]
OPTIONS:
--chains2 <CHAINS2> Name of chain [default: all] [possible values: all, mainnet, goerli]
-h, --help Print help information
When I try to use
|
Yeah you are getting this error because of:
|
I've opened a new pr because I've been getting build errors that I think stem from cargo.lock Will close this one and use this: #1636 |
issue: #1564
Was using references:
https://users.rust-lang.org/t/structopt-enum-like-args/67414/2
https://github.com/TeXitoi/structopt/blob/master/examples/enum_in_args_with_strum.rs
Motivation
Solution
Unsure if I should be adding strum
foundry/cli/Cargo.toml
Line 73 in c8872a9
I was a bit too hurried and didn't try using this:
foundry/cli/src/opts/mod.rs
Lines 40 to 57 in ed4eb2d
Will try again and update