Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikbratashchuk committed Jun 2, 2022
1 parent f29884b commit 72c8f83
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
14 changes: 9 additions & 5 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ pub trait Ext: sealing::Sealed {
/// Sets new code hash for existing contract.
fn set_code_hash(&mut self, hash: CodeHash<Self::T>) -> 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<Self::T>) -> u32;
}
Expand Down Expand Up @@ -1243,7 +1243,11 @@ where
}

fn account_entrance_count(&self, account_id: &AccountIdOf<Self::T>) -> 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
}
}

Expand Down
8 changes: 4 additions & 4 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3257,8 +3257,8 @@ fn reentrant_count_works() {
AsRef::<[u8]>::as_ref(&contract_addr1).to_vec(),
true,
)
.result
.unwrap();
.result
.unwrap();
});
}
#[test]
Expand Down Expand Up @@ -3289,7 +3289,7 @@ fn account_entrance_count_works() {
AsRef::<[u8]>::as_ref(&contract_addr1).to_vec(),
true,
)
.result
.unwrap();
.result
.unwrap();
});
}
8 changes: 6 additions & 2 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::T>) -> u32 { unimplemented!() }
fn reentrant_count(&self) -> u32 {
12
}
fn account_entrance_count(&self, _account_id: &AccountIdOf<Self::T>) -> u32 {
unimplemented!()
}
}

fn execute<E: BorrowMut<MockExt>>(wat: &str, input_data: Vec<u8>, mut ext: E) -> ExecResult {
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ define_env!(Env, <E: Ext>,
// 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: &<<E as Ext>::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?;
let account_id: <<E as Ext>::T as frame_system::Config>::AccountId = ctx.read_sandbox_memory_as(account_ptr)?;
Ok(ctx.ext.account_entrance_count(&account_id) as u32)
},
);

0 comments on commit 72c8f83

Please sign in to comment.