Skip to content

Commit

Permalink
fmt: wrap comments (centrifuge#1330)
Browse files Browse the repository at this point in the history
* feat: add comment wrapping to fmt config

* fmt: wrap comments

* Update libs/test-utils/src/mocks/order_manager.rs

Co-authored-by: Nuno Alexandre <hi@nunoalexandre.com>

* fmt: new stuff

---------

Co-authored-by: Nuno Alexandre <hi@nunoalexandre.com>
  • Loading branch information
wischli and NunoAlexandre authored May 4, 2023
1 parent a6e0717 commit 189b221
Show file tree
Hide file tree
Showing 120 changed files with 1,826 additions and 1,332 deletions.
13 changes: 8 additions & 5 deletions libs/mock-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

//! Offer utilities to create custom pallet mocks for generic traits.
//!
//! [`register_call!()`] and [`execute_call!()`] expect the following storage in the pallet.
//! It's safe to just copy and paste in your pallet mock.
//! [`register_call!()`] and [`execute_call!()`] expect the following storage in
//! the pallet. It's safe to just copy and paste in your pallet mock.
//!
//! ```no_run
//! # #[frame_support::pallet]
Expand All @@ -37,7 +37,8 @@
//! # }
//! ```
//!
//! Take a look to the [pallet tests](`tests/pallet.rs`) to have a user view of how to use this crate.
//! Take a look to the [pallet tests](`tests/pallet.rs`) to have a user view of
//! how to use this crate.
/// Provide functions for register/execute calls
pub mod storage;
Expand All @@ -53,7 +54,8 @@ pub use storage::CallId;
pub const MOCK_FN_PREFIX: &str = "mock_";

/// Register a mock function into the mock function storage.
/// This function should be called with a locator used as a function identification.
/// This function should be called with a locator used as a function
/// identification.
pub fn register<Map, L, F, I, O>(locator: L, f: F)
where
Map: StorageMap<<Blake2_128 as StorageHasher>::Output, CallId>,
Expand All @@ -71,7 +73,8 @@ where
}

/// Execute a function from the function storage.
/// This function should be called with a locator used as a function identification.
/// This function should be called with a locator used as a function
/// identification.
pub fn execute<Map, L, I, O>(locator: L, input: I) -> O
where
Map: StorageMap<<Blake2_128 as StorageHasher>::Output, CallId>,
Expand Down
3 changes: 2 additions & 1 deletion libs/mock-builder/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use frame_support::StorageHasher;
pub struct FunctionLocation(String);

impl FunctionLocation {
/// Creates a location for the function which created the given closure used as a locator
/// Creates a location for the function which created the given closure used
/// as a locator
pub fn from<F: Fn()>(_: F) -> Self {
let location = std::any::type_name::<F>();
let location = &location[..location.len() - "::{{closure}}".len()];
Expand Down
42 changes: 24 additions & 18 deletions libs/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ pub mod types {
/// An index to a block.
pub type BlockNumber = u32;

/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
/// Alias to 512-bit hash when used in the context of a transaction
/// signature on the chain.
pub type Signature = sp_runtime::MultiSignature;

/// Some way of identifying an account on the chain. We intentionally make it equivalent
/// to the public key of our transaction signing scheme.
/// Some way of identifying an account on the chain. We intentionally make
/// it equivalent to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
/// never know...
/// The type for looking up accounts. We don't expect more than 4 billion of
/// them, but you never know...
pub type AccountIndex = u32;

/// The address format for describing accounts.
Expand Down Expand Up @@ -128,15 +129,17 @@ pub mod types {
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct RegistryId(pub H160);

// The id of an asset as it corresponds to the "token id" of a Centrifuge document.
// A registry id is needed as well to uniquely identify an asset on-chain.
// The id of an asset as it corresponds to the "token id" of a Centrifuge
// document. A registry id is needed as well to uniquely identify an asset
// on-chain.
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct TokenId(pub U256);

/// A generic representation of a local address. A resource id points to this. It may be a
/// registry id (20 bytes) or a fungible asset type (in the future). Constrained to 32 bytes just
/// as an upper bound to store efficiently.
/// A generic representation of a local address. A resource id points to
/// this. It may be a registry id (20 bytes) or a fungible asset type (in
/// the future). Constrained to 32 bytes just as an upper bound to store
/// efficiently.
#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct EthAddress(pub Bytes32);
Expand Down Expand Up @@ -182,9 +185,10 @@ pub mod constants {

use super::types::{Balance, BlockNumber};

/// This determines the average expected block time that we are targeting. Blocks will be
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
/// This determines the average expected block time that we are targeting.
/// Blocks will be produced at a minimum duration defined by
/// `SLOT_DURATION`. `SLOT_DURATION` is picked up by `pallet_timestamp`
/// which is in turn picked up by `pallet_aura` to implement `fn
/// slot_duration()`.
///
/// Change this to adjust the block time.
Expand All @@ -205,11 +209,12 @@ pub mod constants {
pub const SECONDS_PER_DAY: u64 = SECONDS_PER_HOUR * 24;
pub const SECONDS_PER_YEAR: u64 = SECONDS_PER_DAY * 365;

/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
/// We assume that ~5% of the block weight is consumed by `on_initialize`
/// handlers. This is used to limit the maximal weight of a single
/// extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
/// Operational extrinsics.
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest
/// can be used by Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 0.5 seconds of compute with a 6 second average block time.
Expand Down Expand Up @@ -237,7 +242,8 @@ pub mod constants {
/// Value for a not specified fee key.
pub const DEFAULT_FEE_VALUE: Balance = 1 * CFG;

/// % of fee addressed to the Treasury. The reminder % will be for the block author.
/// % of fee addressed to the Treasury. The reminder % will be for the block
/// author.
pub const TREASURY_FEE_RATIO: Perbill = Perbill::from_percent(80);

/// The max length allowed for a tranche token name
Expand Down
30 changes: 17 additions & 13 deletions libs/proofs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! # Optimized Merkle proof verifier and bundle hasher
//!
//! This pallet provides functionality of verifying optimized merkle proofs and bundle hasher.
//! This pallet provides functionality of verifying optimized merkle proofs and
//! bundle hasher.
// Ensure we're `no_std` when compiling for WebAssembly.
#![cfg_attr(not(feature = "std"), no_std)]
Expand Down Expand Up @@ -58,7 +59,8 @@ pub trait Verifier: Hasher {
/// `None` implies a failed proof verification
fn initial_matches(&self, doc_root: Self::Hash) -> Option<Vec<Self::Hash>>;

/// Verifies each proof and return true if all the proofs are valid else returns false
/// Verifies each proof and return true if all the proofs are valid else
/// returns false
fn verify_proofs(&self, doc_root: Self::Hash, proofs: &[Proof<Self::Hash>]) -> bool {
if proofs.is_empty() {
return false;
Expand Down Expand Up @@ -89,17 +91,19 @@ mod inner {
use super::*;
use crate::{Proof, Verifier};

/// This is an optimized Merkle proof checker. It caches all valid leaves in an array called
/// matches. If a proof is validated, all the intermediate hashes will be added to the array.
/// When validating a subsequent proof, that proof will stop being validated as soon as a hash
/// has been computed that has been a computed hash in a previously validated proof.
/// This is an optimized Merkle proof checker. It caches all valid leaves in
/// an array called matches. If a proof is validated, all the intermediate
/// hashes will be added to the array. When validating a subsequent proof,
/// that proof will stop being validated as soon as a hash has been computed
/// that has been a computed hash in a previously validated proof.
///
/// When submitting a list of proofs, the client can thus choose to chop of all the already proven
/// nodes when submitting multiple proofs.
/// When submitting a list of proofs, the client can thus choose to chop of
/// all the already proven nodes when submitting multiple proofs.
///
/// matches: matches will have a pre computed hashes provided by the client and document root of the
/// reference anchor. static proofs are used to computed the pre computed hashes and the result is
/// checked against document root provided.
/// matches: matches will have a pre computed hashes provided by the client
/// and document root of the reference anchor. static proofs are used to
/// computed the pre computed hashes and the result is checked against
/// document root provided.
pub fn verify_proof<V: Verifier>(matches: &mut Vec<V::Hash>, proof: &Proof<V::Hash>) -> bool {
let Proof {
leaf_hash,
Expand Down Expand Up @@ -149,8 +153,8 @@ pub mod hashing {

/// Return a bundled hash from a list of hashes.
///
/// This function appends `deposit_address` and all the given `hashes` from the proofs and
/// returns the result hash
/// This function appends `deposit_address` and all the given `hashes` from
/// the proofs and returns the result hash
pub fn bundled_hash<H: Hasher>(
hashes: Vec<H::Hash>,
deposit_address: DepositAddress,
Expand Down
13 changes: 8 additions & 5 deletions libs/test-utils/src/mocks/accountant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

/// Exposes a struct $name that implements the `trait Accountant`. The struct expects one generic
/// parameter that implements the fungibles traits `Inspect`, `Mutate` and `Transfer`. Furthermore,
/// there exists a struct `GenesisConfig` that implements `trait GenesisBuild` that can be used
/// like any other `GenesisConfig` to initialize state in the `TestExternalities`.
/// Exposes a struct $name that implements the `trait Accountant`. The struct
/// expects one generic parameter that implements the fungibles traits
/// `Inspect`, `Mutate` and `Transfer`. Furthermore, there exists a struct
/// `GenesisConfig` that implements `trait GenesisBuild` that can be used
/// like any other `GenesisConfig` to initialize state in the
/// `TestExternalities`.
///
/// Also exports a `struct InvestmentInfo` to be used in the `GenesisConfig`
///
/// * E.g.: `MockAccountant<Tokens: frame_support::traits::tokens::fungibles::{Inspect, Mutate, Transfer}>`
/// * E.g.: `MockAccountant<Tokens:
/// frame_support::traits::tokens::fungibles::{Inspect, Mutate, Transfer}>`
///
/// # Example macro usage:
/// ```ignore
Expand Down
9 changes: 5 additions & 4 deletions libs/test-utils/src/mocks/authority_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ use sp_std::marker::PhantomData;

type AccountId = u64;

/// This OrmlAssetRegistry::AuthorityOrigin implementation is used for our pallet-loans
/// and pallet-pool-system Mocks. We overwrite this because of the `type AccountId = u64`.
/// In the runtime tests, we use proper AccountIds, in the Mocks, we use 1,2,3,... .
/// Therefore, we implement `AuthorityOrigin` and use the `u64` type for the AccountId.
/// This OrmlAssetRegistry::AuthorityOrigin implementation is used for our
/// pallet-loans and pallet-pool-system Mocks. We overwrite this because of the
/// `type AccountId = u64`. In the runtime tests, we use proper AccountIds, in
/// the Mocks, we use 1,2,3,... . Therefore, we implement `AuthorityOrigin` and
/// use the `u64` type for the AccountId.
///
/// Use this implementation only when setting up Mocks with simple AccountIds.
pub struct AuthorityOrigin<
Expand Down
13 changes: 7 additions & 6 deletions libs/test-utils/src/mocks/order_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ pub mod pallet {
{
/// **Test Method**
///
/// Moves funds from the `T::FundsAccount` to the local `OrderManagerAccount`
/// Moves funds from the `T::FundsAccount` to the local
/// `OrderManagerAccount`
pub fn update_invest_order(
investment_id: T::InvestmentId,
amount: BalanceOf<T>,
Expand All @@ -194,9 +195,9 @@ pub mod pallet {

/// **Test Method**
///
/// DOES NOT move funds. We assume that all received `TrancheTokens` stay in the
/// given `OrderManagerAccount` while testing. Hence, if redeemptions should be
/// locked we do not need to move them.
/// DOES NOT move funds. We assume that all received `TrancheTokens`
/// stay in the given `OrderManagerAccount` while testing. Hence, if
/// redeemptions should be locked we do not need to move them.
pub fn update_redeem_order(
investment_id: T::InvestmentId,
amount: BalanceOf<T>,
Expand All @@ -205,8 +206,8 @@ pub mod pallet {
orders.amount += amount;
RedeemOrders::<T>::insert(investment_id, orders);

// NOTE: TrancheTokens NEVER leave the TEST_PALLET_ID account and hence we can keep them here and
// need no transfer.
// NOTE: TrancheTokens NEVER leave the TEST_PALLET_ID account and hence we can
// keep them here and need no transfer.

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion libs/traits/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub trait DataRegistry<DataId, CollectionId> {
/// Return the last data value for a data id
fn get(data_id: &DataId) -> Self::Data;

/// Retrives a collection of data with all data associated to a collection id
/// Retrives a collection of data with all data associated to a collection
/// id
fn collection(collection_id: &CollectionId) -> Self::Collection;

/// Start listening data changes for a data id in a collection id
Expand Down
52 changes: 29 additions & 23 deletions libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ pub mod data;
/// A trait used for loosely coupling the claim pallet with a reward mechanism.
///
/// ## Overview
/// The crowdloan reward mechanism is separated from the crowdloan claiming process, the latter
/// being generic, acting as a kind of proxy to the rewarding mechanism, that is specific to
/// to each crowdloan campaign. The aim of this pallet is to ensure that a claim for a reward
/// payout is well-formed, checking for replay attacks, spams or invalid claim (e.g. unknown
/// The crowdloan reward mechanism is separated from the crowdloan claiming
/// process, the latter being generic, acting as a kind of proxy to the
/// rewarding mechanism, that is specific to to each crowdloan campaign. The aim
/// of this pallet is to ensure that a claim for a reward payout is well-formed,
/// checking for replay attacks, spams or invalid claim (e.g. unknown
/// contributor, exceeding reward amount, ...).
/// See the [`crowdloan-reward`] pallet, that implements a reward mechanism with vesting, for
/// instance.
/// See the [`crowdloan-reward`] pallet, that implements a reward mechanism with
/// vesting, for instance.
pub trait Reward {
/// The account from the parachain, that the claimer provided in her/his transaction.
/// The account from the parachain, that the claimer provided in her/his
/// transaction.
type ParachainAccountId: Debug
+ MaybeSerialize
+ MaybeSerializeDeserialize
Expand Down Expand Up @@ -91,8 +93,8 @@ pub trait Reward {

/// Rewarding function that is invoked from the claim pallet.
///
/// If this function returns successfully, any subsequent claim of the same claimer will be
/// rejected by the claim module.
/// If this function returns successfully, any subsequent claim of the same
/// claimer will be rejected by the claim module.
fn reward(
who: Self::ParachainAccountId,
contribution: Self::ContributionAmount,
Expand All @@ -113,7 +115,8 @@ pub trait PoolNAV<PoolId, Amount> {
) -> DispatchResult;
}

/// A trait that support pool inspection operations such as pool existence checks and pool admin of permission set.
/// A trait that support pool inspection operations such as pool existence
/// checks and pool admin of permission set.
pub trait PoolInspect<AccountId, CurrencyId> {
type PoolId: Parameter
+ Member
Expand Down Expand Up @@ -214,8 +217,9 @@ pub trait CurrencyPrice<CurrencyId> {
type Rate;
type Moment;

/// Retrieve the latest price of `base` currency, denominated in the `quote` currency
/// If `quote` currency is not passed, then the default `quote` currency is used (when possible)
/// Retrieve the latest price of `base` currency, denominated in the `quote`
/// currency If `quote` currency is not passed, then the default `quote`
/// currency is used (when possible)
fn get_latest(
base: CurrencyId,
quote: Option<CurrencyId>,
Expand Down Expand Up @@ -261,7 +265,8 @@ pub trait InterestAccrual<InterestRate, Balance, Adjustment> {
/// Ask if the rate is valid to use by the implementation
fn validate_rate(interest_rate_per_year: InterestRate) -> DispatchResult;

/// Returns a collection of pre-computed rates to perform multiple operations with
/// Returns a collection of pre-computed rates to perform multiple
/// operations with
fn rates() -> Self::Rates;
}

Expand Down Expand Up @@ -385,8 +390,8 @@ pub trait Investment<AccountId> {
amount: Self::Amount,
) -> Result<(), Self::Error>;

/// Returns, if possible, the current investment amount of who into the given investment
/// class
/// Returns, if possible, the current investment amount of who into the
/// given investment class
fn investment(
who: &AccountId,
investment_id: Self::InvestmentId,
Expand All @@ -402,8 +407,8 @@ pub trait Investment<AccountId> {
amount: Self::Amount,
) -> Result<(), Self::Error>;

/// Returns, if possible, the current redemption amount of who into the given investment
/// class
/// Returns, if possible, the current redemption amount of who into the
/// given investment class
fn redemption(
who: &AccountId,
investment_id: Self::InvestmentId,
Expand Down Expand Up @@ -596,8 +601,8 @@ pub mod fees {
fn fee_value(key: Self::FeeKey) -> Self::Balance;

/// Pay an amount of fee to the block author
/// If the `from` account has not enough balance or the author is invalid the fees are not
/// paid.
/// If the `from` account has not enough balance or the author is
/// invalid the fees are not paid.
fn fee_to_author(
from: &Self::AccountId,
fee: Fee<Self::Balance, Self::FeeKey>,
Expand All @@ -619,13 +624,14 @@ pub mod fees {
}
}

/// Trait to determine whether a sending account and currency have a restriction,
/// and if so is there an allowance for the reciever location.
/// Trait to determine whether a sending account and currency have a
/// restriction, and if so is there an allowance for the reciever location.
pub trait TransferAllowance<AccountId> {
type CurrencyId;
type Location: Member + Debug + Eq + PartialEq + TypeInfo + Encode + Decode + MaxEncodedLen;
/// Determines whether the `send` account is allowed to make a transfer to the `recieve` loocation with `currency` type currency.
/// Returns result wrapped bool for whether allowance is allowed.
/// Determines whether the `send` account is allowed to make a transfer to
/// the `recieve` loocation with `currency` type currency. Returns result
/// wrapped bool for whether allowance is allowed.
fn allowance(
send: AccountId,
recieve: Self::Location,
Expand Down
Loading

0 comments on commit 189b221

Please sign in to comment.