diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 57630753cb275..d70b0f2b8ab30 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -243,12 +243,12 @@ pub trait Ext: sealing::Sealed { /// Sets new code hash for existing contract. fn set_code_hash(&mut self, hash: CodeHash) -> Result<(), DispatchError>; - /// Returns then number of times currently executing contract exists on the call stack in addition - /// to the calling instance. A value of 0 means no reentrancy. + /// Returns then number of times currently executing contract exists on the call stack in + /// addition to the calling instance. A value of 0 means no reentrancy. fn reentrant_count(&self) -> u32; - /// Returns the number of times specified contract exists on the call stack. Delegated calls are not - /// calculated as separate entrance. + /// Returns the number of times specified contract exists on the call stack. Delegated calls are + /// not calculated as separate entrance. /// A value of 0 means it does not exist on the call stack. fn account_entrance_count(&self, account_id: &AccountIdOf) -> u32; } @@ -1243,7 +1243,11 @@ where } fn account_entrance_count(&self, account_id: &AccountIdOf) -> u32 { - self.frames().filter_map(|f| (f.delegate_caller.is_none() && &f.account_id == account_id).then(|| true)).count() as u32 + self.frames() + .filter_map(|f| { + (f.delegate_caller.is_none() && &f.account_id == account_id).then(|| true) + }) + .count() as u32 } } diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 307bd3a660578..152cafbb541d5 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -3257,8 +3257,8 @@ fn reentrant_count_works() { AsRef::<[u8]>::as_ref(&contract_addr1).to_vec(), true, ) - .result - .unwrap(); + .result + .unwrap(); }); } #[test] @@ -3289,7 +3289,7 @@ fn account_entrance_count_works() { AsRef::<[u8]>::as_ref(&contract_addr1).to_vec(), true, ) - .result - .unwrap(); + .result + .unwrap(); }); } diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs index cfc2a9272af4f..9025fd0fe62d3 100644 --- a/frame/contracts/src/wasm/mod.rs +++ b/frame/contracts/src/wasm/mod.rs @@ -523,8 +523,12 @@ mod tests { fn ecdsa_to_eth_address(&self, _pk: &[u8; 33]) -> Result<[u8; 20], ()> { Ok([2u8; 20]) } - fn reentrant_count(&self) -> u32 { 12 } - fn account_entrance_count(&self, _account_id: &AccountIdOf) -> u32 { unimplemented!() } + fn reentrant_count(&self) -> u32 { + 12 + } + fn account_entrance_count(&self, _account_id: &AccountIdOf) -> u32 { + unimplemented!() + } } fn execute>(wat: &str, input_data: Vec, mut ext: E) -> ExecResult { diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index 2d61552c7d61e..ba6122fd4eca1 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -2110,7 +2110,7 @@ define_env!(Env, , // Returns 0 when the contract does not exist on the call stack. [__unstable__] seal_account_entrance_count(ctx, account_ptr: u32) -> u32 => { ctx.charge_gas(RuntimeCosts::AccountEntranceCount)?; - let account_id: &<::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?; + let account_id: <::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?; Ok(ctx.ext.account_entrance_count(&account_id) as u32) }, );