Skip to content

Commit

Permalink
feat: add filecoin chains (#2177)
Browse files Browse the repository at this point in the history
* feat: add filecoin chains

* formatting

* fix: add missing match

---------

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
  • Loading branch information
AmeanAsad and gakonst committed Feb 27, 2023
1 parent 537d0a9 commit 47b56a6
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -452,7 +467,6 @@ impl Chain {
Celo |
CeloAlfajores |
CeloBaklava => "ETHERSCAN_API_KEY",

Avalanche | AvalancheFuji => "SNOWTRACE_API_KEY",

Polygon | PolygonMumbai => "POLYGONSCAN_API_KEY",
Expand All @@ -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)
Expand Down

0 comments on commit 47b56a6

Please sign in to comment.