ci: add quick-check with rustfmt (#615)

* ci: add quick-check with clippy and rustfmt

* chore: rustfmt round

* chore: set the same rustfmt config than substrate

* chore: fix formatting

* cI: remove clippy

* ci: switch to nightly for the checks

* ci: fix toolchains and naming

* ci: Limit the check to formatting

* chore: fix formatting

* Update .rustfmt.toml

* Update .rustfmt.toml

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Chevdor
2021-09-16 16:57:52 +02:00
committed by GitHub
parent e3eb3a0a12
commit 6b20f7a2c5
98 changed files with 1244 additions and 1872 deletions
@@ -22,9 +22,9 @@ pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use cumulus_primitives_core::ParaId;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use cumulus_primitives_core::ParaId;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
@@ -47,9 +47,7 @@ pub mod pallet {
#[cfg(feature = "std")]
impl Default for GenesisConfig {
fn default() -> Self {
Self {
parachain_id: 100.into()
}
Self { parachain_id: 100.into() }
}
}
@@ -61,11 +59,14 @@ pub mod pallet {
}
#[pallet::type_value]
pub(super) fn DefaultForParachainId() -> ParaId { 100.into() }
pub(super) fn DefaultForParachainId() -> ParaId {
100.into()
}
#[pallet::storage]
#[pallet::getter(fn parachain_id)]
pub(super) type ParachainId<T: Config> = StorageValue<_, ParaId, ValueQuery, DefaultForParachainId>;
pub(super) type ParachainId<T: Config> =
StorageValue<_, ParaId, ValueQuery, DefaultForParachainId>;
impl<T: Config> Get<ParaId> for Pallet<T> {
fn get() -> ParaId {
@@ -18,20 +18,20 @@
#![cfg_attr(not(feature = "std"), no_std)]
use cumulus_pallet_xcm::{ensure_sibling_para, Origin as CumulusOrigin};
use cumulus_primitives_core::ParaId;
use frame_system::Config as SystemConfig;
use sp_runtime::traits::Saturating;
use sp_std::prelude::*;
use xcm::latest::prelude::*;
use sp_runtime::traits::Saturating;
use frame_system::Config as SystemConfig;
use cumulus_primitives_core::ParaId;
use cumulus_pallet_xcm::{Origin as CumulusOrigin, ensure_sibling_para};
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
@@ -43,7 +43,8 @@ pub mod pallet {
/// The overarching event type.
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type Origin: From<<Self as SystemConfig>::Origin> + Into<Result<CumulusOrigin, <Self as Config>::Origin>>;
type Origin: From<<Self as SystemConfig>::Origin>
+ Into<Result<CumulusOrigin, <Self as Config>::Origin>>;
/// The overarching call type; we assume sibling chains use the same type.
type Call: From<Call<Self>> + Encode;
@@ -53,29 +54,16 @@ pub mod pallet {
/// The target parachains to ping.
#[pallet::storage]
pub(super) type Targets<T: Config> = StorageValue<
_,
Vec<(ParaId, Vec<u8>)>,
ValueQuery,
>;
pub(super) type Targets<T: Config> = StorageValue<_, Vec<(ParaId, Vec<u8>)>, ValueQuery>;
/// The total number of pings sent.
#[pallet::storage]
pub(super) type PingCount<T: Config> = StorageValue<
_,
u32,
ValueQuery,
>;
pub(super) type PingCount<T: Config> = StorageValue<_, u32, ValueQuery>;
/// The sent pings.
#[pallet::storage]
pub(super) type Pings<T: Config> = StorageMap<
_,
Blake2_128Concat,
u32,
T::BlockNumber,
OptionQuery,
>;
pub(super) type Pings<T: Config> =
StorageMap<_, Blake2_128Concat, u32, T::BlockNumber, OptionQuery>;
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
@@ -94,17 +82,23 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(
n: T::BlockNumber,
) {
fn on_finalize(n: T::BlockNumber) {
for (para, payload) in Targets::<T>::get().into_iter() {
let seq = PingCount::<T>::mutate(|seq| { *seq += 1; *seq });
let seq = PingCount::<T>::mutate(|seq| {
*seq += 1;
*seq
});
match T::XcmSender::send_xcm(
(1, Junction::Parachain(para.into())).into(),
Xcm(vec![Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 1_000,
call: <T as Config>::Call::from(Call::<T>::ping { seq, payload: payload.clone() }).encode().into(),
call: <T as Config>::Call::from(Call::<T>::ping {
seq,
payload: payload.clone(),
})
.encode()
.into(),
}]),
) {
Ok(()) => {
@@ -113,7 +107,7 @@ pub mod pallet {
},
Err(e) => {
Self::deposit_event(Event::ErrorSendingPing(e, para, seq, payload));
}
},
}
}
}
@@ -129,7 +123,12 @@ pub mod pallet {
}
#[pallet::weight(0)]
pub fn start_many(origin: OriginFor<T>, para: ParaId, count: u32, payload: Vec<u8>) -> DispatchResult {
pub fn start_many(
origin: OriginFor<T>,
para: ParaId,
count: u32,
payload: Vec<u8>,
) -> DispatchResult {
ensure_root(origin)?;
for _ in 0..count {
Targets::<T>::mutate(|t| t.push((para, payload.clone())));
@@ -140,7 +139,11 @@ pub mod pallet {
#[pallet::weight(0)]
pub fn stop(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
ensure_root(origin)?;
Targets::<T>::mutate(|t| if let Some(p) = t.iter().position(|(p, _)| p == &para) { t.swap_remove(p); });
Targets::<T>::mutate(|t| {
if let Some(p) = t.iter().position(|(p, _)| p == &para) {
t.swap_remove(p);
}
});
Ok(())
}
@@ -166,7 +169,12 @@ pub mod pallet {
Xcm(vec![Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 1_000,
call: <T as Config>::Call::from(Call::<T>::pong { seq, payload: payload.clone() } ).encode().into(),
call: <T as Config>::Call::from(Call::<T>::pong {
seq,
payload: payload.clone(),
})
.encode()
.into(),
}]),
) {
Ok(()) => Self::deposit_event(Event::PongSent(para, seq, payload)),
@@ -181,7 +189,12 @@ pub mod pallet {
let para = ensure_sibling_para(<T as Config>::Origin::from(origin))?;
if let Some(sent_at) = Pings::<T>::take(seq) {
Self::deposit_event(Event::Ponged(para, seq, payload, frame_system::Pallet::<T>::block_number().saturating_sub(sent_at)));
Self::deposit_event(Event::Ponged(
para,
seq,
payload,
frame_system::Pallet::<T>::block_number().saturating_sub(sent_at),
));
} else {
// Pong received for a ping we apparently didn't send?!
Self::deposit_event(Event::UnknownPong(para, seq, payload));