Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Guantong committed Jan 5, 2023
1 parent 5c7bba1 commit 7db62f3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ use num_traits::{CheckedSub, One};
use scale_info::TypeInfo;
// paritytech
use frame_support::{
log, pallet_prelude::DispatchResult, PalletError, RuntimeDebug, StorageHasher, StorageValue,
log, pallet_prelude::DispatchResult, weights::Weight, PalletError, RuntimeDebug, StorageHasher,
StorageValue,
};
use frame_system::RawOrigin;
use sp_core::{storage::StorageKey, H256};
Expand Down Expand Up @@ -486,6 +487,24 @@ pub fn storage_value_key(pallet_prefix: &str, value_name: &str) -> StorageKey {
StorageKey(final_key)
}

/// All extra operations with weights that we need in bridges.
pub trait WeightExtraOps {
/// Checked division of individual components of two weights.
///
/// Divides components and returns minimal division result. Returns `None` if one
/// of `other` weight components is zero.
fn min_components_checked_div(&self, other: Weight) -> Option<u64>;
}

impl WeightExtraOps for Weight {
fn min_components_checked_div(&self, other: Weight) -> Option<u64> {
Some(sp_std::cmp::min(
self.ref_time().checked_div(other.ref_time())?,
self.proof_size().checked_div(other.proof_size())?,
))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 7db62f3

Please sign in to comment.