From 39662f2c842d4a9b549f9d3c7fe39217f3da07f0 Mon Sep 17 00:00:00 2001 From: Peter White Date: Wed, 28 Feb 2024 13:12:41 -0700 Subject: [PATCH] chore: cargo fmt --- runtime/src/extensions/mod.rs | 2 +- runtime/src/extensions/pop_api_extension.rs | 73 +++++++++------------ runtime/src/lib.rs | 2 +- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/runtime/src/extensions/mod.rs b/runtime/src/extensions/mod.rs index 3d1a6f9d..ad18a5a0 100644 --- a/runtime/src/extensions/mod.rs +++ b/runtime/src/extensions/mod.rs @@ -1 +1 @@ -pub mod pop_api_extension; \ No newline at end of file +pub mod pop_api_extension; diff --git a/runtime/src/extensions/pop_api_extension.rs b/runtime/src/extensions/pop_api_extension.rs index bcfcc689..ad704d30 100644 --- a/runtime/src/extensions/pop_api_extension.rs +++ b/runtime/src/extensions/pop_api_extension.rs @@ -6,21 +6,11 @@ use frame_support::{ use log; use pallet_contracts::chain_extension::{ - ChainExtension, - Environment, - Ext, - InitState, - RetVal, - SysConfig, + ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; use sp_core::crypto::UncheckedFrom; -use sp_runtime::{ - traits::{ - Dispatchable - }, - DispatchError, -}; +use sp_runtime::{traits::Dispatchable, DispatchError}; const LOG_TARGET: &str = "popapi::extension"; #[derive(Default)] @@ -39,7 +29,7 @@ fn convert_err(err_msg: &'static str) -> impl FnOnce(DispatchError) -> DispatchE #[derive(Debug)] enum FuncId { - CallRuntime + CallRuntime, } impl TryFrom for FuncId { @@ -50,7 +40,7 @@ impl TryFrom for FuncId { 0xfecb => Self::CallRuntime, _ => { log::error!("Called an unregistered `func_id`: {:}", func_id); - return Err(DispatchError::Other("Unimplemented func_id")) + return Err(DispatchError::Other("Unimplemented func_id")); } }; @@ -63,11 +53,9 @@ where T: pallet_contracts::Config + frame_system::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, ::RuntimeCall: Parameter - + Dispatchable< - RuntimeOrigin = ::RuntimeOrigin, - PostInfo = PostDispatchInfo, - > + GetDispatchInfo - + From>, + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, E: Ext, { let mut env = env.buf_in_buf_out(); @@ -79,17 +67,17 @@ where // TODO: debug_message weight is a good approximation of the additional overhead of going // from contract layer to substrate layer. - + // input length let len = env.in_len(); let call: ::RuntimeCall = env.read_as_unbounded(len)?; - + log::trace!(target:LOG_TARGET, " dispatch inputted RuntimeCall: {:?}", call); let sender = env.ext().caller(); let origin: T::RuntimeOrigin = RawOrigin::Signed(sender.account_id()?.clone()).into(); - - // TODO: uncomment once charged_weight is fixed + + // TODO: uncomment once charged_weight is fixed // let actual_weight = call.get_dispatch_info().weight; // env.adjust_weight(charged_weight, actual_weight); let result = call.dispatch(origin); @@ -105,26 +93,19 @@ where Ok(()) } - impl ChainExtension for PopApiExtension where T: pallet_contracts::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, ::RuntimeCall: Parameter - + Dispatchable< - RuntimeOrigin = ::RuntimeOrigin, - PostInfo = PostDispatchInfo, - > + GetDispatchInfo - + From>, + + Dispatchable::RuntimeOrigin, PostInfo = PostDispatchInfo> + + GetDispatchInfo + + From>, { - fn call( - &mut self, - env: Environment, - ) -> Result + fn call(&mut self, env: Environment) -> Result where E: Ext, - ::AccountId: - UncheckedFrom<::Hash> + AsRef<[u8]>, + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { let func_id = FuncId::try_from(env.func_id())?; match func_id { @@ -139,8 +120,8 @@ where mod tests { pub use super::*; pub use crate::*; - pub use sp_runtime::{AccountId32, traits::Hash}; pub use pallet_contracts::Code; + pub use sp_runtime::{traits::Hash, AccountId32}; pub const DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::Skip; @@ -199,9 +180,15 @@ mod tests { vec![], DEBUG_OUTPUT, pallet_contracts::CollectEvents::Skip, - ).result.unwrap(); - - assert!(!result.result.did_revert(), "deploying contract reverted {:?}", result); + ) + .result + .unwrap(); + + assert!( + !result.result.did_revert(), + "deploying contract reverted {:?}", + result + ); let addr = result.account_id; @@ -209,7 +196,7 @@ mod tests { let value_to_send: u128 = 1_000_000_000_000_000; let params = [function, BOB.encode(), value_to_send.encode()].concat(); - let bob_balance_before= Balances::free_balance(&BOB); + let bob_balance_before = Balances::free_balance(&BOB); assert_eq!(bob_balance_before, INITIAL_AMOUNT); let result = Contracts::bare_call( @@ -233,10 +220,10 @@ mod tests { } // check for revert - assert!(! result.result.unwrap().did_revert(), "Contract reverted!"); + assert!(!result.result.unwrap().did_revert(), "Contract reverted!"); - let bob_balance_after= Balances::free_balance(&BOB); + let bob_balance_after = Balances::free_balance(&BOB); assert_eq!(bob_balance_before + value_to_send, bob_balance_after); }); } -} \ No newline at end of file +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6219a15b..7f69e8d5 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -8,8 +8,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod assets_config; mod contracts_config; -mod weights; mod extensions; +mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;