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

Upgrade subxt #6

Merged
merged 11 commits into from
Sep 3, 2021
Merged
1,096 changes: 690 additions & 406 deletions Cargo.lock

Large diffs are not rendered by default.

60 changes: 32 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "client", "proc-macro"]

[package]
name = "substrate-subxt"
version = "0.15.2"
version = "0.15.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

Expand All @@ -19,47 +19,51 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[features]
default = ["tokio1"]
client = ["substrate-subxt-client"]
# jsonrpsee http client can be configured to use tokio02 or tokio1.
tokio02 = ["jsonrpsee-http-client/tokio02"]
tokio1 = ["jsonrpsee-http-client/tokio1"]
# jsonrpsee can be configured to use tokio02 or tokio1.
tokio02 = ["jsonrpsee-http-client/tokio02", "jsonrpsee-ws-client/tokio02"]
tokio1 = ["jsonrpsee-http-client/tokio1", "jsonrpsee-ws-client/tokio1"]

[dependencies]
async-trait = "0.1.49"
log = "0.4.14"
thiserror = "1.0.24"
codec = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
dyn-clone = "1.0.4"
futures = "0.3.13"
jsonrpsee-proc-macros = "=0.2.0-alpha.6"
jsonrpsee-ws-client = "=0.2.0-alpha.6"
jsonrpsee-http-client = { version = "=0.2.0-alpha.6", default-features = false }
hex = "0.4.3"
jsonrpsee-proc-macros = "0.3.0"
jsonrpsee-ws-client = { version = "0.3.0", default-features = false }
jsonrpsee-http-client = { version = "0.3.0", default-features = false }
jsonrpsee-types = "0.3.0"
log = "0.4.14"
num-traits = { version = "0.2.14", default-features = false }
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
thiserror = "1.0.24"
url = "2.2.1"
codec = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
dyn-clone = "1.0.4"

frame-metadata = "13.0.0"
frame-support = "3.0.0"
sp-runtime = "3.0.0"
sp-version = "3.0.0"
pallet-indices = "3.0.0"
hex = "0.4.3"
sp-std = "3.0.0"
application-crypto = { version = "3.0.0", package = "sp-application-crypto" }
pallet-staking = "3.0.0"

sp-rpc = { version = "3.0.0", package = "sp-rpc" }
sp-core = { version = "3.0.0", package = "sp-core" }
substrate-subxt-client = { version = "0.7.0", path = "client", optional = true }
substrate-subxt-proc-macro = { version = "0.15.0", path = "proc-macro" }

sp-application-crypto = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sp-core = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sp-rpc = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sp-runtime = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sp-std = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sp-version = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }

frame-metadata = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
frame-support = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
pallet-indices = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
pallet-staking = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }


[dev-dependencies]
async-std = { version = "1.9.0", features = ["attributes"] }
assert_matches = "1.5.0"
async-std = { version = "1.9.0", features = ["attributes", "tokio1"] }
env_logger = "0.8.3"
frame-system = "3.0.0"
pallet-balances = "3.0.0"
sp-keyring = "3.0.0"
tempdir = "0.3.7"
wabt = "0.10.0"
which = "4.0.2"
assert_matches = "1.5.0"

sp-keyring = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
frame-system = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
pallet-balances = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
15 changes: 9 additions & 6 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ keywords = ["parity", "substrate", "blockchain"]
async-std = "1.8.0"
futures = { version = "0.3.9", features = ["compat"], package = "futures" }
futures01 = { package = "futures", version = "0.1.29" }
jsonrpsee-types = "=0.2.0-alpha.6"
jsonrpsee-types = "0.3.0"
log = "0.4.13"
sc-network = { version = "0.9.0", default-features = false }
sc-client-db = "0.9.0"
sc-service = { version = "0.9.0", default-features = false }
serde_json = "1.0.61"
sp-keyring = "3.0.0"
thiserror = "1.0.23"

sc-client-db = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sp-keyring = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }
sc-network = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3", default-features = false }
sc-service = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3", default-features = false }



[target.'cfg(target_arch="x86_64")'.dependencies]
sc-service = { version = "0.9.0", default-features = false, features = ["wasmtime"] }
sc-service = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3", default-features = false, features = ["wasmtime"] }

[dev-dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
Expand Down
69 changes: 34 additions & 35 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,31 @@ use futures01::sync::mpsc as mpsc01;
use jsonrpsee_types::{
v2::{
error::{
JsonRpcErrorAlloc,
JsonRpcError,
JsonRpcErrorCode,
},
params::{
Id,
JsonRpcParams,
JsonRpcSubscriptionParams,
SubscriptionId,
TwoPointZero,
},
parse_request_id,
request::{
JsonRpcCallSer,
JsonRpcInvalidRequest,
JsonRpcNotification,
JsonRpcNotificationSer,
},
response::{
JsonRpcNotifResponse,
JsonRpcResponse,
},
response::JsonRpcResponse,
},
DeserializeOwned,
Error as JsonRpseeError,
FrontToBack,
JsonValue,
RequestMessage,
Subscription,
SubscriptionKind,
SubscriptionMessage,
};
use sc_network::config::TransportConfig;
Expand All @@ -94,7 +93,6 @@ use sc_service::{
};
use std::{
collections::HashMap,
marker::PhantomData,
sync::atomic::{
AtomicU64,
Ordering,
Expand Down Expand Up @@ -211,7 +209,9 @@ impl SubxtClient {
while let Some(Ok(response)) = from_back.next().await
{
let notif = serde_json::from_str::<
JsonRpcNotifResponse<JsonValue>,
JsonRpcNotification<
JsonRpcSubscriptionParams<_>,
>,
>(
&response
)
Expand Down Expand Up @@ -241,7 +241,7 @@ impl SubxtClient {
let _ = rpc.rpc_query(&session, &message).await;
}
}
FrontToBack::Batch(_) => (),
_ => (),
}
}
})),
Expand Down Expand Up @@ -280,7 +280,7 @@ impl SubxtClient {
.clone()
.send(FrontToBack::Notification(msg))
.await
.map_err(|e| JsonRpseeError::TransportError(Box::new(e)))
.map_err(|e| JsonRpseeError::Transport(Box::new(e)))
}

/// Send a JSONRPC request.
Expand All @@ -306,12 +306,12 @@ impl SubxtClient {
send_back: Some(send_back_tx),
}))
.await
.map_err(|e| JsonRpseeError::TransportError(Box::new(e)))?;
.map_err(|e| JsonRpseeError::Transport(Box::new(e)))?;

let json_value = match send_back_rx.await {
Ok(Ok(v)) => v,
Ok(Err(err)) => return Err(err),
Err(err) => return Err(JsonRpseeError::TransportError(Box::new(err))),
Err(err) => return Err(JsonRpseeError::Transport(Box::new(err))),
};
serde_json::from_value(json_value).map_err(JsonRpseeError::ParseError)
}
Expand Down Expand Up @@ -351,14 +351,13 @@ impl SubxtClient {
let (notifs_rx, id) = match send_back_rx.await {
Ok(Ok(val)) => val,
Ok(Err(err)) => return Err(err),
Err(err) => return Err(JsonRpseeError::TransportError(Box::new(err))),
Err(err) => return Err(JsonRpseeError::Transport(Box::new(err))),
};
Ok(Subscription {
to_back: self.to_back.clone(),
Ok(Subscription::new(
self.to_back.clone(),
notifs_rx,
marker: PhantomData,
id,
})
SubscriptionKind::Subscription(id),
))
}
}

Expand All @@ -376,9 +375,10 @@ impl From<Role> for sc_service::Role {
match role {
Role::Light => Self::Light,
Role::Authority(_) => {
Self::Authority {
sentry_nodes: Default::default(),
}
// Self::Authority {
// sentry_nodes: Default::default(),
// }
Self::Authority
}
}
}
Expand Down Expand Up @@ -464,8 +464,8 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
telemetry_endpoints,

telemetry_external_transport: Default::default(),
telemetry_handle: Default::default(),
telemetry_span: Default::default(),
// telemetry_handle: Default::default(),
// telemetry_span: Default::default(),
default_heap_pages: Default::default(),
disable_grandpa: Default::default(),
disable_log_reloading: Default::default(),
Expand Down Expand Up @@ -512,26 +512,25 @@ fn read_jsonrpc_response(
maybe_msg: Option<String>,
id: Id,
) -> Option<Result<JsonValue, JsonRpseeError>> {
let msg = maybe_msg?;
match serde_json::from_str::<JsonRpcResponse<JsonValue>>(&msg) {
Ok(rp) => {
match parse_request_id::<Id>(rp.id) {
Ok(rp_id) if rp_id == id => Some(Ok(rp.result)),
_ => Some(Err(JsonRpseeError::InvalidRequestId)),
}
}
let msg: String = maybe_msg?;
// NOTE: `let res` is a workaround because rustc otherwise doesn't compile
// `msg` doesn't live long enough.
let res = match serde_json::from_str::<JsonRpcResponse<JsonValue>>(&msg) {
Ok(rp) if rp.id == id => Some(Ok(rp.result)),
Ok(_) => Some(Err(JsonRpseeError::InvalidRequestId)),
Err(_) => {
match serde_json::from_str::<JsonRpcInvalidRequest<'_>>(&msg) {
Ok(err) => {
let err = JsonRpcErrorAlloc {
let err = JsonRpcError {
jsonrpc: TwoPointZero,
error: JsonRpcErrorCode::InvalidRequest.into(),
id: parse_request_id(err.id).ok()?,
id: err.id,
};
Some(Err(JsonRpseeError::Request(err)))
Some(Err(JsonRpseeError::Request(err.to_string())))
}
Err(_) => None,
}
}
}
};
res
}
5 changes: 3 additions & 2 deletions proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substrate-subxt-proc-macro"
version = "0.15.2"
version = "0.15.3"
authors = ["David Craven <david@craven.ch>", "Parity Technologies <admin@parity.io>"]
edition = "2018"
autotests = false
Expand Down Expand Up @@ -29,10 +29,11 @@ async-std = { version = "1.8.0", features = ["attributes"] }
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }
env_logger = "0.8.2"
pretty_assertions = "0.6.1"
sp-keyring = "3.0.0"
substrate-subxt = { path = ".." }
trybuild = "1.0.38"

sp-keyring = { git = "https://github.com/darwinia-network/substrate.git", tag = "darwinia-v0.11.3" }

[[test]]
name = "balances"
path = "tests/balances.rs"
6 changes: 5 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use jsonrpsee_ws_client::Error as RequestError;
use jsonrpsee_types::Error as RequestError;
use sp_core::crypto::SecretStringError;
use sp_runtime::{
transaction_validity::TransactionValidityError,
Expand Down Expand Up @@ -140,6 +140,10 @@ impl RuntimeError {
DispatchError::ConsumerRemaining => Ok(Self::ConsumerRemaining),
DispatchError::NoProviders => Ok(Self::NoProviders),
DispatchError::Other(msg) => Ok(Self::Other(msg.into())),
DispatchError::Arithmetic(_err) => {
Ok(Self::Other("Arithmetic Err".to_string()))
}
DispatchError::Token(_err) => Ok(Self::Other("Token Err".to_string())),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mod tests {
ModuleMetadata,
RuntimeMetadata,
RuntimeMetadataPrefixed,
RuntimeMetadataV12,
RuntimeMetadataV13,
META_RESERVED,
};
use std::convert::TryFrom;
Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
let decoder = EventsDecoder::<TestRuntime>::new(
Metadata::try_from(RuntimeMetadataPrefixed(
META_RESERVED,
RuntimeMetadata::V12(RuntimeMetadataV12 {
RuntimeMetadata::V13(RuntimeMetadataV13 {
modules: DecodeDifferent::Decoded(vec![ModuleMetadata {
name: DecodeDifferent::Decoded("System".to_string()),
storage: None,
Expand Down
16 changes: 16 additions & 0 deletions src/frame/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ pub struct ValidatorsStore<T: Session> {
pub _runtime: PhantomData<T>,
}

/// The queued keys for the next session.
#[derive(Encode, Store, Debug)]
pub struct QueuedKeysStore<T: Session> {
#[store(returns = Vec<(<T as Session>::ValidatorId, T::Keys)>)]
/// Marker for the runtime
pub _runtime: PhantomData<T>,
}

/// The next session keys for a validator.
#[derive(Encode, Store, Debug)]
pub struct NextKeysStore<'a, T: Session> {
#[store(returns = Option<<T as Session>::Keys>)]
/// The validator account.
pub validator_id: &'a <T as Session>::ValidatorId,
}

default_impl!(ValidatorsStore);

/// Set the session keys for a validator.
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ use codec::{
};
use futures::future;
use jsonrpsee_http_client::HttpClientBuilder;
use jsonrpsee_ws_client::{
Subscription,
WsClientBuilder,
};
use jsonrpsee_types::Subscription;
use jsonrpsee_ws_client::WsClientBuilder;
use sp_core::{
storage::{
StorageChangeSet,
Expand Down Expand Up @@ -210,7 +208,7 @@ impl<T: Runtime> ClientBuilder<T> {
if url.starts_with("ws://") || url.starts_with("wss://") {
let client = WsClientBuilder::default()
.max_notifs_per_subscription(4096)
.build(&url)
.build(url)
.await?;
RpcClient::WebSocket(Arc::new(client))
} else {
Expand Down
Loading