Skip to content

Commit c32c0dc

Browse files
committed
update format with rustfmt
1 parent 47e772c commit c32c0dc

File tree

6 files changed

+153
-179
lines changed

6 files changed

+153
-179
lines changed

pallets/fund-admin-records/src/benchmarking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ benchmarks! {
1717
}
1818

1919
impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
20-
}
20+
}
+50-59
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,55 @@
11
use super::*;
2-
use frame_support::pallet_prelude::*;
3-
use frame_support::traits::Time;
4-
use frame_support::sp_io::hashing::blake2_256;
2+
use frame_support::{pallet_prelude::*, sp_io::hashing::blake2_256, traits::Time};
53

64
use crate::types::*;
75

86
impl<T: Config> Pallet<T> {
9-
/*---- Offchain extrinsics ----*/
10-
pub fn do_add_record(
11-
records: RecordCollection<T>,
12-
) -> DispatchResult{
13-
for record in records.iter().cloned() {
14-
// Validations
15-
ensure!(!record.0.is_empty(), Error::<T>::ProjectIdIsEmpty);
16-
ensure!(!record.1.is_empty(), Error::<T>::HashedInfoIsEmpty);
17-
18-
let project_id_validated = ProjectId::try_from(record.0.clone())
19-
.map_err(|_| Error::<T>::ProjectIdExceededMaxLength)?;
20-
21-
let hashed_info_validated = HashedInfo::try_from(record.1.clone())
22-
.map_err(|_| Error::<T>::HashedInfoExceededMaxLength)?;
23-
24-
// Get timestamp
25-
let creation_date: CreationDate = Self::get_timestamp_in_milliseconds().ok_or(Error::<T>::TimestampError)?;
26-
27-
let record_id: Id = (
28-
record.0.clone(),
29-
record.1.clone(),
30-
record.2,
31-
record.3,
32-
creation_date.clone()
33-
).using_encoded(blake2_256);
34-
35-
// Ensure the generated id is unique
36-
ensure!(!Records::<T>::contains_key((record.0.clone(), record.2), record_id), Error::<T>::IdAlreadyExists);
37-
38-
let record_data = RecordData {
39-
project_id: project_id_validated,
40-
hashed_info: hashed_info_validated,
41-
table_type: record.2,
42-
record_type: record.3,
43-
creation_date,
44-
};
45-
46-
// Insert the record into the storage
47-
<Records<T>>::insert(
48-
(record.0.clone(), record.2),
49-
&record_id,
50-
record_data
51-
);
52-
53-
Self::deposit_event(Event::RecordAdded(record.0, record.2, record.3, record_id));
54-
}
55-
Ok(())
56-
}
57-
58-
fn get_timestamp_in_milliseconds() -> Option<u64> {
59-
let timestamp: u64 = T::Timestamp::now().into();
60-
61-
Some(timestamp)
62-
}
63-
64-
}
7+
/* ---- Offchain extrinsics ---- */
8+
pub fn do_add_record(records: RecordCollection<T>) -> DispatchResult {
9+
for record in records.iter().cloned() {
10+
// Validations
11+
ensure!(!record.0.is_empty(), Error::<T>::ProjectIdIsEmpty);
12+
ensure!(!record.1.is_empty(), Error::<T>::HashedInfoIsEmpty);
13+
14+
let project_id_validated = ProjectId::try_from(record.0.clone())
15+
.map_err(|_| Error::<T>::ProjectIdExceededMaxLength)?;
16+
17+
let hashed_info_validated = HashedInfo::try_from(record.1.clone())
18+
.map_err(|_| Error::<T>::HashedInfoExceededMaxLength)?;
19+
20+
// Get timestamp
21+
let creation_date: CreationDate =
22+
Self::get_timestamp_in_milliseconds().ok_or(Error::<T>::TimestampError)?;
23+
24+
let record_id: Id =
25+
(record.0.clone(), record.1.clone(), record.2, record.3, creation_date.clone())
26+
.using_encoded(blake2_256);
27+
28+
// Ensure the generated id is unique
29+
ensure!(
30+
!Records::<T>::contains_key((record.0.clone(), record.2), record_id),
31+
Error::<T>::IdAlreadyExists
32+
);
33+
34+
let record_data = RecordData {
35+
project_id: project_id_validated,
36+
hashed_info: hashed_info_validated,
37+
table_type: record.2,
38+
record_type: record.3,
39+
creation_date,
40+
};
41+
42+
// Insert the record into the storage
43+
<Records<T>>::insert((record.0.clone(), record.2), &record_id, record_data);
44+
45+
Self::deposit_event(Event::RecordAdded(record.0, record.2, record.3, record_id));
46+
}
47+
Ok(())
48+
}
49+
50+
fn get_timestamp_in_milliseconds() -> Option<u64> {
51+
let timestamp: u64 = T::Timestamp::now().into();
52+
53+
Some(timestamp)
54+
}
55+
}

pallets/fund-admin-records/src/lib.rs

+29-40
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ mod types;
1616

1717
#[frame_support::pallet]
1818
pub mod pallet {
19-
use frame_support::pallet_prelude::*;
19+
use frame_support::{pallet_prelude::*, traits::Time};
2020
use frame_system::pallet_prelude::*;
2121
use sp_runtime::traits::Scale;
22-
use frame_support::traits::Time;
2322

2423
use crate::types::*;
2524
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
@@ -29,34 +28,29 @@ pub mod pallet {
2928
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
3029

3130
type Moment: Parameter
32-
+ Default
33-
+ Scale<Self::BlockNumber, Output = Self::Moment>
34-
+ Copy
35-
+ MaxEncodedLen
36-
+ scale_info::StaticTypeInfo
37-
+ Into<u64>;
31+
+ Default
32+
+ Scale<Self::BlockNumber, Output = Self::Moment>
33+
+ Copy
34+
+ MaxEncodedLen
35+
+ scale_info::StaticTypeInfo
36+
+ Into<u64>;
3837

3938
type Timestamp: Time<Moment = Self::Moment>;
4039

4140
type RemoveOrigin: EnsureOrigin<Self::RuntimeOrigin>;
4241

4342
#[pallet::constant]
4443
type MaxRecordsAtTime: Get<u32>;
45-
4644
}
4745

4846
#[pallet::pallet]
4947
#[pallet::storage_version(STORAGE_VERSION)]
5048
pub struct Pallet<T>(_);
5149

52-
/*--- Onchain storage section ---*/
50+
/* --- Onchain storage section --- */
5351
#[pallet::storage]
5452
#[pallet::getter(fn signer_account)]
55-
pub(super) type SignerAccount<T: Config> = StorageValue<
56-
_,
57-
T::AccountId,
58-
OptionQuery
59-
>;
53+
pub(super) type SignerAccount<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;
6054

6155
#[pallet::storage]
6256
#[pallet::getter(fn records)]
@@ -65,18 +59,18 @@ pub mod pallet {
6559
Identity,
6660
(ProjectId, TableType), //K1: (projectId, TableType)
6761
Identity,
68-
Id, //K2: record id
62+
Id, //K2: record id
6963
RecordData, // Value record data
7064
OptionQuery,
7165
>;
7266

73-
// E V E N T S
67+
// E V E N T S
7468
// --------------------------------------------------------------------
7569
#[pallet::event]
7670
#[pallet::generate_deposit(pub(super) fn deposit_event)]
7771
pub enum Event<T: Config> {
78-
/// A record was added
79-
RecordAdded(ProjectId, TableType, RecordType, Id),
72+
/// A record was added
73+
RecordAdded(ProjectId, TableType, RecordType, Id),
8074
}
8175

8276
// E R R O R S
@@ -103,22 +97,19 @@ pub mod pallet {
10397
MaxRegistrationsAtATimeReached,
10498
}
10599

106-
// E X T R I N S I C S
100+
// E X T R I N S I C S
107101
// --------------------------------------------------------------------
108102
#[pallet::call]
109103
impl<T: Config> Pallet<T> {
110104
/// Sets the signer account.
111-
///
105+
///
112106
/// # Parameters:
113107
/// * `origin` - The sender of the transaction
114108
/// * `signer_account` - The account id of the signer
115109
/// Returns `Ok` if the operation is successful, `Err` otherwise.
116110
#[pallet::call_index(1)]
117111
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
118-
pub fn set_signer_account(
119-
origin: OriginFor<T>,
120-
account: T::AccountId,
121-
) -> DispatchResult {
112+
pub fn set_signer_account(origin: OriginFor<T>, account: T::AccountId) -> DispatchResult {
122113
T::RemoveOrigin::ensure_origin(origin)?;
123114
<SignerAccount<T>>::put(account);
124115
Ok(())
@@ -129,31 +120,31 @@ pub mod pallet {
129120
/// # Parameters:
130121
///
131122
/// - `origin`: The origin of the call. Must be a signed extrinsic.
132-
/// - `records`: The collection of records to be added. It is a vector of tuples, where each tuple represents a single record.
123+
/// - `records`: The collection of records to be added. It is a vector of tuples, where each
124+
/// tuple represents a single record.
133125
///
134126
/// # Returns:
135127
///
136-
/// - DispatchResult: This function will return an instance of `DispatchResult`.
137-
/// If the function executes successfully without any error, it will return `Ok(())`.
138-
/// If there is an error, it will return `Err(error)`, where `error` is an instance of the `DispatchError` class.
128+
/// - DispatchResult: This function will return an instance of `DispatchResult`. If the
129+
/// function executes successfully without any error, it will return `Ok(())`. If there is
130+
/// an error, it will return `Err(error)`, where `error` is an instance of the
131+
/// `DispatchError` class.
139132
#[pallet::call_index(2)]
140133
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
141-
pub fn add_record(
142-
origin: OriginFor<T>,
143-
records: RecordCollection<T>,
144-
) -> DispatchResult {
134+
pub fn add_record(origin: OriginFor<T>, records: RecordCollection<T>) -> DispatchResult {
145135
let who = ensure_signed(origin.clone())?;
146136

147137
// Ensure the signer account is set
148-
let signer_account = SignerAccount::<T>::get().ok_or(Error::<T>::SignerAccountNotSet)?;
138+
let signer_account =
139+
SignerAccount::<T>::get().ok_or(Error::<T>::SignerAccountNotSet)?;
149140

150141
// Ensure the sender is the signer account
151142
ensure!(who == signer_account, Error::<T>::SenderIsNotTheSignerAccount);
152143

153144
Self::do_add_record(records)
154145
}
155146

156-
/// Kill all the stored data.
147+
/// Kill all the stored data.
157148
///
158149
/// This function is used to kill ALL the stored data.
159150
/// Use it with caution!
@@ -165,13 +156,11 @@ pub mod pallet {
165156
/// - This function is only available to the `admin` with sudo access.
166157
#[pallet::call_index(3)]
167158
#[pallet::weight(Weight::from_parts(10_000,0) + T::DbWeight::get().writes(10))]
168-
pub fn kill_storage(
169-
origin: OriginFor<T>,
170-
) -> DispatchResult{
159+
pub fn kill_storage(origin: OriginFor<T>) -> DispatchResult {
171160
T::RemoveOrigin::ensure_origin(origin.clone())?;
172161
let _ = <SignerAccount<T>>::kill();
173162
let _ = <Records<T>>::clear(1000, None);
174163
Ok(())
175164
}
176-
}
177-
}
165+
}
166+
}

pallets/fund-admin-records/src/mock.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ impl pallet_fund_admin_records::Config for Test {
6868
type MaxRecordsAtTime = MaxRecordsAtTime;
6969
}
7070

71-
72-
parameter_types! {
73-
74-
}
71+
parameter_types! {}
7572

7673
impl pallet_timestamp::Config for Test {
7774
type Moment = u64;

0 commit comments

Comments
 (0)