mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
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:
@@ -24,7 +24,7 @@
|
||||
|
||||
use sp_runtime::RuntimeDebug;
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -34,9 +34,9 @@ pub use pallet::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
@@ -65,9 +65,10 @@ pub mod pallet {
|
||||
/// The example utilizes parallel execution by checking half of the
|
||||
/// signatures in spawned task.
|
||||
#[pallet::weight(0)]
|
||||
pub fn enlist_participants(origin: OriginFor<T>, participants: Vec<EnlistedParticipant>)
|
||||
-> DispatchResultWithPostInfo
|
||||
{
|
||||
pub fn enlist_participants(
|
||||
origin: OriginFor<T>,
|
||||
participants: Vec<EnlistedParticipant>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let _ = ensure_signed(origin)?;
|
||||
|
||||
if validate_participants_parallel(&<CurrentEventId<T>>::get(), &participants[..]) {
|
||||
@@ -103,21 +104,20 @@ pub struct EnlistedParticipant {
|
||||
impl EnlistedParticipant {
|
||||
fn verify(&self, event_id: &[u8]) -> bool {
|
||||
use sp_core::Public;
|
||||
use std::convert::TryFrom;
|
||||
use sp_runtime::traits::Verify;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
match sp_core::sr25519::Signature::try_from(&self.signature[..]) {
|
||||
Ok(signature) => {
|
||||
let public = sp_core::sr25519::Public::from_slice(self.account.as_ref());
|
||||
signature.verify(event_id, &public)
|
||||
}
|
||||
_ => false
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_participants_parallel(event_id: &[u8], participants: &[EnlistedParticipant]) -> bool {
|
||||
|
||||
fn spawn_verify(data: Vec<u8>) -> Vec<u8> {
|
||||
let stream = &mut &data[..];
|
||||
let event_id = Vec::<u8>::decode(stream).expect("Failed to decode");
|
||||
@@ -138,10 +138,10 @@ fn validate_participants_parallel(event_id: &[u8], participants: &[EnlistedParti
|
||||
let handle = sp_tasks::spawn(spawn_verify, async_payload);
|
||||
let mut result = true;
|
||||
|
||||
for participant in &participants[participants.len()/2+1..] {
|
||||
for participant in &participants[participants.len() / 2 + 1..] {
|
||||
if !participant.verify(event_id) {
|
||||
result = false;
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ use crate::{self as pallet_example_parallel, *};
|
||||
use frame_support::parameter_types;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
Perbill, testing::Header,
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
Perbill,
|
||||
};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
@@ -108,7 +109,6 @@ fn it_can_enlist() {
|
||||
|
||||
assert_eq!(Example::participants().len(), 2);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -146,5 +146,4 @@ fn one_wrong_will_not_enlist_anyone() {
|
||||
|
||||
assert_eq!(Example::participants().len(), 0);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user