git.delta.rocks / unique-network / refs/commits / 7168c554956e

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-07-27parent: #0e47fc5.patch.diff
in: master

7 files changed

modifiedcrates/evm-coder-macros/src/lib.rsdiffbeforeafterboth
before · crates/evm-coder-macros/src/lib.rs
1#![allow(dead_code)]23use darling::FromMeta;4use inflector::cases;5use proc_macro::TokenStream;6use quote::quote;7use sha3::{Digest, Keccak256};8use syn::{AttributeArgs, DeriveInput, GenericArgument, Ident, ItemImpl, Pat, Path, PathArguments, PathSegment, Type, parse_macro_input, spanned::Spanned};910mod solidity_interface;11mod to_log;1213fn fn_selector_str(input: &str) -> u32 {14	let mut hasher = Keccak256::new();15	hasher.update(input.as_bytes());16	let result = hasher.finalize();1718	let mut selector_bytes = [0; 4];19	selector_bytes.copy_from_slice(&result[0..4]);2021	u32::from_be_bytes(selector_bytes)22}2324/// Returns solidity function selector (first 4 bytes of hash) by its25/// textual representation26///27/// ```rs28/// use evm_coder_macros::fn_selector;29///30/// assert_eq!(fn_selector!(transfer(address, uint256)), 0xa9059cbb);31/// ```32#[proc_macro]33pub fn fn_selector(input: TokenStream) -> TokenStream {34	let input = input.to_string().replace(' ', "");35	let selector = fn_selector_str(&input);3637	(quote! {38		#selector39	})40	.into()41}4243fn event_selector_str(input: &str) -> [u8; 32] {44	let mut hasher = Keccak256::new();45	hasher.update(input.as_bytes());46	let result = hasher.finalize();4748	let mut selector_bytes = [0; 32];49	selector_bytes.copy_from_slice(&result[0..32]);50	selector_bytes51}5253/// Returns solidity topic (hash) by its textual representation54///55/// ```rs56/// use evm_coder_macros::event_topic;57///58/// assert_eq!(59///     format!("{:x}", event_topic!(Transfer(address, address, uint256))),60///     "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",61/// );62/// ```63#[proc_macro]64pub fn event_topic(stream: TokenStream) -> TokenStream {65	let input = stream.to_string().replace(' ', "");66	let selector_bytes = event_selector_str(&input);6768	(quote! {69		::primitive_types::H256([#(70			#selector_bytes,71		)*])72	})73	.into()74}7576fn parse_path(ty: &Type) -> syn::Result<&Path> {77	match &ty {78		syn::Type::Path(pat) => {79			if let Some(qself) = &pat.qself {80				return Err(syn::Error::new(qself.ty.span(), "no receiver expected"));81			}82			Ok(&pat.path)83		}84		_ => Err(syn::Error::new(ty.span(), "expected ty to be path")),85	}86}8788fn parse_path_segment(path: &Path) -> syn::Result<&PathSegment> {89	if path.segments.len() != 1 {90		return Err(syn::Error::new(91			path.span(),92			"expected path to have only segment",93		));94	}95	let last_segment = &path.segments.last().unwrap();96	Ok(last_segment)97}9899fn parse_ident_from_pat(pat: &Pat) -> syn::Result<&Ident> {100	match pat {101		Pat::Ident(i) => Ok(&i.ident),102		_ => Err(syn::Error::new(pat.span(), "expected pat ident")),103	}104}105106fn parse_ident_from_segment(segment: &PathSegment, allow_generics: bool) -> syn::Result<&Ident> {107	if segment.arguments != PathArguments::None && !allow_generics {108		return Err(syn::Error::new(109			segment.arguments.span(),110			"unexpected generic type",111		));112	}113	Ok(&segment.ident)114}115116fn parse_ident_from_path(path: &Path, allow_generics: bool) -> syn::Result<&Ident> {117	let segment = parse_path_segment(path)?;118	parse_ident_from_segment(segment, allow_generics)119}120121fn parse_ident_from_type(ty: &Type, allow_generics: bool) -> syn::Result<&Ident> {122	let path = parse_path(ty)?;123	parse_ident_from_path(path, allow_generics)124}125126// Gets T out of Result<T>127fn parse_result_ok(ty: &Type) -> syn::Result<&Type> {128	let path = parse_path(ty)?;129	let segment = parse_path_segment(path)?;130131	if segment.ident != "Result" {132		return Err(syn::Error::new(133			ty.span(),134			"expected Result as return type (no renamed aliases allowed)",135		));136	}137	let args = match &segment.arguments {138		PathArguments::AngleBracketed(e) => e,139		_ => {140			return Err(syn::Error::new(141				segment.arguments.span(),142				"missing Result generics",143			))144		}145	};146147	let args = &args.args;148	let arg = args.first().unwrap();149150	let ty = match arg {151		GenericArgument::Type(ty) => ty,152		_ => {153			return Err(syn::Error::new(154				arg.span(),155				"expected first generic to be type",156			))157		}158	};159160	Ok(ty)161}162163fn pascal_ident_to_call(ident: &Ident) -> Ident {164	let name = format!("{}Call", ident);165	Ident::new(&name, ident.span())166}167fn snake_ident_to_pascal(ident: &Ident) -> Ident {168	let name = ident.to_string();169	let name = cases::pascalcase::to_pascal_case(&name);170	Ident::new(&name, ident.span())171}172fn snake_ident_to_screaming(ident: &Ident) -> Ident {173	let name = ident.to_string();174	let name = cases::screamingsnakecase::to_screaming_snake_case(&name);175	Ident::new(&name, ident.span())176}177fn pascal_ident_to_snake_call(ident: &Ident) -> Ident {178	let name = ident.to_string();179	let name = cases::snakecase::to_snake_case(&name);180	let name = format!("call_{}", name);181	Ident::new(&name, ident.span())182}183184#[proc_macro_attribute]185pub fn solidity_interface(args: TokenStream, stream: TokenStream) -> TokenStream {186	let args = parse_macro_input!(args as AttributeArgs);187	let args = solidity_interface::InterfaceInfo::from_list(&args).unwrap();188189	let input: ItemImpl = match syn::parse(stream) {190		Ok(t) => t,191		Err(e) => return e.to_compile_error().into(),192	};193194	let expanded = match solidity_interface::SolidityInterface::try_from(args, &input) {195		Ok(v) => v.expand(),196		Err(e) => e.to_compile_error(),197	};198199    (quote! {200        #input201202        #expanded203    }).into()204}205206#[proc_macro_attribute]207pub fn solidity(_args: TokenStream, stream: TokenStream) -> TokenStream {208	stream209}210211#[proc_macro_derive(ToLog, attributes(indexed))]212pub fn to_log(value: TokenStream) -> TokenStream {213	let input = parse_macro_input!(value as DeriveInput);214215	match to_log::Events::try_from(&input) {216		Ok(e) => e.expand(),217		Err(e) => e.to_compile_error(),218	}219	.into()220}
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -54,11 +54,11 @@
 }
 
 pub trait Call: Sized {
-    fn parse(selector: u32, input: &mut AbiReader) -> execution::Result<Option<Self>>;
+	fn parse(selector: u32, input: &mut AbiReader) -> execution::Result<Option<Self>>;
 }
 
 pub trait Callable<C: Call> {
-    fn call(&mut self, call: types::Msg<C>) -> execution::Result<AbiWriter>;
+	fn call(&mut self, call: types::Msg<C>) -> execution::Result<AbiWriter>;
 }
 
 #[cfg(test)]
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -186,4 +186,4 @@
 		writeln!(out, "}}")?;
 		Ok(())
 	}
-}
\ No newline at end of file
+}
modifiedcrates/evm-coder/tests/a.rsdiffbeforeafterboth
--- a/crates/evm-coder/tests/a.rs
+++ b/crates/evm-coder/tests/a.rs
@@ -8,33 +8,38 @@
 #[solidity_interface(name = "OurInterface")]
 impl Impls {
 	fn fn_a(&self, input: uint256) -> Result<bool> {
-        todo!()
-    }
+		todo!()
+	}
 }
 
 #[solidity_interface(name = "OurInterface1")]
 impl Impls {
 	fn fn_b(&self, input: uint128) -> Result<uint32> {
-        todo!()
-    }
+		todo!()
+	}
 }
 
-#[solidity_interface(name = "OurInterface2", is(OurInterface), inline_is(OurInterface1), events(ERC721Log))]
+#[solidity_interface(
+	name = "OurInterface2",
+	is(OurInterface),
+	inline_is(OurInterface1),
+	events(ERC721Log)
+)]
 impl Impls {
 	#[solidity(rename_selector = "fnK")]
 	fn fn_c(&self, input: uint32) -> Result<uint8> {
-        todo!()
-    }
+		todo!()
+	}
 	fn fn_d(&self, value: uint32) -> Result<uint32> {
-        todo!()
-    }
+		todo!()
+	}
 
 	fn caller_sensitive(&self, caller: caller) -> Result<uint8> {
-        todo!()
-    }
+		todo!()
+	}
 	fn payable(&mut self, value: value) -> Result<uint8> {
-        todo!()
-    }
+		todo!()
+	}
 }
 
 #[derive(ToLog)]
@@ -58,14 +63,14 @@
 #[solidity_interface(name = "ERC20")]
 impl ERC20 {
 	fn decimals(&self) -> Result<uint8> {
-        todo!()
-    }
+		todo!()
+	}
 	fn balance_of(&self, owner: address) -> Result<uint256> {
-        todo!()
-    }
+		todo!()
+	}
 	fn transfer(&mut self, caller: caller, to: address, value: uint256) -> Result<bool> {
-        todo!()
-    }
+		todo!()
+	}
 	fn transfer_from(
 		&mut self,
 		caller: caller,
@@ -73,12 +78,13 @@
 		to: address,
 		value: uint256,
 	) -> Result<bool> {
-        todo!()
-    }
+		todo!()
+	}
 	fn approve(&mut self, caller: caller, spender: address, value: uint256) -> Result<bool> {
-        todo!()
-    }
+		todo!()
+	}
 	fn allowance(&self, owner: address, spender: address) -> Result<uint256> {
-        todo!()
-    }
+		todo!()
+	}
 }
+
modifiednode/cli/src/service.rsdiffbeforeafterboth
--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -304,7 +304,7 @@
 
 		nft_rpc::create_full::<_, _, _, RuntimeApi, _>(full_deps, subscription_executor.clone())
 	});
-	
+
 	task_manager.spawn_essential_handle().spawn(
 		"frontier-mapping-sync-worker",
 		MappingSyncWorker::new(
@@ -313,7 +313,8 @@
 			client.clone(),
 			backend.clone(),
 			frontier_backend.clone(),
-		).for_each(|()| futures::future::ready(()))
+		)
+		.for_each(|()| futures::future::ready(())),
 	);
 
 	sc_service::spawn_tasks(sc_service::SpawnTasksParams {
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -136,7 +136,7 @@
 			let limit = <SponsoringRateLimit<T>>::get(&call.0);
 			if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
 				<SponsorBasket<T>>::insert(&call.0, who, block_number);
-				let limit_time = last_tx_block + limit.into();
+				let limit_time = last_tx_block + limit;
 				if block_number > limit_time {
 					return Some(call.0);
 				}
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -281,7 +281,7 @@
 impl pallet_ethereum::Config for Runtime {
 	type Event = Event;
 	type StateRoot = pallet_ethereum::IntermediateStateRoot;
-	type EvmSubmitLog = pallet_evm::Pallet<Runtime>;
+	type EvmSubmitLog = pallet_evm::Pallet<Self>;
 }
 
 impl pallet_randomness_collective_flip::Config for Runtime {}
@@ -329,7 +329,7 @@
 	/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
 	type SS58Prefix = SS58Prefix;
 	/// Weight information for the extrinsics of this pallet.
-	type SystemWeightInfo = system::weights::SubstrateWeight<Runtime>;
+	type SystemWeightInfo = system::weights::SubstrateWeight<Self>;
 	/// Version of the runtime.
 	type Version = Version;
 }
@@ -363,7 +363,7 @@
 	type DustRemoval = Treasury;
 	type ExistentialDeposit = ExistentialDeposit;
 	type AccountStore = System;
-	type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
+	type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;
 }
 
 pub const MICROUNIQUE: Balance = 1_000_000_000;
@@ -487,7 +487,7 @@
 	type Burn = Burn;
 	type BurnDestination = ();
 	type SpendFunds = ();
-	type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
+	type WeightInfo = pallet_treasury::weights::SubstrateWeight<Self>;
 	type MaxApprovals = MaxApprovals;
 }
 
@@ -516,7 +516,7 @@
 impl cumulus_pallet_parachain_system::Config for Runtime {
 	type Event = Event;
 	type OnValidationData = ();
-	type SelfParaId = parachain_info::Pallet<Runtime>;
+	type SelfParaId = parachain_info::Pallet<Self>;
 	// type DownwardMessageHandlers = cumulus_primitives_utility::UnqueuedDmpAsParent<
 	// 	MaxDownwardMessageWeight,
 	// 	XcmExecutor<XcmConfig>,