Skip to content

Commit

Permalink
check script (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann authored Jan 18, 2024
1 parent f75bd6a commit 8d0abba
Show file tree
Hide file tree
Showing 35 changed files with 1,546 additions and 551,859 deletions.
1,548 changes: 1,020 additions & 528 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ rosetta-server = { path = "rosetta-server", default-features = false }
rosetta-types = { path = "rosetta-types" }

## Crates we want all members to use the same version
jsonrpsee = { version = "0.20", default-features = false }
jsonrpsee = { version = "0.21", default-features = false }
parity-scale-codec = { version = "3.6" }
tokio = { version = "1.32" }
subxt = { version = "0.32", default-features = false }
subxt = { version = "0.33", default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
scale-info = { version = "2.3" }
2 changes: 1 addition & 1 deletion chains/astar/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn config(network: &str) -> Result<BlockchainConfig> {
currency_symbol: symbol,
currency_decimals: 18,
node_uri: NodeUri::parse("ws://127.0.0.1:9945")?,
node_image: "staketechnologies/astar-collator:v5.15.0",
node_image: "staketechnologies/astar-collator:v5.28.0-rerun",
node_command: Arc::new(|network, port| {
let mut params = vec![
"astar-collator".into(),
Expand Down
8 changes: 4 additions & 4 deletions chains/astar/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ rosetta-server = { workspace = true, features = ["ws", "webpki-tls"] }
rosetta-server-ethereum.workspace = true
serde.workspace = true
serde_json.workspace = true
sp-core = { version = "21.0", default-features = false, features = ["blake2", "std"] }
sp-keyring = "24.0"
# sp-core = { version = "27.0", default-features = false, features = ["blake2", "std"] }
sp-keyring = "29.0"
subxt = { workspace = true, features = ["substrate-compat"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }

[dev-dependencies]
alloy-primitives = { version = "0.5" }
alloy-sol-types = { version = "0.5" }
alloy-primitives = { version = "0.6" }
alloy-sol-types = { version = "0.6" }
ethers-solc = "2.0"
rosetta-client.workspace = true
rosetta-docker = { workspace = true, features = ["tests"] }
Expand Down
2 changes: 1 addition & 1 deletion chains/astar/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ use rosetta_core::{
use rosetta_server::ws::default_client;
use rosetta_server_ethereum::MaybeWsEthereumClient;
use serde::{Deserialize, Serialize};
use sp_core::crypto::Ss58AddressFormat;
use std::sync::Arc;
use subxt::{
backend::{
legacy::{rpc_methods::BlockNumber, LegacyBackend, LegacyRpcMethods},
rpc::RpcClient,
},
dynamic::Value as SubtxValue,
ext::sp_core::{self, crypto::Ss58AddressFormat},
tx::PairSigner,
utils::AccountId32,
OnlineClient, PolkadotConfig,
Expand Down
7 changes: 4 additions & 3 deletions chains/ethereum/rpc-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use ethers::providers::{
JsonRpcError as EthJsonRpcError, ProviderError as EthProviderError,
RpcError as EthRpcErrorTrait,
};
use jsonrpsee::{client_transport::ws::WsHandshakeError, core::Error as JsonRpseeError};
use jsonrpsee::{client_transport::ws::WsHandshakeError, core::ClientError as JsonRpseeError};
use std::sync::Arc;

/// Adapter for [`jsonrpsee::core::Error`] to [`ethers::providers::RpcError`].
#[derive(Debug, thiserror::Error)]
Expand All @@ -22,7 +23,7 @@ pub enum EthError {

/// The background task has been terminated.
#[error("The background task been terminated because: {0}; restart required")]
RestartNeeded(String),
RestartNeeded(Arc<JsonRpseeError>),

/// The client is reconnecting
#[error("The client is restarting the background task")]
Expand All @@ -43,7 +44,7 @@ impl From<JsonRpseeError> for EthError {
}
},
JsonRpseeError::ParseError(serde_error) => Self::ParseError(serde_error),
JsonRpseeError::RestartNeeded(reason) => Self::RestartNeeded(reason),
JsonRpseeError::RestartNeeded(reason) => Self::RestartNeeded(Arc::clone(&reason)),
error => {
let message = format!("{}", &error);
Self::JsonRpsee {
Expand Down
10 changes: 5 additions & 5 deletions chains/ethereum/rpc-client/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ macro_rules! impl_client_trait {
) -> ::core::pin::Pin<
Box<
dyn ::core::future::Future<
Output = ::core::result::Result<(), ::jsonrpsee::core::Error>,
Output = ::core::result::Result<(), ::jsonrpsee::core::ClientError>,
> + ::core::marker::Send
+ 'async_trait,
>,
Expand All @@ -62,7 +62,7 @@ macro_rules! impl_client_trait {
params: Params,
) -> ::core::pin::Pin<
Box<
dyn ::core::future::Future<Output = ::core::result::Result<R, ::jsonrpsee::core::Error>>
dyn ::core::future::Future<Output = ::core::result::Result<R, ::jsonrpsee::core::ClientError>>
+ ::core::marker::Send
+ 'async_trait,
>,
Expand All @@ -89,7 +89,7 @@ macro_rules! impl_client_trait {
dyn ::core::future::Future<
Output = ::core::result::Result<
::jsonrpsee::core::client::BatchResponse<'a, R>,
::jsonrpsee::core::Error,
::jsonrpsee::core::ClientError,
>,
> + ::core::marker::Send
+ 'async_trait,
Expand Down Expand Up @@ -153,7 +153,7 @@ macro_rules! impl_subscription_trait {
Box<
dyn ::core::future::Future<Output = ::core::result::Result<
::jsonrpsee::core::client::Subscription<Notif>,
::jsonrpsee::core::Error
::jsonrpsee::core::ClientError
>>
+ ::core::marker::Send
+ 'async_trait,
Expand Down Expand Up @@ -185,7 +185,7 @@ macro_rules! impl_subscription_trait {
Box<
dyn ::core::future::Future<Output = ::core::result::Result<
::jsonrpsee::core::client::Subscription<Notif>,
::jsonrpsee::core::Error
::jsonrpsee::core::ClientError
>>
+ ::core::marker::Send
+ 'async_trait,
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/rpc-client/src/params.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use jsonrpsee::core::{error::Error as JsonRpseeError, traits::ToRpcParams};
use jsonrpsee::core::traits::ToRpcParams;
use serde::{de::DeserializeOwned, Serialize};
use serde_json::value::RawValue;
use std::fmt::{Display, Formatter};
Expand All @@ -23,7 +23,7 @@ impl EthRpcParams {
}

impl ToRpcParams for EthRpcParams {
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, JsonRpseeError> {
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, serde_json::Error> {
Ok(Some(self.0))
}
}
Expand Down
2 changes: 1 addition & 1 deletion chains/ethereum/rpc-client/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ethers::{
use jsonrpsee::{
core::{
client::{ClientT, Subscription, SubscriptionClientT, SubscriptionKind},
error::Error as JsonRpseeError,
ClientError as JsonRpseeError,
},
types::SubscriptionId,
};
Expand Down
6 changes: 2 additions & 4 deletions chains/ethereum/rpc-client/src/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ethers::types::U256;
use futures_util::{future::BoxFuture, FutureExt, Stream, StreamExt};
use jsonrpsee::core::{client::Subscription, error::Error as JsonRpseeError};
use jsonrpsee::core::{client::Subscription, ClientError as JsonRpseeError};
use pin_project::pin_project;
use serde_json::value::RawValue;
use std::{
Expand Down Expand Up @@ -135,10 +135,8 @@ impl Stream for EthSubscription {
JsonRpseeError::RestartNeeded(_) |
JsonRpseeError::InvalidSubscriptionId |
JsonRpseeError::InvalidRequestId(_) |
JsonRpseeError::UnregisteredNotification(_) |
JsonRpseeError::SubscriptionNameConflict(_) |
JsonRpseeError::RequestTimeout |
JsonRpseeError::AlreadyStopped => {},
JsonRpseeError::RegisterMethod(_) => {},
JsonRpseeError::Custom(reason) => {
tracing::warn!("failed to unsubscribe: \"{reason}\"");
},
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 @@ -102,7 +102,7 @@ where
}

pub async fn finalized_block(&self, latest_block: Option<u64>) -> Result<NonPendingBlock> {
let number = match self.block_finality_strategy {
let number: BlockNumber = match self.block_finality_strategy {
BlockFinalityStrategy::Confirmations(confirmations) => {
let latest_block = match latest_block {
Some(number) => number,
Expand Down
2 changes: 1 addition & 1 deletion chains/ethereum/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl MaybeWsEthereumClient {
"ethereum" => rosetta_config_ethereum::config(network)?,
"polygon" => rosetta_config_ethereum::polygon_config(network)?,
"arbitrum" => rosetta_config_ethereum::arbitrum_config(network)?,
blockchain => anyhow::bail!("1unsupported blockchain: {blockchain}"),
blockchain => anyhow::bail!("unsupported blockchain: {blockchain}"),
};
Self::from_config(config, addr).await
}
Expand Down
6 changes: 6 additions & 0 deletions chains/polkadot/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ anyhow = "1.0"
rosetta-core.workspace = true
serde.workspace = true
subxt = { workspace = true, features = ["substrate-compat", "native"] }

[features]
default = ["polkadot-metadata", "westend-metadata", "rococo-metadata"]
polkadot-metadata = []
westend-metadata = []
rococo-metadata = []
Binary file not shown.
Binary file removed chains/polkadot/config/res/polkadot-v9430.scale
Binary file not shown.
Binary file not shown.
48 changes: 33 additions & 15 deletions chains/polkadot/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ use std::sync::Arc;
use subxt::ext::sp_core::crypto::Ss58AddressFormat;

// Generate an interface that we can use from the node's metadata.

pub mod metadata {
#[subxt::subxt(runtime_metadata_path = "res/polkadot-v9430.scale")]
pub mod dev {}
#[cfg(feature = "polkadot-metadata")]
pub mod polkadot {
#[subxt::subxt(runtime_metadata_path = "res/polkadot-v1000001.scale")]
pub mod dev {}
}

#[cfg(feature = "westend-metadata")]
pub mod westend {
#[subxt::subxt(runtime_metadata_path = "res/westend-dev-v1.5.0.scale")]
pub mod dev {}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -31,15 +41,31 @@ impl TryFrom<&str> for PolkadotNetworkProperties {

fn try_from(value: &str) -> std::result::Result<Self, Self::Error> {
// To see all available blockchains and networks, see:
// https://github.com/paritytech/polkadot/blob/v1.0.0/cli/src/command.rs#L93-L145
// https://github.com/paritytech/polkadot-sdk/blob/v1.5.0-rc4/polkadot/cli/src/command.rs#L87-L154
// All blockchains in polkadot have "dev", "local" and "staging" variants

// "dev" and "polkadot-dev" are the same
let chain = if value == "dev" { "polkadot-dev" } else { value };
// "dev" and "rococo-dev" are the same
let chain = if value == "dev" { "rococo-dev" } else { value };

// Split blockchain and network
let (blockchain, network) = chain.split_once('-').unwrap_or((chain, ""));

// Convert network to &'static str
let network = match network {
"" | "mainnet" => "mainnet",
"dev" => "dev",
"local" => "local",
"staging" => "staging",
_ => anyhow::bail!("unsupported network: {blockchain}-{network}"),
};

// Since polkadot v1.2.0 the native runtime is no longer part of the node.
// Reference:
// https://github.com/paritytech/polkadot-sdk/compare/v1.1.0-rc2...v1.2.0-rc1#diff-67483124e887614f5d8edc2a46dd5329354bc294ed58bc1748f41dfeb6ec2404R90-R93
if matches!(blockchain, "polkadot" | "kusama") && network != "mainnet" {
anyhow::bail!("{blockchain}-{network} is not supported anymore as the polkadot native runtime no longer part of the node.");
}

// Convert blockchain to &'static str
let blockchain = match blockchain {
"polkadot" => "polkadot",
Expand All @@ -51,15 +77,6 @@ impl TryFrom<&str> for PolkadotNetworkProperties {
_ => anyhow::bail!("unsupported blockchain: {}", blockchain),
};

// Convert network to &'static str
let network = match network {
"" => "mainnet",
"dev" => "dev",
"local" => "local",
"staging" => "staging",
_ => anyhow::bail!("unsupported network: {blockchain}-{network}"),
};

// Get blockchain parameters
let (symbol, bip44_id, decimals, ss58_format) = match (blockchain, network) {
// Polkadot mainnet and dev networks
Expand All @@ -77,6 +94,7 @@ impl TryFrom<&str> for PolkadotNetworkProperties {
("westend", _) => ("WND", 1, 12, Ss58AddressFormatRegistry::SubstrateAccount),

// Wococo
("wococo", "staging") => anyhow::bail!("wococo doesn't have staging network"),
("wococo", _) => ("WOCO", 1, 12, Ss58AddressFormatRegistry::SubstrateAccount),

// Versi
Expand Down Expand Up @@ -129,7 +147,7 @@ pub fn config(network: &str) -> Result<BlockchainConfig> {
currency_symbol: properties.symbol,
currency_decimals: properties.decimals,
node_uri: NodeUri::parse("ws://127.0.0.1:9944")?,
node_image: "parity/polkadot:v1.0.0",
node_image: "parity/polkadot:v1.5.0",
node_command: Arc::new(move |network, port| {
let chain = if network == "mainnet" {
blockchain.to_string()
Expand Down
Loading

0 comments on commit 8d0abba

Please sign in to comment.