Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 6c7e0fd

Browse files
authored
Migrate pallet event from tuple to struct (paritytech#195)
Now it's recommended to use a struct for the event.
1 parent 11cc3fb commit 6c7e0fd

File tree

10 files changed

+72
-32
lines changed

10 files changed

+72
-32
lines changed

crates/pallet-executor/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ mod pallet {
4646
#[pallet::generate_deposit(pub(super) fn deposit_event)]
4747
pub enum Event<T: Config> {
4848
/// A new candidate receipt was backed.
49-
CandidateReceiptStored(T::BlockNumber, T::Hash),
49+
CandidateReceiptStored {
50+
head_number: T::BlockNumber,
51+
head_hash: T::Hash,
52+
},
5053
}
5154

5255
#[pallet::call]
@@ -78,7 +81,10 @@ mod pallet {
7881
LastHeadNumber::<T>::put(head_number);
7982
Heads::<T>::insert(head_number, head_hash);
8083

81-
Self::deposit_event(Event::CandidateReceiptStored(head_number, head_hash));
84+
Self::deposit_event(Event::CandidateReceiptStored {
85+
head_number,
86+
head_hash,
87+
});
8288

8389
Ok(())
8490
}

crates/pallet-feeds/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,14 @@ mod pallet {
8080
#[pallet::event]
8181
#[pallet::generate_deposit(pub(super) fn deposit_event)]
8282
pub enum Event<T: Config> {
83-
/// New object is added \[object_metadata, account_id, object_size\]
84-
DataSubmitted(ObjectMetadata, T::AccountId, u64),
85-
/// New feed is created \[feed_id, account_id\]
86-
FeedCreated(FeedId, T::AccountId),
83+
/// New object was added.
84+
DataSubmitted {
85+
metadata: ObjectMetadata,
86+
who: T::AccountId,
87+
object_size: u64,
88+
},
89+
/// New feed was created.
90+
FeedCreated { feed_id: FeedId, who: T::AccountId },
8791
}
8892

8993
/// `pallet-feeds` errors
@@ -107,7 +111,7 @@ mod pallet {
107111

108112
Totals::<T>::insert(feed_id, TotalObjectsAndSize::default());
109113

110-
Self::deposit_event(Event::FeedCreated(feed_id, who));
114+
Self::deposit_event(Event::FeedCreated { feed_id, who });
111115

112116
Ok(())
113117
}
@@ -140,7 +144,11 @@ mod pallet {
140144
feed_totals.count += 1;
141145
});
142146

143-
Self::deposit_event(Event::DataSubmitted(metadata, who, object_size));
147+
Self::deposit_event(Event::DataSubmitted {
148+
metadata,
149+
who,
150+
object_size,
151+
});
144152

145153
Ok(())
146154
}

crates/pallet-feeds/src/tests.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ fn can_create_feed() {
1616

1717
assert_eq!(Feeds::totals(0), TotalObjectsAndSize::default());
1818

19-
System::assert_last_event(Event::Feeds(crate::Event::<Test>::FeedCreated(
20-
FEED_ID, ACCOUNT_ID,
21-
)));
19+
System::assert_last_event(Event::Feeds(crate::Event::<Test>::FeedCreated {
20+
feed_id: FEED_ID,
21+
who: ACCOUNT_ID,
22+
}));
2223
});
2324
}
2425

@@ -50,11 +51,11 @@ fn can_do_put() {
5051
}
5152
);
5253

53-
System::assert_last_event(Event::Feeds(crate::Event::<Test>::DataSubmitted(
54-
object_metadata,
55-
ACCOUNT_ID,
54+
System::assert_last_event(Event::Feeds(crate::Event::<Test>::DataSubmitted {
55+
metadata: object_metadata,
56+
who: ACCOUNT_ID,
5657
object_size,
57-
)));
58+
}));
5859
});
5960
}
6061

crates/pallet-object-store/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ mod pallet {
5050
#[pallet::event]
5151
#[pallet::generate_deposit(pub(super) fn deposit_event)]
5252
pub enum Event<T: Config> {
53-
/// New object is added \[who, object_id, object_size\]
54-
DataSubmitted(T::AccountId, Sha256Hash, u32),
53+
/// New object was added.
54+
DataSubmitted {
55+
who: T::AccountId,
56+
object_id: Sha256Hash,
57+
object_size: u32,
58+
},
5559
}
5660

5761
#[pallet::call]
@@ -74,7 +78,11 @@ mod pallet {
7478
object_size
7579
);
7680

77-
Self::deposit_event(Event::DataSubmitted(who, object_id, object_size));
81+
Self::deposit_event(Event::DataSubmitted {
82+
who,
83+
object_id,
84+
object_size,
85+
});
7886

7987
Ok(())
8088
}

crates/pallet-object-store/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ fn can_do_put() {
1313

1414
assert_ok!(ObjectStore::put(Origin::signed(ACCOUNT_ID), object));
1515

16-
System::assert_last_event(Event::ObjectStore(crate::Event::<Test>::DataSubmitted(
17-
ACCOUNT_ID,
16+
System::assert_last_event(Event::ObjectStore(crate::Event::<Test>::DataSubmitted {
17+
who: ACCOUNT_ID,
1818
object_id,
1919
object_size,
20-
)));
20+
}));
2121
});
2222
}

crates/pallet-offences-subspace/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ mod pallet {
101101
/// There is an offence reported of the given `kind` happened at the `session_index` and
102102
/// (kind-specific) time slot. This event is not deposited for duplicate slashes.
103103
/// \[kind, timeslot\].
104-
Offence(Kind, OpaqueTimeSlot),
104+
Offence {
105+
kind: Kind,
106+
timeslot: OpaqueTimeSlot,
107+
},
105108
}
106109
}
107110

@@ -123,7 +126,10 @@ impl<T: Config, O: Offence<FarmerPublicKey>> ReportOffence<FarmerPublicKey, O> f
123126
T::OnOffenceHandler::on_offence(&concurrent_offenders);
124127

125128
// Deposit the event.
126-
Self::deposit_event(Event::Offence(O::ID, time_slot.encode()));
129+
Self::deposit_event(Event::Offence {
130+
kind: O::ID,
131+
timeslot: time_slot.encode(),
132+
});
127133

128134
Ok(())
129135
}

crates/pallet-offences-subspace/src/tests.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ fn should_deposit_event() {
137137
System::events(),
138138
vec![EventRecord {
139139
phase: Phase::Initialization,
140-
event: Event::OffencesSubspace(crate::Event::Offence(KIND, time_slot.encode())),
140+
event: Event::OffencesSubspace(crate::Event::Offence {
141+
kind: KIND,
142+
timeslot: time_slot.encode()
143+
}),
141144
topics: vec![],
142145
}]
143146
);
@@ -174,7 +177,10 @@ fn doesnt_deposit_event_for_dups() {
174177
System::events(),
175178
vec![EventRecord {
176179
phase: Phase::Initialization,
177-
event: Event::OffencesSubspace(crate::Event::Offence(KIND, time_slot.encode())),
180+
event: Event::OffencesSubspace(crate::Event::Offence {
181+
kind: KIND,
182+
timeslot: time_slot.encode()
183+
}),
178184
topics: vec![],
179185
}]
180186
);

crates/pallet-rewards/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ mod pallet {
6363
#[pallet::event]
6464
#[pallet::generate_deposit(pub(super) fn deposit_event)]
6565
pub enum Event<T: Config> {
66-
/// Issued reward for the block author. \[block_author, reward\]
67-
BlockReward(T::AccountId, BalanceOf<T>),
66+
/// Issued reward for the block author.
67+
BlockReward {
68+
block_author: T::AccountId,
69+
reward: BalanceOf<T>,
70+
},
6871
}
6972

7073
#[pallet::hooks]
@@ -87,7 +90,10 @@ impl<T: Config> Pallet<T> {
8790
let reward = T::BlockReward::get();
8891
T::Currency::deposit_creating(&block_author, reward);
8992

90-
Self::deposit_event(Event::BlockReward(block_author, reward));
93+
Self::deposit_event(Event::BlockReward {
94+
block_author,
95+
reward,
96+
});
9197
}
9298
}
9399
}

crates/pallet-subspace/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ mod pallet {
237237
#[pallet::generate_deposit(pub(super) fn deposit_event)]
238238
pub enum Event {
239239
/// Root block was stored in blockchain history.
240-
/// \[root_block\].
241-
RootBlockStored(RootBlock),
240+
RootBlockStored { root_block: RootBlock },
242241
}
243242

244243
#[pallet::error]
@@ -962,7 +961,7 @@ impl<T: Config> Pallet<T> {
962961
fn do_store_root_blocks(root_blocks: Vec<RootBlock>) -> DispatchResult {
963962
for root_block in root_blocks {
964963
RecordsRoot::<T>::insert(root_block.segment_index(), root_block.records_root());
965-
Self::deposit_event(Event::RootBlockStored(root_block));
964+
Self::deposit_event(Event::RootBlockStored { root_block });
966965
}
967966
Ok(())
968967
}

crates/pallet-subspace/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fn store_root_block_works() {
592592
System::events(),
593593
vec![EventRecord {
594594
phase: Phase::Initialization,
595-
event: Event::Subspace(crate::Event::RootBlockStored(root_block)),
595+
event: Event::Subspace(crate::Event::RootBlockStored { root_block }),
596596
topics: vec![],
597597
}]
598598
);

0 commit comments

Comments
 (0)