mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 04:11:07 +00:00
Merge branch 'master' into staking
* 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)
This commit is contained in:
+11
-1
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
+27
-26
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+7
-7
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
+15
-17
@@ -64,7 +64,6 @@ use sc_service::{
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -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;
|
||||
@@ -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))
|
||||
}
|
||||
@@ -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",
|
||||
@@ -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
|
||||
@@ -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(
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
+29
-15
@@ -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),
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
+44
-15
@@ -39,7 +39,10 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::Error,
|
||||
error::{
|
||||
Error,
|
||||
RuntimeError,
|
||||
},
|
||||
metadata::{
|
||||
EventArg,
|
||||
Metadata,
|
||||
@@ -151,6 +154,17 @@ impl<T: System> EventsDecoder<T> {
|
||||
self.decode_raw_bytes(&[*arg.clone()], input, output)?
|
||||
}
|
||||
}
|
||||
EventArg::Option(arg) => {
|
||||
match input.read_byte()? {
|
||||
0 => (),
|
||||
1 => self.decode_raw_bytes(&[*arg.clone()], input, output)?,
|
||||
_ => {
|
||||
return Err(Error::Other(
|
||||
"unexpected first byte decoding Option".into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
EventArg::Tuple(args) => self.decode_raw_bytes(args, input, output)?,
|
||||
EventArg::Primitive(name) => {
|
||||
let result = match name.as_str() {
|
||||
@@ -168,7 +182,9 @@ impl<T: System> EventsDecoder<T> {
|
||||
}
|
||||
};
|
||||
if let Err(error) = result {
|
||||
Error::from_dispatch(&self.metadata, error)?;
|
||||
return Err(
|
||||
RuntimeError::from_dispatch(&self.metadata, error)?.into()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,10 +193,7 @@ impl<T: System> EventsDecoder<T> {
|
||||
}
|
||||
|
||||
/// Decode events.
|
||||
pub fn decode_events(
|
||||
&self,
|
||||
input: &mut &[u8],
|
||||
) -> Result<Vec<(Phase, RawEvent)>, Error> {
|
||||
pub fn decode_events(&self, input: &mut &[u8]) -> Result<Vec<(Phase, Raw)>, Error> {
|
||||
let compact_len = <Compact<u32>>::decode(input)?;
|
||||
let len = compact_len.0 as usize;
|
||||
|
||||
@@ -201,20 +214,36 @@ impl<T: System> EventsDecoder<T> {
|
||||
);
|
||||
|
||||
let mut event_data = Vec::<u8>::new();
|
||||
self.decode_raw_bytes(&event_metadata.arguments(), input, &mut event_data)?;
|
||||
let result = self.decode_raw_bytes(
|
||||
&event_metadata.arguments(),
|
||||
input,
|
||||
&mut event_data,
|
||||
);
|
||||
let raw = match result {
|
||||
Ok(()) => {
|
||||
log::debug!("raw bytes: {}", hex::encode(&event_data),);
|
||||
|
||||
log::debug!("raw bytes: {}", hex::encode(&event_data),);
|
||||
let event = RawEvent {
|
||||
module: module.name().to_string(),
|
||||
variant: event_metadata.name.clone(),
|
||||
data: event_data,
|
||||
};
|
||||
|
||||
let event = RawEvent {
|
||||
module: module.name().to_string(),
|
||||
variant: event_metadata.name.clone(),
|
||||
data: event_data,
|
||||
// topics come after the event data in EventRecord
|
||||
let _topics = Vec::<T::Hash>::decode(input)?;
|
||||
Raw::Event(event)
|
||||
}
|
||||
Err(Error::Runtime(err)) => Raw::Error(err),
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
||||
// topics come after the event data in EventRecord
|
||||
let _topics = Vec::<T::Hash>::decode(input)?;
|
||||
r.push((phase, event));
|
||||
r.push((phase, raw));
|
||||
}
|
||||
Ok(r)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Raw {
|
||||
Event(RawEvent),
|
||||
Error(RuntimeError),
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ mod tests {
|
||||
use crate::{
|
||||
error::{
|
||||
Error,
|
||||
ModuleError,
|
||||
RuntimeError,
|
||||
},
|
||||
events::EventsDecoder,
|
||||
@@ -193,8 +194,8 @@ mod tests {
|
||||
let res = client
|
||||
.transfer_and_watch(&hans, alice.account_id(), 100_000_000_000)
|
||||
.await;
|
||||
if let Err(Error::Runtime(error)) = res {
|
||||
let error2 = RuntimeError {
|
||||
if let Err(Error::Runtime(RuntimeError::Module(error))) = res {
|
||||
let error2 = ModuleError {
|
||||
module: "Balances".into(),
|
||||
error: "InsufficientBalance".into(),
|
||||
};
|
||||
|
||||
+5
-2
@@ -43,7 +43,10 @@ pub struct SudoCall<'a, T: Sudo> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
error::Error,
|
||||
error::{
|
||||
Error,
|
||||
RuntimeError,
|
||||
},
|
||||
extrinsic::PairSigner,
|
||||
frame::balances::TransferCall,
|
||||
tests::{
|
||||
@@ -68,7 +71,7 @@ mod tests {
|
||||
|
||||
let res = client.sudo_and_watch(&alice, &call).await;
|
||||
assert!(
|
||||
if let Err(Error::BadOrigin) = res {
|
||||
if let Err(Error::Runtime(RuntimeError::BadOrigin)) = res {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
+17
-8
@@ -247,7 +247,7 @@ impl<T: Runtime, F: Store<T>> KeyIter<T, F> {
|
||||
}
|
||||
}
|
||||
}
|
||||
debug_assert_eq!(self.buffer.len(), self.count as usize);
|
||||
debug_assert_eq!(self.buffer.len(), keys.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,6 +269,19 @@ impl<T: Runtime> Client<T> {
|
||||
&self.properties
|
||||
}
|
||||
|
||||
/// Fetch the value under an unhashed storage key
|
||||
pub async fn fetch_unhashed<V: Decode>(
|
||||
&self,
|
||||
key: StorageKey,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<V>, Error> {
|
||||
if let Some(data) = self.rpc.storage(&key, hash).await? {
|
||||
Ok(Some(Decode::decode(&mut &data.0[..])?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch a StorageKey with an optional block hash.
|
||||
pub async fn fetch<F: Store<T>>(
|
||||
&self,
|
||||
@@ -276,11 +289,7 @@ impl<T: Runtime> Client<T> {
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<F::Returns>, Error> {
|
||||
let key = store.key(&self.metadata)?;
|
||||
if let Some(data) = self.rpc.storage(&key, hash).await? {
|
||||
Ok(Some(Decode::decode(&mut &data.0[..])?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
self.fetch_unhashed::<F::Returns>(key, hash).await
|
||||
}
|
||||
|
||||
/// Fetch a StorageKey that has a default value with an optional block hash.
|
||||
@@ -599,14 +608,14 @@ mod tests {
|
||||
},
|
||||
chain_spec: test_node::chain_spec::development_config().unwrap(),
|
||||
role: Role::Authority(key),
|
||||
enable_telemetry: false,
|
||||
telemetry: None,
|
||||
};
|
||||
let client = ClientBuilder::new()
|
||||
.set_client(
|
||||
SubxtClient::from_config(config, test_node::service::new_full)
|
||||
.expect("Error creating subxt client"),
|
||||
)
|
||||
.set_page_size(2)
|
||||
.set_page_size(3)
|
||||
.build()
|
||||
.await
|
||||
.expect("Error creating client");
|
||||
|
||||
@@ -398,6 +398,7 @@ pub enum EventArg {
|
||||
Primitive(String),
|
||||
Vec(Box<EventArg>),
|
||||
Tuple(Vec<EventArg>),
|
||||
Option(Box<EventArg>),
|
||||
}
|
||||
|
||||
impl FromStr for EventArg {
|
||||
@@ -413,6 +414,15 @@ impl FromStr for EventArg {
|
||||
"Expected closing `>` for `Vec`",
|
||||
))
|
||||
}
|
||||
} else if s.starts_with("Option<") {
|
||||
if s.ends_with('>') {
|
||||
Ok(EventArg::Option(Box::new(s[7..s.len() - 1].parse()?)))
|
||||
} else {
|
||||
Err(ConversionError::InvalidEventArg(
|
||||
s.to_string(),
|
||||
"Expected closing `>` for `Option`",
|
||||
))
|
||||
}
|
||||
} else if s.starts_with('(') {
|
||||
if s.ends_with(')') {
|
||||
let mut args = Vec::new();
|
||||
@@ -439,6 +449,7 @@ impl EventArg {
|
||||
match self {
|
||||
EventArg::Primitive(p) => vec![p.clone()],
|
||||
EventArg::Vec(arg) => arg.primitives(),
|
||||
EventArg::Option(arg) => arg.primitives(),
|
||||
EventArg::Tuple(args) => {
|
||||
let mut primitives = Vec::new();
|
||||
for arg in args {
|
||||
|
||||
+6
-1
@@ -22,6 +22,7 @@ use crate::{
|
||||
error::Error,
|
||||
events::{
|
||||
EventsDecoder,
|
||||
Raw,
|
||||
RawEvent,
|
||||
},
|
||||
frame::{
|
||||
@@ -99,13 +100,17 @@ impl<T: Runtime> EventSubscription<T> {
|
||||
Ok(events) => events,
|
||||
Err(error) => return Some(Err(error)),
|
||||
};
|
||||
for (phase, event) in raw_events {
|
||||
for (phase, raw) in raw_events {
|
||||
if let Phase::ApplyExtrinsic(i) = phase {
|
||||
if let Some(ext_index) = self.extrinsic {
|
||||
if i as usize != ext_index {
|
||||
continue
|
||||
}
|
||||
}
|
||||
let event = match raw {
|
||||
Raw::Event(event) => event,
|
||||
Raw::Error(err) => return Some(Err(err.into())),
|
||||
};
|
||||
if let Some((module, variant)) = self.event {
|
||||
if event.module != module || event.variant != variant {
|
||||
continue
|
||||
|
||||
+21
-21
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "test-node"
|
||||
version = "2.0.0-rc5"
|
||||
version = "2.0.0"
|
||||
authors = ["Anonymous"]
|
||||
description = "Substrate Node template"
|
||||
edition = "2018"
|
||||
@@ -15,28 +15,28 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
futures = "0.3.5"
|
||||
log = "0.4.11"
|
||||
structopt = "0.3.15"
|
||||
structopt = "0.3.16"
|
||||
parking_lot = "0.11.0"
|
||||
|
||||
sc-cli = { version = "0.8.0-rc5", features = ["wasmtime"] }
|
||||
sp-core = "2.0.0-rc5"
|
||||
sc-executor = { version = "0.8.0-rc5", features = ["wasmtime"] }
|
||||
sc-service = { version = "0.8.0-rc5", features = ["wasmtime"] }
|
||||
sp-inherents = "2.0.0-rc5"
|
||||
sc-transaction-pool = "2.0.0-rc5"
|
||||
sp-transaction-pool = "2.0.0-rc5"
|
||||
sc-network = "0.8.0-rc5"
|
||||
sc-consensus-aura = "0.8.0-rc5"
|
||||
sp-consensus-aura = "0.8.0-rc5"
|
||||
sp-consensus = "0.8.0-rc5"
|
||||
sc-consensus = "0.8.0-rc5"
|
||||
sc-finality-grandpa = "0.8.0-rc5"
|
||||
sp-finality-grandpa = "2.0.0-rc5"
|
||||
sc-client-api = "2.0.0-rc5"
|
||||
sp-runtime = "2.0.0-rc5"
|
||||
sc-basic-authorship = "0.8.0-rc5"
|
||||
sc-cli = { version = "0.8.0-rc6", features = ["wasmtime"] }
|
||||
sp-core = "2.0.0-rc6"
|
||||
sc-executor = { version = "0.8.0-rc6", features = ["wasmtime"] }
|
||||
sc-service = { version = "0.8.0-rc6", features = ["wasmtime"] }
|
||||
sp-inherents = "2.0.0-rc6"
|
||||
sc-transaction-pool = "2.0.0-rc6"
|
||||
sp-transaction-pool = "2.0.0-rc6"
|
||||
sc-network = "0.8.0-rc6"
|
||||
sc-consensus-aura = "0.8.0-rc6"
|
||||
sp-consensus-aura = "0.8.0-rc6"
|
||||
sp-consensus = "0.8.0-rc6"
|
||||
sc-consensus = "0.8.0-rc6"
|
||||
sc-finality-grandpa = "0.8.0-rc6"
|
||||
sp-finality-grandpa = "2.0.0-rc6"
|
||||
sc-client-api = "2.0.0-rc6"
|
||||
sp-runtime = "2.0.0-rc6"
|
||||
sc-basic-authorship = "0.8.0-rc6"
|
||||
|
||||
test-node-runtime = { version = "2.0.0-rc5", path = "runtime" }
|
||||
test-node-runtime = { path = "runtime" }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-build-script-utils = "2.0.0-rc5"
|
||||
substrate-build-script-utils = "2.0.0-rc6"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "test-node-runtime"
|
||||
version = "2.0.0-rc5"
|
||||
version = "2.0.0"
|
||||
authors = ["Anonymous"]
|
||||
edition = "2018"
|
||||
license = "Unlicense"
|
||||
@@ -13,43 +13,47 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
|
||||
|
||||
aura = { version = "2.0.0-rc5", default-features = false, package = "pallet-aura" }
|
||||
balances = { version = "2.0.0-rc5", default-features = false, package = "pallet-balances" }
|
||||
frame-support = { version = "2.0.0-rc5", default-features = false }
|
||||
grandpa = { version = "2.0.0-rc5", default-features = false, package = "pallet-grandpa" }
|
||||
randomness-collective-flip = { version = "2.0.0-rc5", default-features = false, package = "pallet-randomness-collective-flip" }
|
||||
sudo = { version = "2.0.0-rc5", default-features = false, package = "pallet-sudo" }
|
||||
system = { version = "2.0.0-rc5", default-features = false, package = "frame-system" }
|
||||
timestamp = { version = "2.0.0-rc5", default-features = false, package = "pallet-timestamp" }
|
||||
transaction-payment = { version = "2.0.0-rc5", default-features = false, package = "pallet-transaction-payment" }
|
||||
frame-executive = { version = "2.0.0-rc5", default-features = false }
|
||||
serde = { version = "1.0.114", optional = true, features = ["derive"] }
|
||||
sp-api = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-block-builder = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-consensus-aura = { version = "0.8.0-rc5", default-features = false }
|
||||
sp-core = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-inherents = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-io = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-offchain = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-runtime = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-session = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-std = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-transaction-pool = { version = "2.0.0-rc5", default-features = false }
|
||||
sp-version = { version = "2.0.0-rc5", default-features = false }
|
||||
frame-executive = { version = "2.0.0-rc6", default-features = false }
|
||||
frame-support = { version = "2.0.0-rc6", default-features = false }
|
||||
frame-system = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-aura = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-balances = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-grandpa = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-randomness-collective-flip = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-sudo = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-timestamp = { version = "2.0.0-rc6", default-features = false }
|
||||
pallet-transaction-payment = { version = "2.0.0-rc6", default-features = false }
|
||||
serde = { version = "1.0.115", optional = true, features = ["derive"] }
|
||||
sp-api = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-block-builder = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-consensus-aura = { version = "0.8.0-rc6", default-features = false }
|
||||
sp-core = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-inherents = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-io = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-offchain = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-runtime = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-session = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-std = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-transaction-pool = { version = "2.0.0-rc6", default-features = false }
|
||||
sp-version = { version = "2.0.0-rc6", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { version = "1.0.6", package = "substrate-wasm-builder-runner" }
|
||||
substrate-wasm-builder-runner = "1.0.6"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"aura/std",
|
||||
"balances/std",
|
||||
"codec/std",
|
||||
"frame-executive/std",
|
||||
"frame-support/std",
|
||||
"grandpa/std",
|
||||
"randomness-collective-flip/std",
|
||||
"frame-system/std",
|
||||
"pallet-aura/std",
|
||||
"pallet-balances/std",
|
||||
"pallet-grandpa/std",
|
||||
"pallet-randomness-collective-flip/std",
|
||||
"pallet-sudo/std",
|
||||
"pallet-timestamp/std",
|
||||
"pallet-transaction-payment/std",
|
||||
"serde",
|
||||
"sp-api/std",
|
||||
"sp-block-builder/std",
|
||||
@@ -63,8 +67,4 @@ std = [
|
||||
"sp-std/std",
|
||||
"sp-transaction-pool/std",
|
||||
"sp-version/std",
|
||||
"sudo/std",
|
||||
"system/std",
|
||||
"timestamp/std",
|
||||
"transaction-payment/std",
|
||||
]
|
||||
|
||||
@@ -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 wasm_builder_runner::WasmBuilder;
|
||||
use substrate_wasm_builder_runner::WasmBuilder;
|
||||
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
||||
#![recursion_limit = "256"]
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
|
||||
// Make the WASM binary available.
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
use grandpa::{
|
||||
use pallet_grandpa::{
|
||||
fg_primitives,
|
||||
AuthorityId as GrandpaId,
|
||||
AuthorityList as GrandpaAuthorityList,
|
||||
@@ -61,7 +62,6 @@ use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
// A few exports that help ease life for downstream crates.
|
||||
pub use balances::Call as BalancesCall;
|
||||
pub use frame_support::{
|
||||
construct_runtime,
|
||||
parameter_types,
|
||||
@@ -81,13 +81,14 @@ pub use frame_support::{
|
||||
},
|
||||
StorageValue,
|
||||
};
|
||||
pub use pallet_balances::Call as BalancesCall;
|
||||
pub use pallet_timestamp::Call as TimestampCall;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub use sp_runtime::BuildStorage;
|
||||
pub use sp_runtime::{
|
||||
Perbill,
|
||||
Permill,
|
||||
};
|
||||
pub use timestamp::Call as TimestampCall;
|
||||
|
||||
/// An index to a block.
|
||||
pub type BlockNumber = u32;
|
||||
@@ -180,7 +181,7 @@ parameter_types! {
|
||||
pub const Version: RuntimeVersion = VERSION;
|
||||
}
|
||||
|
||||
impl system::Trait for Runtime {
|
||||
impl frame_system::Trait for Runtime {
|
||||
/// The basic call filter to use in dispatchable.
|
||||
type BaseCallFilter = ();
|
||||
/// The identifier used to distinguish between accounts.
|
||||
@@ -234,16 +235,16 @@ impl system::Trait for Runtime {
|
||||
/// What to do if an account is fully reaped from the system.
|
||||
type OnKilledAccount = ();
|
||||
/// The data to be stored in an account.
|
||||
type AccountData = balances::AccountData<Balance>;
|
||||
type AccountData = pallet_balances::AccountData<Balance>;
|
||||
/// Weight information for the extrinsics of this pallet.
|
||||
type SystemWeightInfo = ();
|
||||
}
|
||||
|
||||
impl aura::Trait for Runtime {
|
||||
impl pallet_aura::Trait for Runtime {
|
||||
type AuthorityId = AuraId;
|
||||
}
|
||||
|
||||
impl grandpa::Trait for Runtime {
|
||||
impl pallet_grandpa::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
|
||||
@@ -264,7 +265,7 @@ parameter_types! {
|
||||
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
|
||||
}
|
||||
|
||||
impl timestamp::Trait for Runtime {
|
||||
impl pallet_timestamp::Trait for Runtime {
|
||||
/// A timestamp: milliseconds since the unix epoch.
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Aura;
|
||||
@@ -276,7 +277,7 @@ parameter_types! {
|
||||
pub const ExistentialDeposit: u128 = 500;
|
||||
}
|
||||
|
||||
impl balances::Trait for Runtime {
|
||||
impl pallet_balances::Trait for Runtime {
|
||||
/// The type for recording an account's balance.
|
||||
type Balance = Balance;
|
||||
/// The ubiquitous event type.
|
||||
@@ -291,15 +292,15 @@ parameter_types! {
|
||||
pub const TransactionByteFee: Balance = 1;
|
||||
}
|
||||
|
||||
impl transaction_payment::Trait for Runtime {
|
||||
type Currency = balances::Module<Runtime>;
|
||||
impl pallet_transaction_payment::Trait for Runtime {
|
||||
type Currency = pallet_balances::Module<Runtime>;
|
||||
type OnTransactionPayment = ();
|
||||
type TransactionByteFee = TransactionByteFee;
|
||||
type WeightToFee = IdentityFee<Balance>;
|
||||
type FeeMultiplierUpdate = ();
|
||||
}
|
||||
|
||||
impl sudo::Trait for Runtime {
|
||||
impl pallet_sudo::Trait for Runtime {
|
||||
type Event = Event;
|
||||
type Call = Call;
|
||||
}
|
||||
@@ -310,14 +311,14 @@ construct_runtime!(
|
||||
NodeBlock = opaque::Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic
|
||||
{
|
||||
System: system::{Module, Call, Config, Storage, Event<T>},
|
||||
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
|
||||
Timestamp: timestamp::{Module, Call, Storage, Inherent},
|
||||
Aura: aura::{Module, Config<T>, Inherent},
|
||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||
Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: transaction_payment::{Module, Storage},
|
||||
Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},
|
||||
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
|
||||
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
|
||||
Aura: pallet_aura::{Module, Config<T>, Inherent},
|
||||
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
|
||||
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Module, Storage},
|
||||
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -333,13 +334,13 @@ pub type SignedBlock = generic::SignedBlock<Block>;
|
||||
pub type BlockId = generic::BlockId<Block>;
|
||||
/// The SignedExtension to the basic transaction logic.
|
||||
pub type SignedExtra = (
|
||||
system::CheckSpecVersion<Runtime>,
|
||||
system::CheckTxVersion<Runtime>,
|
||||
system::CheckGenesis<Runtime>,
|
||||
system::CheckEra<Runtime>,
|
||||
system::CheckNonce<Runtime>,
|
||||
system::CheckWeight<Runtime>,
|
||||
transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||
frame_system::CheckSpecVersion<Runtime>,
|
||||
frame_system::CheckTxVersion<Runtime>,
|
||||
frame_system::CheckGenesis<Runtime>,
|
||||
frame_system::CheckEra<Runtime>,
|
||||
frame_system::CheckNonce<Runtime>,
|
||||
frame_system::CheckWeight<Runtime>,
|
||||
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
|
||||
);
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
pub type UncheckedExtrinsic =
|
||||
@@ -350,7 +351,7 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExt
|
||||
pub type Executive = frame_executive::Executive<
|
||||
Runtime,
|
||||
Block,
|
||||
system::ChainContext<Runtime>,
|
||||
frame_system::ChainContext<Runtime>,
|
||||
Runtime,
|
||||
AllModules,
|
||||
>;
|
||||
|
||||
@@ -164,12 +164,12 @@ fn testnet_genesis(
|
||||
_enable_println: bool,
|
||||
) -> GenesisConfig {
|
||||
GenesisConfig {
|
||||
system: Some(SystemConfig {
|
||||
frame_system: Some(SystemConfig {
|
||||
// Add Wasm runtime to storage.
|
||||
code: wasm_binary.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
balances: Some(BalancesConfig {
|
||||
pallet_balances: Some(BalancesConfig {
|
||||
// Configure endowed accounts with initial balance of 1 << 60.
|
||||
balances: endowed_accounts
|
||||
.iter()
|
||||
@@ -177,16 +177,16 @@ fn testnet_genesis(
|
||||
.map(|k| (k, 1 << 60))
|
||||
.collect(),
|
||||
}),
|
||||
aura: Some(AuraConfig {
|
||||
pallet_aura: Some(AuraConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
|
||||
}),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
pallet_grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities
|
||||
.iter()
|
||||
.map(|x| (x.1.clone(), 1))
|
||||
.collect(),
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
pallet_sudo: Some(SudoConfig {
|
||||
// Assign network admin rights.
|
||||
key: root_key,
|
||||
}),
|
||||
|
||||
@@ -18,7 +18,6 @@ use crate::{
|
||||
chain_spec,
|
||||
cli::Cli,
|
||||
service,
|
||||
service::new_full_params,
|
||||
};
|
||||
use sc_cli::{
|
||||
ChainSpec,
|
||||
@@ -26,7 +25,7 @@ use sc_cli::{
|
||||
RuntimeVersion,
|
||||
SubstrateCli,
|
||||
};
|
||||
use sc_service::ServiceParams;
|
||||
use sc_service::PartialComponents;
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
fn impl_name() -> String {
|
||||
@@ -78,16 +77,13 @@ pub fn run() -> sc_cli::Result<()> {
|
||||
Some(subcommand) => {
|
||||
let runner = cli.create_runner(subcommand)?;
|
||||
runner.run_subcommand(subcommand, |config| {
|
||||
let (
|
||||
ServiceParams {
|
||||
client,
|
||||
backend,
|
||||
task_manager,
|
||||
import_queue,
|
||||
..
|
||||
},
|
||||
..,
|
||||
) = new_full_params(config)?;
|
||||
let PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
task_manager,
|
||||
import_queue,
|
||||
..
|
||||
} = service::new_partial(&config)?;
|
||||
Ok((client, backend, import_queue, task_manager))
|
||||
})
|
||||
}
|
||||
|
||||
+132
-118
@@ -15,6 +15,7 @@
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
|
||||
#![allow(clippy::type_complexity)]
|
||||
|
||||
use sc_client_api::{
|
||||
ExecutorProvider,
|
||||
@@ -25,13 +26,12 @@ pub use sc_executor::NativeExecutor;
|
||||
use sc_finality_grandpa::{
|
||||
FinalityProofProvider as GrandpaFinalityProofProvider,
|
||||
SharedVoterState,
|
||||
StorageAndProofProvider,
|
||||
};
|
||||
use sc_service::{
|
||||
error::Error as ServiceError,
|
||||
Configuration,
|
||||
PartialComponents,
|
||||
RpcHandlers,
|
||||
ServiceComponents,
|
||||
TaskManager,
|
||||
};
|
||||
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
|
||||
@@ -57,28 +57,25 @@ type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
|
||||
type FullBackend = sc_service::TFullBackend<Block>;
|
||||
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
|
||||
|
||||
pub fn new_full_params(
|
||||
config: Configuration,
|
||||
pub fn new_partial(
|
||||
config: &Configuration,
|
||||
) -> Result<
|
||||
(
|
||||
sc_service::ServiceParams<
|
||||
Block,
|
||||
FullClient,
|
||||
sc_consensus_aura::AuraImportQueue<Block, FullClient>,
|
||||
sc_transaction_pool::FullPool<Block, FullClient>,
|
||||
(),
|
||||
FullBackend,
|
||||
>,
|
||||
sc_service::PartialComponents<
|
||||
FullClient,
|
||||
FullBackend,
|
||||
FullSelectChain,
|
||||
sp_inherents::InherentDataProviders,
|
||||
sc_finality_grandpa::GrandpaBlockImport<
|
||||
FullBackend,
|
||||
Block,
|
||||
FullClient,
|
||||
FullSelectChain,
|
||||
>,
|
||||
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
|
||||
),
|
||||
sp_consensus::DefaultImportQueue<Block, FullClient>,
|
||||
sc_transaction_pool::FullPool<Block, FullClient>,
|
||||
(
|
||||
sc_finality_grandpa::GrandpaBlockImport<
|
||||
FullBackend,
|
||||
Block,
|
||||
FullClient,
|
||||
FullSelectChain,
|
||||
>,
|
||||
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
|
||||
),
|
||||
>,
|
||||
ServiceError,
|
||||
> {
|
||||
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
|
||||
@@ -89,13 +86,8 @@ pub fn new_full_params(
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
|
||||
let pool_api = sc_transaction_pool::FullChainApi::new(
|
||||
client.clone(),
|
||||
config.prometheus_registry(),
|
||||
);
|
||||
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
||||
config.transaction_pool.clone(),
|
||||
std::sync::Arc::new(pool_api),
|
||||
config.prometheus_registry(),
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
@@ -112,7 +104,7 @@ pub fn new_full_params(
|
||||
client.clone(),
|
||||
);
|
||||
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>(
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>(
|
||||
sc_consensus_aura::slot_duration(&*client)?,
|
||||
aura_block_import,
|
||||
Some(Box::new(grandpa_block_import.clone())),
|
||||
@@ -121,81 +113,86 @@ pub fn new_full_params(
|
||||
inherent_data_providers.clone(),
|
||||
&task_manager.spawn_handle(),
|
||||
config.prometheus_registry(),
|
||||
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
|
||||
)?;
|
||||
|
||||
let provider = client.clone() as Arc<dyn StorageAndProofProvider<_, _>>;
|
||||
let finality_proof_provider =
|
||||
Arc::new(GrandpaFinalityProofProvider::new(backend.clone(), provider));
|
||||
|
||||
let params = sc_service::ServiceParams {
|
||||
backend,
|
||||
Ok(sc_service::PartialComponents {
|
||||
client,
|
||||
backend,
|
||||
task_manager,
|
||||
import_queue,
|
||||
keystore,
|
||||
task_manager,
|
||||
transaction_pool,
|
||||
config,
|
||||
block_announce_validator_builder: None,
|
||||
finality_proof_request_builder: None,
|
||||
finality_proof_provider: Some(finality_proof_provider),
|
||||
on_demand: None,
|
||||
remote_blockchain: None,
|
||||
rpc_extensions_builder: Box::new(|_| ()),
|
||||
};
|
||||
|
||||
Ok((
|
||||
params,
|
||||
select_chain,
|
||||
transaction_pool,
|
||||
inherent_data_providers,
|
||||
grandpa_block_import,
|
||||
grandpa_link,
|
||||
))
|
||||
other: (grandpa_block_import, grandpa_link),
|
||||
})
|
||||
}
|
||||
|
||||
/// Builds a new service for a full client.
|
||||
pub fn new_full(
|
||||
config: Configuration,
|
||||
) -> Result<(TaskManager, Arc<RpcHandlers>), ServiceError> {
|
||||
let (params, select_chain, inherent_data_providers, block_import, grandpa_link) =
|
||||
new_full_params(config)?;
|
||||
|
||||
let (
|
||||
role,
|
||||
force_authoring,
|
||||
name,
|
||||
enable_grandpa,
|
||||
prometheus_registry,
|
||||
) -> Result<(TaskManager, RpcHandlers), ServiceError> {
|
||||
let PartialComponents {
|
||||
client,
|
||||
transaction_pool,
|
||||
backend,
|
||||
mut task_manager,
|
||||
import_queue,
|
||||
keystore,
|
||||
) = {
|
||||
let sc_service::ServiceParams {
|
||||
config,
|
||||
client,
|
||||
transaction_pool,
|
||||
keystore,
|
||||
..
|
||||
} = ¶ms;
|
||||
select_chain,
|
||||
transaction_pool,
|
||||
inherent_data_providers,
|
||||
other: (block_import, grandpa_link),
|
||||
} = new_partial(&config)?;
|
||||
|
||||
(
|
||||
config.role.clone(),
|
||||
config.force_authoring,
|
||||
config.network.node_name.clone(),
|
||||
!config.disable_grandpa,
|
||||
config.prometheus_registry().cloned(),
|
||||
let finality_proof_provider =
|
||||
GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone());
|
||||
|
||||
let (network, network_status_sinks, system_rpc_tx, network_starter) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
config: &config,
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue,
|
||||
on_demand: None,
|
||||
block_announce_validator_builder: None,
|
||||
finality_proof_request_builder: None,
|
||||
finality_proof_provider: Some(finality_proof_provider),
|
||||
})?;
|
||||
|
||||
if config.offchain_worker.enabled {
|
||||
sc_service::build_offchain_workers(
|
||||
&config,
|
||||
backend.clone(),
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
transaction_pool.clone(),
|
||||
keystore.clone(),
|
||||
)
|
||||
};
|
||||
network.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
let ServiceComponents {
|
||||
task_manager,
|
||||
rpc_handlers,
|
||||
network,
|
||||
telemetry_on_connect_sinks,
|
||||
..
|
||||
} = sc_service::build(params)?;
|
||||
let role = config.role.clone();
|
||||
let force_authoring = config.force_authoring;
|
||||
let name = config.network.node_name.clone();
|
||||
let enable_grandpa = !config.disable_grandpa;
|
||||
let prometheus_registry = config.prometheus_registry().cloned();
|
||||
let telemetry_connection_sinks = sc_service::TelemetryConnectionSinks::default();
|
||||
|
||||
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
network: network.clone(),
|
||||
client: client.clone(),
|
||||
keystore: keystore.clone(),
|
||||
task_manager: &mut task_manager,
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
telemetry_connection_sinks: telemetry_connection_sinks.clone(),
|
||||
rpc_extensions_builder: Box::new(|_, _| ()),
|
||||
on_demand: None,
|
||||
remote_blockchain: None,
|
||||
backend,
|
||||
network_status_sinks,
|
||||
system_rpc_tx,
|
||||
config,
|
||||
})?;
|
||||
|
||||
if role.is_authority() {
|
||||
let proposer = sc_basic_authorship::ProposerFactory::new(
|
||||
@@ -256,7 +253,7 @@ pub fn new_full(
|
||||
link: grandpa_link,
|
||||
network,
|
||||
inherent_data_providers,
|
||||
telemetry_on_connect: Some(telemetry_on_connect_sinks.on_connect_stream()),
|
||||
telemetry_on_connect: Some(telemetry_connection_sinks.on_connect_stream()),
|
||||
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
|
||||
prometheus_registry,
|
||||
shared_voter_state: SharedVoterState::empty(),
|
||||
@@ -276,26 +273,24 @@ pub fn new_full(
|
||||
)?;
|
||||
}
|
||||
|
||||
network_starter.start_network();
|
||||
Ok((task_manager, rpc_handlers))
|
||||
}
|
||||
|
||||
/// Builds a new service for a light client.
|
||||
pub fn new_light(
|
||||
config: Configuration,
|
||||
) -> Result<(TaskManager, Arc<RpcHandlers>), ServiceError> {
|
||||
let (client, backend, keystore, task_manager, on_demand) =
|
||||
) -> Result<(TaskManager, RpcHandlers), ServiceError> {
|
||||
let (client, backend, keystore, mut task_manager, on_demand) =
|
||||
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
|
||||
|
||||
let transaction_pool_api = Arc::new(sc_transaction_pool::LightChainApi::new(
|
||||
let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
|
||||
config.transaction_pool.clone(),
|
||||
config.prometheus_registry(),
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
on_demand.clone(),
|
||||
));
|
||||
let transaction_pool = sc_transaction_pool::BasicPool::new_light(
|
||||
config.transaction_pool.clone(),
|
||||
transaction_pool_api,
|
||||
config.prometheus_registry(),
|
||||
task_manager.spawn_handle(),
|
||||
);
|
||||
|
||||
let grandpa_block_import = sc_finality_grandpa::light_block_import(
|
||||
client.clone(),
|
||||
@@ -307,7 +302,7 @@ pub fn new_light(
|
||||
let finality_proof_request_builder =
|
||||
finality_proof_import.create_finality_proof_request_builder();
|
||||
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>(
|
||||
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>(
|
||||
sc_consensus_aura::slot_duration(&*client)?,
|
||||
grandpa_block_import,
|
||||
None,
|
||||
@@ -316,33 +311,52 @@ pub fn new_light(
|
||||
InherentDataProviders::new(),
|
||||
&task_manager.spawn_handle(),
|
||||
config.prometheus_registry(),
|
||||
sp_consensus::NeverCanAuthor,
|
||||
)?;
|
||||
|
||||
let finality_proof_provider = Arc::new(GrandpaFinalityProofProvider::new(
|
||||
backend.clone(),
|
||||
client.clone() as Arc<_>,
|
||||
));
|
||||
let finality_proof_provider =
|
||||
GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone());
|
||||
|
||||
sc_service::build(sc_service::ServiceParams {
|
||||
block_announce_validator_builder: None,
|
||||
finality_proof_request_builder: Some(finality_proof_request_builder),
|
||||
finality_proof_provider: Some(finality_proof_provider),
|
||||
on_demand: Some(on_demand),
|
||||
let (network, network_status_sinks, system_rpc_tx, network_starter) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
config: &config,
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue,
|
||||
on_demand: Some(on_demand.clone()),
|
||||
block_announce_validator_builder: None,
|
||||
finality_proof_request_builder: Some(finality_proof_request_builder),
|
||||
finality_proof_provider: Some(finality_proof_provider),
|
||||
})?;
|
||||
|
||||
if config.offchain_worker.enabled {
|
||||
sc_service::build_offchain_workers(
|
||||
&config,
|
||||
backend.clone(),
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
network.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
remote_blockchain: Some(backend.remote_blockchain()),
|
||||
rpc_extensions_builder: Box::new(|_| ()),
|
||||
transaction_pool: Arc::new(transaction_pool),
|
||||
transaction_pool,
|
||||
task_manager: &mut task_manager,
|
||||
on_demand: Some(on_demand),
|
||||
rpc_extensions_builder: Box::new(|_, _| ()),
|
||||
telemetry_connection_sinks: sc_service::TelemetryConnectionSinks::default(),
|
||||
config,
|
||||
client,
|
||||
import_queue,
|
||||
keystore,
|
||||
backend,
|
||||
task_manager,
|
||||
})
|
||||
.map(
|
||||
|ServiceComponents {
|
||||
task_manager,
|
||||
rpc_handlers,
|
||||
..
|
||||
}| (task_manager, rpc_handlers),
|
||||
)
|
||||
network,
|
||||
network_status_sinks,
|
||||
system_rpc_tx,
|
||||
})?;
|
||||
|
||||
network_starter.start_network();
|
||||
|
||||
Ok((task_manager, rpc_handlers))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user