@@ -16,10 +16,9 @@ mod types;
16
16
17
17
#[ frame_support:: pallet]
18
18
pub mod pallet {
19
- use frame_support:: pallet_prelude:: * ;
19
+ use frame_support:: { pallet_prelude:: * , traits :: Time } ;
20
20
use frame_system:: pallet_prelude:: * ;
21
21
use sp_runtime:: traits:: Scale ;
22
- use frame_support:: traits:: Time ;
23
22
24
23
use crate :: types:: * ;
25
24
const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 1 ) ;
@@ -29,34 +28,29 @@ pub mod pallet {
29
28
type RuntimeEvent : From < Event < Self > > + IsType < <Self as frame_system:: Config >:: RuntimeEvent > ;
30
29
31
30
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 > ;
38
37
39
38
type Timestamp : Time < Moment = Self :: Moment > ;
40
39
41
40
type RemoveOrigin : EnsureOrigin < Self :: RuntimeOrigin > ;
42
41
43
42
#[ pallet:: constant]
44
43
type MaxRecordsAtTime : Get < u32 > ;
45
-
46
44
}
47
45
48
46
#[ pallet:: pallet]
49
47
#[ pallet:: storage_version( STORAGE_VERSION ) ]
50
48
pub struct Pallet < T > ( _ ) ;
51
49
52
- /*--- Onchain storage section ---*/
50
+ /* --- Onchain storage section --- */
53
51
#[ pallet:: storage]
54
52
#[ 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 > ;
60
54
61
55
#[ pallet:: storage]
62
56
#[ pallet:: getter( fn records) ]
@@ -65,18 +59,18 @@ pub mod pallet {
65
59
Identity ,
66
60
( ProjectId , TableType ) , //K1: (projectId, TableType)
67
61
Identity ,
68
- Id , //K2: record id
62
+ Id , //K2: record id
69
63
RecordData , // Value record data
70
64
OptionQuery ,
71
65
> ;
72
66
73
- // E V E N T S
67
+ // E V E N T S
74
68
// --------------------------------------------------------------------
75
69
#[ pallet:: event]
76
70
#[ pallet:: generate_deposit( pub ( super ) fn deposit_event) ]
77
71
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 ) ,
80
74
}
81
75
82
76
// E R R O R S
@@ -103,22 +97,19 @@ pub mod pallet {
103
97
MaxRegistrationsAtATimeReached ,
104
98
}
105
99
106
- // E X T R I N S I C S
100
+ // E X T R I N S I C S
107
101
// --------------------------------------------------------------------
108
102
#[ pallet:: call]
109
103
impl < T : Config > Pallet < T > {
110
104
/// Sets the signer account.
111
- ///
105
+ ///
112
106
/// # Parameters:
113
107
/// * `origin` - The sender of the transaction
114
108
/// * `signer_account` - The account id of the signer
115
109
/// Returns `Ok` if the operation is successful, `Err` otherwise.
116
110
#[ pallet:: call_index( 1 ) ]
117
111
#[ 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 {
122
113
T :: RemoveOrigin :: ensure_origin ( origin) ?;
123
114
<SignerAccount < T > >:: put ( account) ;
124
115
Ok ( ( ) )
@@ -129,31 +120,31 @@ pub mod pallet {
129
120
/// # Parameters:
130
121
///
131
122
/// - `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.
133
125
///
134
126
/// # Returns:
135
127
///
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.
139
132
#[ pallet:: call_index( 2 ) ]
140
133
#[ 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 {
145
135
let who = ensure_signed ( origin. clone ( ) ) ?;
146
136
147
137
// 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 ) ?;
149
140
150
141
// Ensure the sender is the signer account
151
142
ensure ! ( who == signer_account, Error :: <T >:: SenderIsNotTheSignerAccount ) ;
152
143
153
144
Self :: do_add_record ( records)
154
145
}
155
146
156
- /// Kill all the stored data.
147
+ /// Kill all the stored data.
157
148
///
158
149
/// This function is used to kill ALL the stored data.
159
150
/// Use it with caution!
@@ -165,13 +156,11 @@ pub mod pallet {
165
156
/// - This function is only available to the `admin` with sudo access.
166
157
#[ pallet:: call_index( 3 ) ]
167
158
#[ 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 {
171
160
T :: RemoveOrigin :: ensure_origin ( origin. clone ( ) ) ?;
172
161
let _ = <SignerAccount < T > >:: kill ( ) ;
173
162
let _ = <Records < T > >:: clear ( 1000 , None ) ;
174
163
Ok ( ( ) )
175
164
}
176
- }
177
- }
165
+ }
166
+ }
0 commit comments