chore: add celo chain (#1932)

* add celo chain

* add missing chain case

* clippy & fmt
This commit is contained in:
joshieDo 2022-12-08 13:37:11 +08:00 committed by GitHub
parent 3dfc04f9fe
commit 92e726921a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 13 deletions

View File

@ -349,8 +349,7 @@ mod tests {
assert_eq!(parsed, Source::String(src.to_owned()));
let hardhat_src = format!(
r#"{{"_format": "hh-sol-artifact-1", "contractName": "Verifier", "sourceName": "contracts/verifier.sol", "abi": {}, "bytecode": "0x", "deployedBytecode": "0x", "linkReferences": {{}}, "deployedLinkReferences": {{}}}}"#,
src,
r#"{{"_format": "hh-sol-artifact-1", "contractName": "Verifier", "sourceName": "contracts/verifier.sol", "abi": {src}, "bytecode": "0x", "deployedBytecode": "0x", "linkReferences": {{}}, "deployedLinkReferences": {{}}}}"#,
);
let hardhat_parsed = Source::parse(&hardhat_src).unwrap();
assert_eq!(hardhat_parsed, Source::String(hardhat_src));

View File

@ -69,6 +69,9 @@ pub enum Chain {
Sepolia = 11155111,
Aurora = 1313161554,
AuroraTestnet = 1313161555,
Celo = 42220,
CeloAlfajores = 44787,
CeloBaklava = 62320,
}
// === impl Chain ===
@ -117,6 +120,9 @@ impl fmt::Display for Chain {
Chain::EvmosTestnet => "evmos-testnet",
Chain::Aurora => "aurora",
Chain::AuroraTestnet => "aurora-testnet",
Chain::Celo => "celo",
Chain::CeloAlfajores => "celo-alfajores",
Chain::CeloBaklava => "celo-baklava",
};
f.pad(chain)
@ -195,6 +201,9 @@ impl TryFrom<u64> for Chain {
9000 => Chain::EvmosTestnet,
1313161554 => Chain::Aurora,
1313161555 => Chain::AuroraTestnet,
42220 => Chain::Celo,
44787 => Chain::CeloAlfajores,
62320 => Chain::CeloBaklava,
_ => return Err(ParseChainError(chain.to_string())),
})
}
@ -255,6 +264,9 @@ impl FromStr for Chain {
"emerald-testnet" => Chain::EmeraldTestnet,
"aurora" => Chain::Aurora,
"aurora-testnet" => Chain::AuroraTestnet,
"celo" => Chain::Celo,
"celo-alfajores" => Chain::CeloAlfajores,
"celo-baklava" => Chain::CeloBaklava,
_ => return Err(ParseChainError(chain.to_owned())),
})
}
@ -293,6 +305,7 @@ impl Chain {
Chain::Oasis => 5_500,
Chain::Emerald => 6_000,
Chain::Dev | Chain::AnvilHardhat => 200,
Chain::Celo | Chain::CeloAlfajores | Chain::CeloBaklava => 5_000,
// Explictly handle all network to make it easier not to forget this match when new
// networks are added.
Chain::Morden |
@ -411,6 +424,15 @@ impl Chain {
}
Chain::Evmos => ("https://evm.evmos.org/api", "https://evm.evmos.org/"),
Chain::EvmosTestnet => ("https://evm.evmos.dev/api", "https://evm.evmos.dev/"),
Chain::Celo => {
("https://explorer.celo.org/mainnet", "https://explorer.celo.org/mainnet/api")
}
Chain::CeloAlfajores => {
("https://explorer.celo.org/alfajores", "https://explorer.celo.org/alfajores/api")
}
Chain::CeloBaklava => {
("https://explorer.celo.org/baklava", "https://explorer.celo.org/baklava/api")
}
Chain::AnvilHardhat | Chain::Dev | Chain::Morden | Chain::MoonbeamDev => {
// this is explicitly exhaustive so we don't forget to add new urls when adding a
// new chain
@ -440,7 +462,10 @@ impl Chain {
Chain::Rsk |
Chain::Oasis |
Chain::Emerald |
Chain::EmeraldTestnet,
Chain::EmeraldTestnet |
Chain::Celo |
Chain::CeloAlfajores |
Chain::CeloBaklava,
)
}
}

View File

@ -98,7 +98,10 @@ impl Client {
Chain::Cronos |
Chain::CronosTestnet |
Chain::Aurora |
Chain::AuroraTestnet => std::env::var("ETHERSCAN_API_KEY")?,
Chain::AuroraTestnet |
Chain::Celo |
Chain::CeloAlfajores |
Chain::CeloBaklava => std::env::var("ETHERSCAN_API_KEY")?,
Chain::Fantom | Chain::FantomTestnet => {
std::env::var("FTMSCAN_API_KEY").or_else(|_| std::env::var("FANTOMSCAN_API_KEY"))?
}

View File

@ -39,10 +39,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
r#"
Gas price
---------------
{:>10.2} gwei
{:>10.8} usd
"#,
gwei, usd_per_gas
{gwei:>10.2} gwei
{usd_per_gas:>10.8} usd
"#
);
Ok(())
}

View File

@ -1,4 +1,4 @@
use ethers::{abi::AbiDecode, prelude::*, providers::Middleware, utils::keccak256};
use ethers::{abi::AbiDecode, prelude::*, providers::Middleware};
use eyre::Result;
use std::sync::Arc;

View File

@ -37,8 +37,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Note that `log` has type AnswerUpdatedFilter
while let Some(Ok((log, meta))) = stream.next().await {
println!("{:?}", log);
println!("{:?}", meta)
println!("{log:?}");
println!("{meta:?}")
}
Ok(())

View File

@ -1,4 +1,4 @@
use ethers::{abi::AbiDecode, prelude::*, utils::keccak256};
use ethers::{abi::AbiDecode, prelude::*};
use eyre::Result;
use std::sync::Arc;