mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 04:31:08 +00:00
Convert to std futures (#58)
* WIP * Begin converting rpc layer to use std futures and jsonrpsee * Convert metadata to async/await * Convert block_hash to async/await * Convert more methods to async/await * Remove sp_rpc * Fix more compilation errors * Remove connect * Starting to convert subscription functions * Use jsonrpsee branch from PR for public client types * Implement subscribe events with jsonrpsee subscription * Converting subscriptions and wait_for_block_events * WIP converting lib methods to async * Use shared client reference directly for rpc call `rpc_api!` macro currently only supports RawClient (which cannot be shared). Also supports named params only which is not currently compatible with substrate rpd which accepts only positional params. * Use &self instead of &mut self for shared Client * Convert submit_and_watch to async/await * Convert more Client fns to async * Pin some trait futures * Add serde error * Fix client creation * Fix client request compiler errors * Unify metadata errors * Add WS handshake error variant * Fix some more compiler errors * Fix more compiler errors * Convert submit_extrinsic to async * Convert submit and submit_and_watch * Add Send + Sync constraints * Clone clients * Fix EventArg conversion error * Fix remaining warnings/errors * Replace deny warnings with specific lints * Infallable subscription loops * Use jsonrpsee wss branch * Fix example * Start to fix up tests * Make contracts tests compile * Make some more tests pass * Fix up remaining tests * Fmt * Use correct event storage key type * Fix finding events * Use master jsonrpsee
This commit is contained in:
+20
-12
@@ -41,6 +41,8 @@ use crate::Encoded;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum MetadataError {
|
||||
#[error("Error converting substrate metadata: {0}")]
|
||||
Conversion(#[from] ConversionError),
|
||||
#[error("Module not found")]
|
||||
ModuleNotFound(String),
|
||||
#[error("Module with events not found")]
|
||||
@@ -284,14 +286,14 @@ pub enum EventArg {
|
||||
}
|
||||
|
||||
impl FromStr for EventArg {
|
||||
type Err = Error;
|
||||
type Err = ConversionError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if s.starts_with("Vec<") {
|
||||
if s.ends_with('>') {
|
||||
Ok(EventArg::Vec(Box::new(s[4..s.len() - 1].parse()?)))
|
||||
} else {
|
||||
Err(Error::InvalidEventArg(
|
||||
Err(ConversionError::InvalidEventArg(
|
||||
s.to_string(),
|
||||
"Expected closing `>` for `Vec`",
|
||||
))
|
||||
@@ -305,7 +307,7 @@ impl FromStr for EventArg {
|
||||
}
|
||||
Ok(EventArg::Tuple(args))
|
||||
} else {
|
||||
Err(Error::InvalidEventArg(
|
||||
Err(ConversionError::InvalidEventArg(
|
||||
s.to_string(),
|
||||
"Expecting closing `)` for tuple",
|
||||
))
|
||||
@@ -333,24 +335,28 @@ impl EventArg {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ConversionError {
|
||||
#[error("Invalid prefix")]
|
||||
InvalidPrefix,
|
||||
#[error("Invalid version")]
|
||||
InvalidVersion,
|
||||
#[error("Expected DecodeDifferent::Decoded")]
|
||||
ExpectedDecoded,
|
||||
#[error("Invalid event arg {0}")]
|
||||
InvalidEventArg(String, &'static str),
|
||||
}
|
||||
|
||||
impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
||||
type Error = Error;
|
||||
type Error = MetadataError;
|
||||
|
||||
fn try_from(metadata: RuntimeMetadataPrefixed) -> Result<Self, Self::Error> {
|
||||
if metadata.0 != META_RESERVED {
|
||||
return Err(Error::InvalidPrefix)
|
||||
return Err(ConversionError::InvalidPrefix.into())
|
||||
}
|
||||
let meta = match metadata.1 {
|
||||
RuntimeMetadata::V10(meta) => meta,
|
||||
_ => return Err(Error::InvalidVersion),
|
||||
_ => return Err(ConversionError::InvalidVersion.into()),
|
||||
};
|
||||
let mut modules = HashMap::new();
|
||||
let mut modules_with_calls = HashMap::new();
|
||||
@@ -417,16 +423,18 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert<B: 'static, O: 'static>(dd: DecodeDifferent<B, O>) -> Result<O, Error> {
|
||||
fn convert<B: 'static, O: 'static>(
|
||||
dd: DecodeDifferent<B, O>,
|
||||
) -> Result<O, ConversionError> {
|
||||
match dd {
|
||||
DecodeDifferent::Decoded(value) => Ok(value),
|
||||
_ => Err(Error::ExpectedDecoded),
|
||||
_ => Err(ConversionError::ExpectedDecoded),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_event(
|
||||
event: frame_metadata::EventMetadata,
|
||||
) -> Result<ModuleEventMetadata, Error> {
|
||||
) -> Result<ModuleEventMetadata, ConversionError> {
|
||||
let name = convert(event.name)?;
|
||||
let mut arguments = Vec::new();
|
||||
for arg in convert(event.arguments)? {
|
||||
@@ -440,7 +448,7 @@ fn convert_entry(
|
||||
module_prefix: String,
|
||||
storage_prefix: String,
|
||||
entry: frame_metadata::StorageEntryMetadata,
|
||||
) -> Result<StorageMetadata, Error> {
|
||||
) -> Result<StorageMetadata, ConversionError> {
|
||||
let default = convert(entry.default)?;
|
||||
Ok(StorageMetadata {
|
||||
module_prefix,
|
||||
|
||||
Reference in New Issue
Block a user