Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+40 -36
View File
@@ -42,16 +42,20 @@
mod tests;
use sp_std::{prelude::*, marker::PhantomData, ops::{Deref, DerefMut}};
use sp_io::hashing::blake2_256;
use codec::{Decode, Encode};
use frame_support::{
RuntimeDebugNoBound,
traits::{Get, Currency, ReservableCurrency, BalanceStatus},
weights::Weight,
dispatch::DispatchResult,
traits::{BalanceStatus, Currency, Get, ReservableCurrency},
weights::Weight,
RuntimeDebugNoBound,
};
use codec::{Encode, Decode};
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeDebug;
use sp_std::{
marker::PhantomData,
ops::{Deref, DerefMut},
prelude::*,
};
/// Pending atomic swap operation.
#[derive(Clone, Eq, PartialEq, RuntimeDebugNoBound, Encode, Decode)]
@@ -93,14 +97,20 @@ pub struct BalanceSwapAction<AccountId, C: ReservableCurrency<AccountId>> {
_marker: PhantomData<C>,
}
impl<AccountId, C> BalanceSwapAction<AccountId, C> where C: ReservableCurrency<AccountId> {
impl<AccountId, C> BalanceSwapAction<AccountId, C>
where
C: ReservableCurrency<AccountId>,
{
/// Create a new swap action value of balance.
pub fn new(value: <C as Currency<AccountId>>::Balance) -> Self {
Self { value, _marker: PhantomData }
}
}
impl<AccountId, C> Deref for BalanceSwapAction<AccountId, C> where C: ReservableCurrency<AccountId> {
impl<AccountId, C> Deref for BalanceSwapAction<AccountId, C>
where
C: ReservableCurrency<AccountId>,
{
type Target = <C as Currency<AccountId>>::Balance;
fn deref(&self) -> &Self::Target {
@@ -108,14 +118,18 @@ impl<AccountId, C> Deref for BalanceSwapAction<AccountId, C> where C: Reservable
}
}
impl<AccountId, C> DerefMut for BalanceSwapAction<AccountId, C> where C: ReservableCurrency<AccountId> {
impl<AccountId, C> DerefMut for BalanceSwapAction<AccountId, C>
where
C: ReservableCurrency<AccountId>,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.value
}
}
impl<T: Config, AccountId, C> SwapAction<AccountId, T> for BalanceSwapAction<AccountId, C>
where C: ReservableCurrency<AccountId>
where
C: ReservableCurrency<AccountId>,
{
fn reserve(&self, source: &AccountId) -> DispatchResult {
C::reserve(&source, self.value)
@@ -138,9 +152,9 @@ pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;
/// Atomic swap's pallet configuration trait.
#[pallet::config]
@@ -168,9 +182,12 @@ pub mod pallet {
pub struct Pallet<T>(PhantomData<T>);
#[pallet::storage]
pub type PendingSwaps<T: Config> = StorageDoubleMap<_,
Twox64Concat, T::AccountId,
Blake2_128Concat, HashedProof,
pub type PendingSwaps<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
T::AccountId,
Blake2_128Concat,
HashedProof,
PendingSwap<T>,
>;
@@ -209,7 +226,7 @@ pub mod pallet {
}
/// Old name generated by `decl_event`.
#[deprecated(note="use `Event` instead")]
#[deprecated(note = "use `Event` instead")]
pub type RawEvent<T> = Event<T>;
#[pallet::call]
@@ -249,9 +266,7 @@ pub mod pallet {
};
PendingSwaps::<T>::insert(target.clone(), hashed_proof.clone(), swap.clone());
Self::deposit_event(
Event::NewSwap(target, hashed_proof, swap)
);
Self::deposit_event(Event::NewSwap(target, hashed_proof, swap));
Ok(())
}
@@ -274,25 +289,20 @@ pub mod pallet {
proof: Vec<u8>,
action: T::SwapAction,
) -> DispatchResult {
ensure!(
proof.len() <= T::ProofLimit::get() as usize,
Error::<T>::ProofTooLarge,
);
ensure!(proof.len() <= T::ProofLimit::get() as usize, Error::<T>::ProofTooLarge,);
let target = ensure_signed(origin)?;
let hashed_proof = blake2_256(&proof);
let swap = PendingSwaps::<T>::get(&target, hashed_proof)
.ok_or(Error::<T>::InvalidProof)?;
let swap =
PendingSwaps::<T>::get(&target, hashed_proof).ok_or(Error::<T>::InvalidProof)?;
ensure!(swap.action == action, Error::<T>::ClaimActionMismatch);
let succeeded = swap.action.claim(&swap.source, &target);
PendingSwaps::<T>::remove(target.clone(), hashed_proof.clone());
Self::deposit_event(
Event::SwapClaimed(target, hashed_proof, succeeded)
);
Self::deposit_event(Event::SwapClaimed(target, hashed_proof, succeeded));
Ok(())
}
@@ -311,12 +321,8 @@ pub mod pallet {
) -> DispatchResult {
let source = ensure_signed(origin)?;
let swap = PendingSwaps::<T>::get(&target, hashed_proof)
.ok_or(Error::<T>::NotExist)?;
ensure!(
swap.source == source,
Error::<T>::SourceMismatch,
);
let swap = PendingSwaps::<T>::get(&target, hashed_proof).ok_or(Error::<T>::NotExist)?;
ensure!(swap.source == source, Error::<T>::SourceMismatch,);
ensure!(
frame_system::Pallet::<T>::block_number() >= swap.end_block,
Error::<T>::DurationNotPassed,
@@ -325,9 +331,7 @@ pub mod pallet {
swap.action.cancel(&swap.source);
PendingSwaps::<T>::remove(&target, hashed_proof.clone());
Self::deposit_event(
Event::SwapCancelled(target, hashed_proof)
);
Self::deposit_event(Event::SwapCancelled(target, hashed_proof));
Ok(())
}
+9 -18
View File
@@ -84,12 +84,7 @@ const B: u64 = 2;
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let genesis = pallet_balances::GenesisConfig::<Test> {
balances: vec![
(A, 100),
(B, 200),
],
};
let genesis = pallet_balances::GenesisConfig::<Test> { balances: vec![(A, 100), (B, 200)] };
genesis.assimilate_storage(&mut t).unwrap();
t.into()
}
@@ -112,7 +107,8 @@ fn two_party_successful_swap() {
hashed_proof.clone(),
BalanceSwapAction::new(50),
1000,
).unwrap();
)
.unwrap();
assert_eq!(Balances::free_balance(A), 100 - 50);
assert_eq!(Balances::free_balance(B), 200);
@@ -126,7 +122,8 @@ fn two_party_successful_swap() {
hashed_proof.clone(),
BalanceSwapAction::new(75),
1000,
).unwrap();
)
.unwrap();
assert_eq!(Balances::free_balance(A), 100);
assert_eq!(Balances::free_balance(B), 200 - 75);
@@ -134,11 +131,8 @@ fn two_party_successful_swap() {
// A reveals the proof and claims the swap on chain2.
chain2.execute_with(|| {
AtomicSwap::claim_swap(
Origin::signed(A),
proof.to_vec(),
BalanceSwapAction::new(75),
).unwrap();
AtomicSwap::claim_swap(Origin::signed(A), proof.to_vec(), BalanceSwapAction::new(75))
.unwrap();
assert_eq!(Balances::free_balance(A), 100 + 75);
assert_eq!(Balances::free_balance(B), 200 - 75);
@@ -146,11 +140,8 @@ fn two_party_successful_swap() {
// B use the revealed proof to claim the swap on chain1.
chain1.execute_with(|| {
AtomicSwap::claim_swap(
Origin::signed(B),
proof.to_vec(),
BalanceSwapAction::new(50),
).unwrap();
AtomicSwap::claim_swap(Origin::signed(B), proof.to_vec(), BalanceSwapAction::new(50))
.unwrap();
assert_eq!(Balances::free_balance(A), 100 - 50);
assert_eq!(Balances::free_balance(B), 200 + 50);