From 47b56a65b10d8caad6318379b673a4d641db748e Mon Sep 17 00:00:00 2001 From: Amean Asad Date: Mon, 27 Feb 2023 18:00:04 -0500 Subject: [PATCH] feat: add filecoin chains (#2177) * feat: add filecoin chains * formatting * fix: add missing match --------- Co-authored-by: Georgios Konstantopoulos --- ethers-core/src/types/chain.rs | 51 ++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index 05d8140d..269d5fdb 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -109,6 +109,9 @@ pub enum Chain { Emerald = 42262, EmeraldTestnet = 42261, + FilecoinMainnet = 314, + FilecoinHyperspaceTestnet = 3141, + Avalanche = 43114, #[strum(serialize = "fuji", serialize = "avalanche-fuji")] AvalancheFuji = 43113, @@ -248,8 +251,9 @@ impl Chain { Emerald => 6_000, Dev | AnvilHardhat => 200, Celo | CeloAlfajores | CeloBaklava => 5_000, - - // Explicitly exhaustive. See NB above. + FilecoinHyperspaceTestnet | FilecoinMainnet => 30_000, + // Explictly handle all network to make it easier not to forget this match when new + // networks are added. Morden | Ropsten | Rinkeby | Goerli | Kovan | XDai | Chiado | Sepolia | Moonbase | MoonbeamDev | Optimism | OptimismGoerli | OptimismKovan | Poa | Sokol | Rsk | EmeraldTestnet => return None, @@ -294,14 +298,20 @@ impl Chain { CeloBaklava => true, // Known EIP-1559 chains - Mainnet | Goerli | Sepolia | Polygon | PolygonMumbai | Avalanche | AvalancheFuji => { - false - } + Mainnet | + Goerli | + Sepolia | + Polygon | + PolygonMumbai | + Avalanche | + AvalancheFuji | + FilecoinHyperspaceTestnet => false, // Unknown / not applicable, default to false for backwards compatibility Dev | AnvilHardhat | Morden | Ropsten | Rinkeby | Cronos | CronosTestnet | Kovan | Sokol | Poa | XDai | Moonbeam | MoonbeamDev | Moonriver | Moonbase | Evmos | - EvmosTestnet | Chiado | Aurora | AuroraTestnet | Canto | CantoTestnet => false, + EvmosTestnet | Chiado | Aurora | AuroraTestnet | Canto | CantoTestnet | + FilecoinMainnet => false, } } @@ -379,6 +389,9 @@ impl Chain { Chiado => { ("https://blockscout.chiadochain.net/api", "https://blockscout.chiadochain.net") } + FilecoinHyperspaceTestnet => { + ("https://api.hyperspace.node.glif.io/rpc/v1", "https://hyperspace.filfox.info") + } Sokol => ("https://blockscout.com/poa/sokol/api", "https://blockscout.com/poa/sokol"), Poa => ("https://blockscout.com/poa/core/api", "https://blockscout.com/poa/core"), Rsk => ("https://blockscout.com/rsk/mainnet/api", "https://blockscout.com/rsk/mainnet"), @@ -408,9 +421,11 @@ impl Chain { "https://testnet-explorer.canto.neobase.one/", "https://testnet-explorer.canto.neobase.one/api", ), - - // Explicitly exhaustive. See NB above. - AnvilHardhat | Dev | Morden | MoonbeamDev => return None, + AnvilHardhat | Dev | Morden | MoonbeamDev | FilecoinMainnet => { + // this is explicitly exhaustive so we don't forget to add new urls when adding a + // new chain + return None + } }; Some(urls) @@ -452,7 +467,6 @@ impl Chain { Celo | CeloAlfajores | CeloBaklava => "ETHERSCAN_API_KEY", - Avalanche | AvalancheFuji => "SNOWTRACE_API_KEY", Polygon | PolygonMumbai => "POLYGONSCAN_API_KEY", @@ -464,8 +478,21 @@ impl Chain { Canto | CantoTestnet => "BLOCKSCOUT_API_KEY", // Explicitly exhaustive. See NB above. - XDai | Chiado | Sepolia | Rsk | Sokol | Poa | Oasis | Emerald | EmeraldTestnet | - Evmos | EvmosTestnet | AnvilHardhat | Dev => return None, + XDai | + Chiado | + Sepolia | + Rsk | + Sokol | + Poa | + Oasis | + Emerald | + EmeraldTestnet | + Evmos | + EvmosTestnet | + AnvilHardhat | + Dev | + FilecoinMainnet | + FilecoinHyperspaceTestnet => return None, }; Some(api_key_name)