Skip to content

Commit

Permalink
decode option event arg
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Sep 3, 2020
1 parent af45c39 commit 9200e45
Show file tree
Hide file tree
Showing 35 changed files with 207 additions and 606 deletions.
58 changes: 14 additions & 44 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,26 @@
use async_std::task;
use futures::{
channel::mpsc,
compat::{
Compat01As03,
Sink01CompatExt,
Stream01CompatExt,
},
future::{
select,
FutureExt,
},
compat::{Compat01As03, Sink01CompatExt, Stream01CompatExt},
future::{select, FutureExt},
sink::SinkExt,
stream::StreamExt,
};
use futures01::sync::mpsc as mpsc01;
use jsonrpsee::{
common::{
Request,
Response,
},
common::{Request, Response},
transport::TransportClient,
};
use sc_network::config::TransportConfig;
pub use sc_service::{
config::{
DatabaseConfig,
KeystoreConfig,
},
config::{DatabaseConfig, KeystoreConfig},
Error as ServiceError,
};
use sc_service::{
config::{
NetworkConfiguration,
TaskType,
TelemetryEndpoints,
},
ChainSpec,
Configuration,
RpcHandlers,
RpcSession,
TaskManager,
};
use std::{
future::Future,
pin::Pin,
config::{NetworkConfiguration, TaskType, TelemetryEndpoints},
ChainSpec, Configuration, RpcHandlers, RpcSession, TaskManager,
};
use std::{future::Future, pin::Pin};
use thiserror::Error;

/// Error thrown by the client.
Expand Down Expand Up @@ -177,11 +153,9 @@ impl From<Role> for sc_service::Role {
fn from(role: Role) -> Self {
match role {
Role::Light => Self::Light,
Role::Authority(_) => {
Self::Authority {
sentry_nodes: Default::default(),
}
}
Role::Authority(_) => Self::Authority {
sentry_nodes: Default::default(),
},
}
}
}
Expand Down Expand Up @@ -250,11 +224,9 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
impl_version: self.impl_version.to_string(),
chain_spec: Box::new(self.chain_spec),
role: self.role.into(),
task_executor: (move |fut, ty| {
match ty {
TaskType::Async => task::spawn(fut),
TaskType::Blocking => task::spawn_blocking(|| task::block_on(fut)),
}
task_executor: (move |fut, ty| match ty {
TaskType::Async => task::spawn(fut),
TaskType::Blocking => task::spawn_blocking(|| task::block_on(fut)),
})
.into(),
database: self.db,
Expand Down Expand Up @@ -308,9 +280,7 @@ mod tests {
use async_std::path::Path;
use sp_keyring::AccountKeyring;
use substrate_subxt::{
balances::TransferCallExt,
ClientBuilder,
KusamaRuntime as NodeTemplateRuntime,
balances::TransferCallExt, ClientBuilder, KusamaRuntime as NodeTemplateRuntime,
PairSigner,
};
use tempdir::TempDir;
Expand Down
6 changes: 1 addition & 5 deletions examples/fetch_all_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +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 substrate_subxt::{
system::AccountStoreExt,
ClientBuilder,
DefaultNodeRuntime,
};
use substrate_subxt::{system::AccountStoreExt, ClientBuilder, DefaultNodeRuntime};

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
5 changes: 1 addition & 4 deletions examples/fetch_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +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 substrate_subxt::{
ClientBuilder,
KusamaRuntime,
};
use substrate_subxt::{ClientBuilder, KusamaRuntime};

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
7 changes: 1 addition & 6 deletions examples/kusama_balance_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use sp_keyring::AccountKeyring;
use substrate_subxt::{
balances::*,
ClientBuilder,
KusamaRuntime,
PairSigner,
};
use substrate_subxt::{balances::*, ClientBuilder, KusamaRuntime, PairSigner};

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
9 changes: 2 additions & 7 deletions examples/submit_and_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@

use sp_keyring::AccountKeyring;
use substrate_subxt::{
balances::{
TransferCallExt,
TransferEventExt,
},
ClientBuilder,
DefaultNodeRuntime,
PairSigner,
balances::{TransferCallExt, TransferEventExt},
ClientBuilder, DefaultNodeRuntime, PairSigner,
};

#[async_std::main]
Expand Down
12 changes: 2 additions & 10 deletions examples/transfer_subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@

use sp_keyring::AccountKeyring;
use substrate_subxt::{
balances::{
BalancesEventsDecoder,
TransferCallExt,
TransferEvent,
},
balances::{BalancesEventsDecoder, TransferCallExt, TransferEvent},
sp_core::Decode,
ClientBuilder,
DefaultNodeRuntime,
EventSubscription,
EventsDecoder,
PairSigner,
ClientBuilder, DefaultNodeRuntime, EventSubscription, EventsDecoder, PairSigner,
};

#[async_std::main]
Expand Down
10 changes: 2 additions & 8 deletions proc-macro/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use crate::utils;
use heck::{
CamelCase,
SnakeCase,
};
use heck::{CamelCase, SnakeCase};
use proc_macro2::TokenStream;
use quote::{
format_ident,
quote,
};
use quote::{format_ident, quote};
use synstructure::Structure;

pub fn call(s: Structure) -> TokenStream {
Expand Down
10 changes: 2 additions & 8 deletions proc-macro/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use crate::utils;
use heck::{
CamelCase,
SnakeCase,
};
use heck::{CamelCase, SnakeCase};
use proc_macro2::TokenStream;
use quote::{
format_ident,
quote,
};
use quote::{format_ident, quote};
use synstructure::Structure;

pub fn event(s: Structure) -> TokenStream {
Expand Down
5 changes: 1 addition & 4 deletions proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ mod utils;

use proc_macro::TokenStream;
use proc_macro_error::proc_macro_error;
use synstructure::{
decl_derive,
Structure,
};
use synstructure::{decl_derive, Structure};

/// Register type sizes for [EventsDecoder](struct.EventsDecoder.html) and set the `MODULE`.
///
Expand Down
16 changes: 5 additions & 11 deletions proc-macro/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ use crate::utils;
use heck::SnakeCase;
use proc_macro2::TokenStream;
use proc_macro_error::abort;
use quote::{
format_ident,
quote,
};
use syn::parse::{
Parse,
ParseStream,
};
use quote::{format_ident, quote};
use syn::parse::{Parse, ParseStream};

mod kw {
use syn::custom_keyword;
Expand Down Expand Up @@ -54,7 +48,7 @@ fn ignore(attrs: &[syn::Attribute]) -> bool {
.map_err(|err| abort!("{}", err))
.unwrap();
if !attrs.attrs.is_empty() {
return true
return true;
}
}
}
Expand All @@ -76,7 +70,7 @@ pub fn module(_args: TokenStream, tokens: TokenStream) -> TokenStream {
input
} else {
// handle #[module(ignore)] by just returning the tokens
return tokens
return tokens;
};

let subxt = utils::use_crate("substrate-subxt");
Expand All @@ -99,7 +93,7 @@ pub fn module(_args: TokenStream, tokens: TokenStream) -> TokenStream {
let types = input.items.iter().filter_map(|item| {
if let syn::TraitItem::Type(ty) = item {
if ignore(&ty.attrs) {
return None
return None;
}
let ident = &ty.ident;
let ident_str = ident.to_string();
Expand Down
15 changes: 3 additions & 12 deletions proc-macro/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use crate::utils;
use heck::{
CamelCase,
SnakeCase,
};
use heck::{CamelCase, SnakeCase};
use proc_macro2::TokenStream;
use proc_macro_error::abort;
use quote::{
format_ident,
quote,
};
use syn::parse::{
Parse,
ParseStream,
};
use quote::{format_ident, quote};
use syn::parse::{Parse, ParseStream};
use synstructure::Structure;

mod kw {
Expand Down
10 changes: 2 additions & 8 deletions proc-macro/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
use crate::utils;
use proc_macro2::TokenStream;
use proc_macro_error::abort;
use quote::{
format_ident,
quote,
};
use quote::{format_ident, quote};
use syn::{
parse::{
Parse,
ParseStream,
},
parse::{Parse, ParseStream},
punctuated::Punctuated,
};

Expand Down
42 changes: 14 additions & 28 deletions proc-macro/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,13 @@
// 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 proc_macro2::{
Span,
TokenStream,
};
use quote::{
format_ident,
quote,
};
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
use syn::{
parse::{
Parse,
ParseStream,
},
parse::{Parse, ParseStream},
punctuated::Punctuated,
};
use synstructure::{
BindingInfo,
Structure,
};
use synstructure::{BindingInfo, Structure};

pub fn use_crate(name: &str) -> syn::Ident {
opt_crate(name).unwrap_or_else(|| syn::Ident::new("crate", Span::call_site()))
Expand Down Expand Up @@ -151,18 +139,16 @@ pub fn type_params(generics: &syn::Generics) -> Vec<TokenStream> {
generics
.params
.iter()
.filter_map(|g| {
match g {
syn::GenericParam::Type(p) => {
let ident = &p.ident;
Some(quote!(#ident))
}
syn::GenericParam::Lifetime(p) => {
let lifetime = &p.lifetime;
Some(quote!(#lifetime))
}
syn::GenericParam::Const(_) => None,
.filter_map(|g| match g {
syn::GenericParam::Type(p) => {
let ident = &p.ident;
Some(quote!(#ident))
}
syn::GenericParam::Lifetime(p) => {
let lifetime = &p.lifetime;
Some(quote!(#lifetime))
}
syn::GenericParam::Const(_) => None,
})
.collect()
}
Expand All @@ -173,7 +159,7 @@ pub fn parse_option(ty: &syn::Type) -> Option<syn::Type> {
if &seg.ident == "Option" {
if let syn::PathArguments::AngleBracketed(args) = &seg.arguments {
if let Some(syn::GenericArgument::Type(ty)) = args.args.first() {
return Some(ty.clone())
return Some(ty.clone());
}
}
}
Expand Down
Loading

0 comments on commit 9200e45

Please sign in to comment.