From 4bdb1693342a854ecd9c1e12c89649809f950326 Mon Sep 17 00:00:00 2001 From: ManojJiSharma Date: Wed, 11 Oct 2023 22:03:23 +0530 Subject: [PATCH 1/5] Initial commit --- .gitignore | 1 + .vscode/settings.json | 4 ++++ Cargo.lock | 9 +++++++++ Cargo.toml | 1 + chains/ethereum/config/src/lib.rs | 21 +++++++++++++++++++++ chains/ethereum/server/src/client.rs | 2 +- chains/ethereum/server/src/lib.rs | 3 ++- rosetta-client/src/client.rs | 6 +++++- rosetta-client/src/lib.rs | 3 +++ 9 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 9df2e92d..0deed88a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ # These are backup files generated by rustfmt **/*.rs.bk +/connector-test \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e909088e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "rust-analyzer.check.command": "clippy", + "rust-analyzer.check.extraArgs": ["--", "-Dwarnings", "-Dclippy::unwrap_used", "-Dclippy::expect_used", "-Dclippy::nursery", "-Dclippy::pedantic", "-Aclippy::module_name_repetitions"] + } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d7e64ad1..fc6ee10e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1040,6 +1040,15 @@ dependencies = [ "serde", ] +[[package]] +name = "connector-test" +version = "0.1.0" +dependencies = [ + "futures-util", + "rosetta-client", + "tokio", +] + [[package]] name = "const-hex" version = "1.9.1" diff --git a/Cargo.toml b/Cargo.toml index 69c0e929..4ce65e66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,5 +17,6 @@ members = [ "rosetta-docker", "rosetta-server", "rosetta-types", + "connector-test", ] resolver = "2" diff --git a/chains/ethereum/config/src/lib.rs b/chains/ethereum/config/src/lib.rs index cd623e73..368342d9 100644 --- a/chains/ethereum/config/src/lib.rs +++ b/chains/ethereum/config/src/lib.rs @@ -22,6 +22,21 @@ pub fn polygon_config(network: &str) -> Result { Ok(evm_config("polygon", network, "MATIC", bip44_id, is_dev)) } +/// Retrieve the [`BlockchainConfig`] from the provided arbitrum `network` +/// +/// # Errors +/// Returns `Err` if the network is not supported +pub fn arbitrum_config(network: &str) -> Result { + let (network, bip44_id, is_dev) = match network { + "dev" => ("dev", 1, true), + "goerli" => ("goerli", 1, true), + "mainnet" => ("mainnet", 42161, false), + _ => anyhow::bail!("unsupported network: {}", network), + }; + + Ok(evm_config("arbitrum", network, "ARB", bip44_id, is_dev)) +} + /// Retrieve the [`BlockchainConfig`] from the provided ethereum `network` /// /// # Errors @@ -39,6 +54,12 @@ pub fn config(network: &str) -> Result { // Astar "astar-local" => return astar_config("dev"), + + // Arbitrum + "arbitrum-local" => return arbitrum_config("dev"), + "arbitrum" => return arbitrum_config("mainnet"), + "arbitrum-goerli" => return arbitrum_config("goerli"), + network => return astar_config(network), }; diff --git a/chains/ethereum/server/src/client.rs b/chains/ethereum/server/src/client.rs index f8c0d850..e2a69f6b 100644 --- a/chains/ethereum/server/src/client.rs +++ b/chains/ethereum/server/src/client.rs @@ -83,7 +83,7 @@ where pub async fn finalized_block(&self) -> Result { // TODO: ISSUE-176 Create a new connector for polygon - let block = if self.config.blockchain == "polygon" { + let block = if self.config.blockchain == "polygon" || self.config.blockchain == "Arbitrum" { let Some(latest_block) = self.client.get_block(BlockId::Number(BlockNumber::Latest)).await? else { diff --git a/chains/ethereum/server/src/lib.rs b/chains/ethereum/server/src/lib.rs index 2f8eba05..88b79347 100644 --- a/chains/ethereum/server/src/lib.rs +++ b/chains/ethereum/server/src/lib.rs @@ -44,7 +44,8 @@ impl MaybeWsEthereumClient { let config = match blockchain { "polygon" => rosetta_config_ethereum::polygon_config(network)?, "ethereum" => rosetta_config_ethereum::config(network)?, - blockchain => anyhow::bail!("unsupported blockchain: {blockchain}"), + "Arbitrum" => rosetta_config_ethereum::config(network)?, + blockchain => anyhow::bail!("1unsupported blockchain: {blockchain}"), }; Self::from_config(config, addr).await } diff --git a/rosetta-client/src/client.rs b/rosetta-client/src/client.rs index b95e7ca2..c3f711a4 100644 --- a/rosetta-client/src/client.rs +++ b/rosetta-client/src/client.rs @@ -47,6 +47,10 @@ impl GenericClient { let client = EthereumClient::new("polygon", network, url).await?; Self::Ethereum(client) }, + Blockchain::Arbitrum => { + let client = EthereumClient::new("Arbitrum", network, url).await?; + Self::Ethereum(client) + }, Blockchain::Astar => { let client = AstarClient::new(network, url).await?; Self::Astar(client) @@ -65,7 +69,7 @@ impl GenericClient { let client = BitcoinClient::from_config(config, url).await?; Self::Bitcoin(client) }, - Blockchain::Ethereum | Blockchain::Polygon => { + Blockchain::Ethereum | Blockchain::Polygon | Blockchain::Arbitrum => { let client = EthereumClient::from_config(config, url).await?; Self::Ethereum(client) }, diff --git a/rosetta-client/src/lib.rs b/rosetta-client/src/lib.rs index 4d416d5b..43ead771 100644 --- a/rosetta-client/src/lib.rs +++ b/rosetta-client/src/lib.rs @@ -27,6 +27,8 @@ pub enum Blockchain { Polkadot, /// Polygon Polygon, + /// Arbitrum + Arbitrum, } impl std::str::FromStr for Blockchain { @@ -39,6 +41,7 @@ impl std::str::FromStr for Blockchain { "astar" => Self::Astar, "polkadot" => Self::Polkadot, "polygon" => Self::Polygon, + "arbitrum" => Self::Arbitrum, _ => anyhow::bail!("unsupported blockchain {}", blockchain), }) } From 4c4b53e5e94eedfeb3749c5dcc3922f32bfa3d64 Mon Sep 17 00:00:00 2001 From: Manoj Sharma <87001470+ManojJiSharma@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:23:59 +0530 Subject: [PATCH 2/5] Delete .vscode/settings.json --- .vscode/settings.json | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e909088e..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "rust-analyzer.check.command": "clippy", - "rust-analyzer.check.extraArgs": ["--", "-Dwarnings", "-Dclippy::unwrap_used", "-Dclippy::expect_used", "-Dclippy::nursery", "-Dclippy::pedantic", "-Aclippy::module_name_repetitions"] - } \ No newline at end of file From 2c331c40a6972a673115da92ad5ab25e576bad11 Mon Sep 17 00:00:00 2001 From: Manoj Sharma <87001470+ManojJiSharma@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:24:30 +0530 Subject: [PATCH 3/5] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0deed88a..9df2e92d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ # These are backup files generated by rustfmt **/*.rs.bk -/connector-test \ No newline at end of file From bda787dedd7e0fe58299631f5b9956417dbe8341 Mon Sep 17 00:00:00 2001 From: Manoj Sharma <87001470+ManojJiSharma@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:36:13 +0530 Subject: [PATCH 4/5] Update Cargo.toml --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4ce65e66..69c0e929 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,5 @@ members = [ "rosetta-docker", "rosetta-server", "rosetta-types", - "connector-test", ] resolver = "2" From 4b1f9dd0c76919715e0584949af3c4a9db6a244f Mon Sep 17 00:00:00 2001 From: ManojJiSharma Date: Fri, 13 Oct 2023 21:10:52 +0530 Subject: [PATCH 5/5] variable case fix --- Cargo.lock | 9 --------- chains/ethereum/server/src/lib.rs | 2 +- rosetta-client/src/client.rs | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc6ee10e..d7e64ad1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1040,15 +1040,6 @@ dependencies = [ "serde", ] -[[package]] -name = "connector-test" -version = "0.1.0" -dependencies = [ - "futures-util", - "rosetta-client", - "tokio", -] - [[package]] name = "const-hex" version = "1.9.1" diff --git a/chains/ethereum/server/src/lib.rs b/chains/ethereum/server/src/lib.rs index 88b79347..c7a21fb7 100644 --- a/chains/ethereum/server/src/lib.rs +++ b/chains/ethereum/server/src/lib.rs @@ -44,7 +44,7 @@ impl MaybeWsEthereumClient { let config = match blockchain { "polygon" => rosetta_config_ethereum::polygon_config(network)?, "ethereum" => rosetta_config_ethereum::config(network)?, - "Arbitrum" => rosetta_config_ethereum::config(network)?, + "arbitrum" => rosetta_config_ethereum::config(network)?, blockchain => anyhow::bail!("1unsupported blockchain: {blockchain}"), }; Self::from_config(config, addr).await diff --git a/rosetta-client/src/client.rs b/rosetta-client/src/client.rs index c3f711a4..340637b9 100644 --- a/rosetta-client/src/client.rs +++ b/rosetta-client/src/client.rs @@ -48,7 +48,7 @@ impl GenericClient { Self::Ethereum(client) }, Blockchain::Arbitrum => { - let client = EthereumClient::new("Arbitrum", network, url).await?; + let client = EthereumClient::new("arbitrum", network, url).await?; Self::Ethereum(client) }, Blockchain::Astar => {