Skip to content

Commit

Permalink
Merge branch 'master' into staking
Browse files Browse the repository at this point in the history
* master:
  decode option event arg (#158)
  Release v0.12.0 (#157)
  Only return an error if the extrinsic failed. (#156)
  Update to rc6. (#155)
  Different assert. (#153)
  Add a method to fetch an unhashed key, close #100 (#152)
  Fix port number. (#151)
  • Loading branch information
dvdplm committed Sep 11, 2020
2 parents c330e68 + e85d01e commit 773d43e
Show file tree
Hide file tree
Showing 19 changed files with 411 additions and 319 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 0.12.0

* Only return an error if the extrinsic failed. [#156](https://github.com/paritytech/substrate-subxt/pull/156)
* Update to rc6. [#155](https://github.com/paritytech/substrate-subxt/pull/155)
* Different assert. [#153](https://github.com/paritytech/substrate-subxt/pull/153)
* Add a method to fetch an unhashed key, close #100 [#152](https://github.com/paritytech/substrate-subxt/pull/152)
* Fix port number. [#151](https://github.com/paritytech/substrate-subxt/pull/151)
* Implement the `concat` in `twox_64_concat` [#150](https://github.com/paritytech/substrate-subxt/pull/150)
* Storage map iter [#148](https://github.com/paritytech/substrate-subxt/pull/148)

# Version 0.11.0

* Fix build error, wabt 0.9.2 is yanked [#146](https://github.com/paritytech/substrate-subxt/pull/146)
Expand Down Expand Up @@ -29,7 +39,7 @@
# Version 0.8.0 (2020-05-26)

* Update to Substrate release candidate [#116](https://github.com/paritytech/substrate-subxt/pull/116)
* Update to alpha.8 [#114]c
* Update to alpha.8 [#114](https://github.com/paritytech/substrate-subxt/pull/114)
* Refactors the api [#113](https://github.com/paritytech/substrate-subxt/pull/113)

# Version 0.7.0 (2020-05-13)
Expand Down
53 changes: 27 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "client", "proc-macro", "test-node"]

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

Expand All @@ -27,39 +27,40 @@ thiserror = "1.0.20"
futures = "0.3.5"
jsonrpsee = { version = "0.1.0", features = ["ws"] }
num-traits = { version = "0.2.12", default-features = false }
serde = { version = "1.0.114", features = ["derive"] }
serde_json = "1.0.56"
serde = { version = "1.0.115", features = ["derive"] }
serde_json = "1.0.57"
url = "2.1.1"
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive", "full"] }

frame-metadata = { version = "11.0.0-rc5", package = "frame-metadata" }
frame-support = { version = "2.0.0-rc5", package = "frame-support" }
sp-runtime = { version = "2.0.0-rc5", package = "sp-runtime" }
sp-version = { version = "2.0.0-rc5", package = "sp-version" }
pallet-indices = { version = "2.0.0-rc5", package = "pallet-indices" }
frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" }
frame-support = { version = "2.0.0-rc6", package = "frame-support" }
sp-runtime = { version = "2.0.0-rc6", package = "sp-runtime" }
sp-version = { version = "2.0.0-rc6", package = "sp-version" }
pallet-indices = { version = "2.0.0-rc6", package = "pallet-indices" }
hex = "0.4.2"
sp-std = "2.0.0-rc5"
application-crypto = { version = "2.0.0-rc5", package = "sp-application-crypto", default-features = false }
sp-finality-grandpa = "2.0.0-rc5"
sp-consensus-babe = "0.8.0-rc5"
pallet-im-online = "2.0.0-rc5"
sp-authority-discovery = "2.0.0-rc5"
pallet-staking = "2.0.0-rc5"

sp-rpc = { version = "2.0.0-rc5", package = "sp-rpc" }
sp-core = { version = "2.0.0-rc5", package = "sp-core" }
sc-rpc-api = { version = "0.8.0-rc5", package = "sc-rpc-api" }
sp-transaction-pool = { version = "2.0.0-rc5", package = "sp-transaction-pool" }
substrate-subxt-client = { version = "0.3.0", path = "client", optional = true }
substrate-subxt-proc-macro = { version = "0.11.0", path = "proc-macro" }
sp-std = "2.0.0-rc6"
application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto", default-features = false }
sp-finality-grandpa = "2.0.0-rc6"
sp-consensus-babe = "0.8.0-rc6"
pallet-im-online = "2.0.0-rc6"
sp-authority-discovery = "2.0.0-rc6"
pallet-staking = "2.0.0-rc6"

sp-rpc = { version = "2.0.0-rc6", package = "sp-rpc" }
sp-core = { version = "2.0.0-rc6", package = "sp-core" }
sc-rpc-api = { version = "0.8.0-rc6", package = "sc-rpc-api" }
sp-transaction-pool = { version = "2.0.0-rc6", package = "sp-transaction-pool" }
substrate-subxt-client = { version = "0.4.0", path = "client", optional = true }
substrate-subxt-proc-macro = { version = "0.12.0", path = "proc-macro" }

[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
async-std = { version = "1.6.3", features = ["attributes"] }
env_logger = "0.7.1"
frame-system = { version = "2.0.0-rc5", package = "frame-system" }
pallet-balances = { version = "2.0.0-rc5", package = "pallet-balances" }
sp-keyring = { version = "2.0.0-rc5", package = "sp-keyring" }
substrate-subxt-client = { version = "0.3.0", path = "client" }
frame-system = { version = "2.0.0-rc6", package = "frame-system" }
pallet-balances = { version = "2.0.0-rc6", package = "pallet-balances" }
sp-keyring = { version = "2.0.0-rc6", package = "sp-keyring" }
substrate-subxt-client = { version = "0.4.0", path = "client" }
tempdir = "0.3.7"
test-node = { path = "test-node" }
wabt = "0.10.0"
14 changes: 7 additions & 7 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substrate-subxt-client"
version = "0.3.0"
version = "0.4.0"
authors = ["David Craven <david@craven.ch>", "Parity Technologies <admin@parity.io>"]
edition = "2018"

Expand All @@ -12,19 +12,19 @@ description = "Embed a substrate node into your subxt application."
keywords = ["parity", "substrate", "blockchain"]

[dependencies]
async-std = "1.6.2"
async-std = "1.6.3"
futures = { version = "0.3.5", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }
jsonrpsee = "0.1.0"
log = "0.4.11"
sc-network = { version = "0.8.0-rc5", default-features = false }
sc-service = { version = "0.8.0-rc5", default-features = false }
serde_json = "1.0.56"
sp-keyring = "2.0.0-rc5"
sc-network = { version = "0.8.0-rc6", default-features = false }
sc-service = { version = "0.8.0-rc6", default-features = false }
serde_json = "1.0.57"
sp-keyring = "2.0.0-rc6"
thiserror = "1.0.20"

[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
async-std = { version = "1.6.3", features = ["attributes"] }
env_logger = "0.7.1"
substrate-subxt = { path = ".." }
tempdir = "0.3.7"
Expand Down
32 changes: 15 additions & 17 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use sc_service::{
use std::{
future::Future,
pin::Pin,
sync::Arc,
};
use thiserror::Error;

Expand All @@ -87,17 +86,16 @@ pub struct SubxtClient {

impl SubxtClient {
/// Create a new client.
pub fn new(mut task_manager: TaskManager, rpc: Arc<RpcHandlers>) -> Self {
pub fn new(mut task_manager: TaskManager, rpc: RpcHandlers) -> Self {
let (to_back, from_front) = mpsc::channel(4);
let (to_front, from_back) = mpsc01::channel(4);

let session = RpcSession::new(to_front.clone());
let session2 = session.clone();
task::spawn(
select(
Box::pin(from_front.for_each(move |message: String| {
let rpc = rpc.clone();
let session = session2.clone();
let session = session.clone();
let mut to_front = to_front.clone().sink_compat();
async move {
let response = rpc.rpc_query(&session, &message).await;
Expand All @@ -122,11 +120,9 @@ impl SubxtClient {
/// Creates a new client from a config.
pub fn from_config<C: ChainSpec + 'static>(
config: SubxtClientConfig<C>,
builder: impl Fn(
Configuration,
) -> Result<(TaskManager, Arc<RpcHandlers>), ServiceError>,
builder: impl Fn(Configuration) -> Result<(TaskManager, RpcHandlers), ServiceError>,
) -> Result<Self, ServiceError> {
let config = config.to_service_config();
let config = config.into_service_config();
let (task_manager, rpc_handlers) = (builder)(config)?;
Ok(Self::new(task_manager, rpc_handlers))
}
Expand Down Expand Up @@ -218,13 +214,13 @@ pub struct SubxtClientConfig<C: ChainSpec + 'static> {
pub chain_spec: C,
/// Role of the node.
pub role: Role,
/// Enable telemetry.
pub enable_telemetry: bool,
/// Enable telemetry on the given port.
pub telemetry: Option<u16>,
}

impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
/// Creates a service configuration.
pub fn to_service_config(self) -> Configuration {
pub fn into_service_config(self) -> Configuration {
let mut network = NetworkConfiguration::new(
format!("{} (subxt client)", self.chain_spec.name()),
"unknown",
Expand All @@ -238,10 +234,12 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
wasm_external_transport: None,
use_yamux_flow_control: true,
};
let telemetry_endpoints = if self.enable_telemetry {
let endpoints =
TelemetryEndpoints::new(vec![("/ip4/127.0.0.1/tcp/99000/ws".into(), 0)])
.expect("valid config; qed");
let telemetry_endpoints = if let Some(port) = self.telemetry {
let endpoints = TelemetryEndpoints::new(vec![(
format!("/ip4/127.0.0.1/tcp/{}/ws", port),
0,
)])
.expect("valid config; qed");
Some(endpoints)
} else {
None
Expand Down Expand Up @@ -356,7 +354,7 @@ mod tests {
keystore: KeystoreConfig::InMemory,
chain_spec,
role: Role::Light,
enable_telemetry: false,
telemetry: None,
};
let client = ClientBuilder::<NodeTemplateRuntime>::new()
.set_client(
Expand Down Expand Up @@ -389,7 +387,7 @@ mod tests {
keystore: KeystoreConfig::InMemory,
chain_spec: test_node::chain_spec::development_config().unwrap(),
role: Role::Authority(AccountKeyring::Alice),
enable_telemetry: false,
telemetry: None,
};
let client = ClientBuilder::<NodeTemplateRuntime>::new()
.set_client(
Expand Down
12 changes: 6 additions & 6 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.11.0"
version = "0.12.0"
authors = ["David Craven <david@craven.ch>", "Parity Technologies <admin@parity.io>"]
edition = "2018"
autotests = false
Expand All @@ -18,19 +18,19 @@ proc-macro = true
heck = "0.3.1"
proc-macro2 = "1.0.19"
proc-macro-crate = "0.1.5"
proc-macro-error = "1.0.3"
proc-macro-error = "1.0.4"
quote = "1.0.7"
syn = "1.0.35"
syn = "1.0.38"
synstructure = "0.12.4"

[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
async-std = { version = "1.6.3", features = ["attributes"] }
codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive"] }
env_logger = "0.7.1"
pretty_assertions = "0.6.1"
sp-keyring = "2.0.0-rc5"
sp-keyring = "2.0.0-rc6"
substrate-subxt = { path = ".." }
trybuild = "1.0.30"
trybuild = "1.0.32"

[[test]]
name = "balances"
Expand Down
44 changes: 29 additions & 15 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ pub enum Error {
TypeSizeUnavailable(String),
/// Runtime error.
#[error("Runtime error: {0}")]
Runtime(RuntimeError),
/// Bad origin.
#[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")]
BadOrigin,
/// Cannot lookup.
#[error("Cannot lookup some information required to validate the transaction.")]
CannotLookup,
Runtime(#[from] RuntimeError),
/// Other error.
#[error("Other error: {0}")]
Other(String),
Expand Down Expand Up @@ -98,9 +92,29 @@ impl From<String> for Error {
}
}

impl Error {
/// Runtime error.
#[derive(Clone, Debug, Eq, Error, PartialEq)]
pub enum RuntimeError {
/// Module error.
#[error("Runtime module error: {0}")]
Module(ModuleError),
/// Bad origin.
#[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")]
BadOrigin,
/// Cannot lookup.
#[error("Cannot lookup some information required to validate the transaction.")]
CannotLookup,
/// Other error.
#[error("Other error: {0}")]
Other(String),
}

impl RuntimeError {
/// Converts a `DispatchError` into a subxt error.
pub fn from_dispatch(metadata: &Metadata, error: DispatchError) -> Result<(), Self> {
pub fn from_dispatch(
metadata: &Metadata,
error: DispatchError,
) -> Result<Self, Error> {
match error {
DispatchError::Module {
index,
Expand All @@ -109,22 +123,22 @@ impl Error {
} => {
let module = metadata.module_with_errors(index)?;
let error = module.error(error)?;
Err(Error::Runtime(RuntimeError {
Ok(Self::Module(ModuleError {
module: module.name().to_string(),
error: error.to_string(),
}))
}
DispatchError::BadOrigin => Err(Error::BadOrigin),
DispatchError::CannotLookup => Err(Error::CannotLookup),
DispatchError::Other(msg) => Err(Error::Other(msg.into())),
DispatchError::BadOrigin => Ok(Self::BadOrigin),
DispatchError::CannotLookup => Ok(Self::CannotLookup),
DispatchError::Other(msg) => Ok(Self::Other(msg.into())),
}
}
}

/// Runtime errors.
/// Module error.
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[error("{error} from {module}")]
pub struct RuntimeError {
pub struct ModuleError {
pub module: String,
pub error: String,
}
Loading

0 comments on commit 773d43e

Please sign in to comment.