Skip to content

Commit

Permalink
refactor: use proper subxt upstream (0.22.0)
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Oct 12, 2022
1 parent 8083038 commit 5c5ecf6
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 556 deletions.
808 changes: 329 additions & 479 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions runtime/Cargo.toml
Expand Up @@ -36,18 +36,17 @@ lazy_static = "1.4.0"

# Substrate dependencies
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }

# Subxt dependencies
# https://github.com/interlay/subxt/tree/polkadot-v0.9.26
subxt = { package = "subxt", git = "https://github.com/interlay/subxt", rev = "cad1564b487f59c53840894607debf1aaae7a2f7" }
subxt-client = { package = "subxt-client", path = "./client", optional = true }
sp-keyring = "6.0.0"

jsonrpsee = { version = "0.10.1", features = ["macros", "jsonrpsee-types", "client", "jsonrpsee-ws-client", "jsonrpsee-client-transport"] }
# Subxt dependencies
subxt = "0.22.0"
subxt-client = { path = "./client", optional = true }
jsonrpsee = { version = "0.14.0", features = ["async-client", "client-ws-transport", "macros", "jsonrpsee-types", "client", "jsonrpsee-ws-client", "jsonrpsee-client-transport"] }

bitcoin = { path = "../bitcoin"}

Expand Down
9 changes: 5 additions & 4 deletions runtime/client/Cargo.toml
Expand Up @@ -15,16 +15,17 @@ keywords = ["parity", "substrate", "blockchain"]
tokio = { version = "1.10", features = ["time", "rt-multi-thread"] }
futures = { version = "0.3.9", features = ["compat"], package = "futures" }
futures01 = { package = "futures", version = "0.1.29" }
jsonrpsee = "0.10.1"
jsonrpsee-types = "0.10.1"
jsonrpsee-core = { version = "0.10.1", features = ["async-client"] }
jsonrpsee = "0.14.0"
jsonrpsee-types = "0.14.0"
jsonrpsee-core = { version = "0.14.0", features = ["async-client"] }

log = "0.4.13"
serde_json = "1.0.61"
thiserror = "1.0.23"

sp-keyring = "6.0.0"

sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.26", default-features = false }

Expand Down
12 changes: 8 additions & 4 deletions runtime/client/src/lib.rs
Expand Up @@ -6,7 +6,7 @@ use futures::{
};
use jsonrpsee_core::{
async_trait,
client::{Client as JsonRpcClient, TransportReceiverT, TransportSenderT},
client::{Client as JsonRpcClient, ClientBuilder, ReceivedMessage, TransportReceiverT, TransportSenderT},
};
use sc_network::config::TransportConfig;
pub use sc_service::{
Expand Down Expand Up @@ -46,15 +46,19 @@ impl TransportSenderT for Sender {
self.0.send(msg).await?;
Ok(())
}

async fn send_ping(&mut self) -> Result<(), Self::Error> {
unimplemented!()
}
}

#[async_trait]
impl TransportReceiverT for Receiver {
type Error = SubxtClientError;

async fn receive(&mut self) -> Result<String, Self::Error> {
async fn receive(&mut self) -> Result<ReceivedMessage, Self::Error> {
let msg = self.0.next().await.expect("channel should be open");
Ok(msg)
Ok(ReceivedMessage::Text(msg))
}
}

Expand Down Expand Up @@ -144,7 +148,7 @@ impl Clone for SubxtClient {

impl From<SubxtClient> for JsonRpcClient {
fn from(client: SubxtClient) -> Self {
(client.sender, client.receiver).into()
ClientBuilder::default().build_with_tokio(client.sender, client.receiver)
}
}

Expand Down
29 changes: 12 additions & 17 deletions runtime/src/error.rs
Expand Up @@ -2,7 +2,11 @@ pub use jsonrpsee::core::Error as JsonRpseeError;

use crate::{metadata::DispatchError, types::*, BTC_RELAY_MODULE, ISSUE_MODULE, SYSTEM_MODULE};
use codec::Error as CodecError;
use jsonrpsee::{client_transport::ws::WsHandshakeError, core::error::Error as RequestError, types::error::CallError};
use jsonrpsee::{
client_transport::ws::WsHandshakeError,
core::error::Error as RequestError,
types::error::{CallError, ErrorObjectOwned},
};
use prometheus::Error as PrometheusError;
use serde_json::Error as SerdeJsonError;
use std::{array::TryFromSliceError, fmt::Debug, io::Error as IoError, num::TryFromIntError, str::Utf8Error};
Expand Down Expand Up @@ -114,35 +118,26 @@ impl Error {
self.is_module_err(ISSUE_MODULE, &format!("{:?}", IssuePalletError::IssueCompleted))
}

fn map_call_error<T>(&self, call: impl Fn(&CallError) -> Option<T>) -> Option<T> {
fn map_custom_error<T>(&self, call: impl Fn(&ErrorObjectOwned) -> Option<T>) -> Option<T> {
match self {
Error::SubxtRuntimeError(SubxtError::Rpc(RequestError::Call(err))) => call(err),
Error::SubxtRuntimeError(SubxtError::Rpc(RequestError::Call(CallError::Custom(err)))) => call(err),
_ => None,
}
}

pub fn is_invalid_transaction(&self) -> Option<String> {
self.map_call_error(|call_error| {
if let CallError::Custom {
code: POOL_INVALID_TX,
data,
..
} = call_error
{
Some(data.clone().map(|raw| raw.to_string()).unwrap_or_default())
self.map_custom_error(|custom_error| {
if custom_error.code() == POOL_INVALID_TX {
Some(custom_error.data().map(ToString::to_string).unwrap_or_default())
} else {
None
}
})
}

pub fn is_pool_too_low_priority(&self) -> Option<()> {
self.map_call_error(|call_error| {
if let CallError::Custom {
code: POOL_TOO_LOW_PRIORITY,
..
} = call_error
{
self.map_custom_error(|custom_error| {
if custom_error.code() == POOL_TOO_LOW_PRIORITY {
Some(())
} else {
None
Expand Down
10 changes: 5 additions & 5 deletions runtime/src/lib.rs
Expand Up @@ -41,7 +41,7 @@ pub use sp_arithmetic::{traits as FixedPointTraits, FixedI128, FixedPointNumber,
use std::time::Duration;
pub use subxt::{
extrinsic::Signer,
sp_core::{crypto::Ss58Codec, sr25519::Pair},
sp_core::{self, crypto::Ss58Codec, sr25519::Pair},
};
pub use types::*;

Expand All @@ -62,28 +62,28 @@ pub const STABLE_PARACHAIN_CONFIRMATIONS: &str = "StableParachainConfirmations";
feature = "parachain-metadata-interlay",
subxt(
runtime_metadata_path = "metadata-parachain-interlay.scale",
generated_type_derives = "Eq, PartialEq, Ord, PartialOrd, Clone"
derive_for_all_types = "Eq, PartialEq, Ord, PartialOrd, Clone"
)
)]
#[cfg_attr(
feature = "parachain-metadata-kintsugi",
subxt(
runtime_metadata_path = "metadata-parachain-kintsugi.scale",
generated_type_derives = "Eq, PartialEq, Ord, PartialOrd, Clone"
derive_for_all_types = "Eq, PartialEq, Ord, PartialOrd, Clone"
)
)]
#[cfg_attr(
feature = "parachain-metadata-interlay-testnet",
subxt(
runtime_metadata_path = "metadata-parachain-interlay-testnet.scale",
generated_type_derives = "Eq, PartialEq, Ord, PartialOrd, Clone"
derive_for_all_types = "Eq, PartialEq, Ord, PartialOrd, Clone"
)
)]
#[cfg_attr(
feature = "parachain-metadata-kintsugi-testnet",
subxt(
runtime_metadata_path = "metadata-parachain-kintsugi-testnet.scale",
generated_type_derives = "Eq, PartialEq, Ord, PartialOrd, Clone"
derive_for_all_types = "Eq, PartialEq, Ord, PartialOrd, Clone"
)
)]
pub mod metadata {
Expand Down

0 comments on commit 5c5ecf6

Please sign in to comment.