Skip to content
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

add_Arbitrum_config #192

Merged
merged 5 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions chains/ethereum/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ pub fn polygon_config(network: &str) -> Result<BlockchainConfig> {
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<BlockchainConfig> {
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
Expand All @@ -39,6 +54,12 @@ pub fn config(network: &str) -> Result<BlockchainConfig> {

// 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),
};

Expand Down
2 changes: 1 addition & 1 deletion chains/ethereum/server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ where

pub async fn finalized_block(&self) -> Result<BlockIdentifier> {
// 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 {
Expand Down
3 changes: 2 additions & 1 deletion chains/ethereum/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Lohann marked this conversation as resolved.
Show resolved Hide resolved
blockchain => anyhow::bail!("1unsupported blockchain: {blockchain}"),
};
Self::from_config(config, addr).await
}
Expand Down
6 changes: 5 additions & 1 deletion rosetta-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Lohann marked this conversation as resolved.
Show resolved Hide resolved
Self::Ethereum(client)
},
Blockchain::Astar => {
let client = AstarClient::new(network, url).await?;
Self::Astar(client)
Expand All @@ -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)
},
Expand Down
3 changes: 3 additions & 0 deletions rosetta-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum Blockchain {
Polkadot,
/// Polygon
Polygon,
/// Arbitrum
Arbitrum,
}

impl std::str::FromStr for Blockchain {
Expand All @@ -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),
})
}
Expand Down
Loading