diff --git a/auction/src/lib.rs b/auction/src/lib.rs index d1b71aaee..14b2bd0c7 100644 --- a/auction/src/lib.rs +++ b/auction/src/lib.rs @@ -69,8 +69,12 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(fn deposit_event)] pub enum Event { - /// A bid is placed. [auction_id, bidder, bidding_amount] - Bid(T::AuctionId, T::AccountId, T::Balance), + /// A bid is placed + Bid { + auction_id: T::AuctionId, + bidder: T::AccountId, + amount: T::Balance, + }, } /// Stores on-going and future auctions. Closed auction are removed. @@ -151,7 +155,11 @@ pub mod module { Ok(()) })?; - Self::deposit_event(Event::Bid(id, from, value)); + Self::deposit_event(Event::Bid { + auction_id: id, + bidder: from, + amount: value, + }); Ok(()) } } diff --git a/auction/src/tests.rs b/auction/src/tests.rs index 0c2864417..89edffcaf 100644 --- a/auction/src/tests.rs +++ b/auction/src/tests.rs @@ -68,7 +68,11 @@ fn bid_should_work() { }) ); assert_ok!(AuctionModule::bid(Origin::signed(ALICE), 0, 20)); - System::assert_last_event(Event::AuctionModule(crate::Event::Bid(0, ALICE, 20))); + System::assert_last_event(Event::AuctionModule(crate::Event::Bid { + auction_id: 0, + bidder: ALICE, + amount: 20, + })); assert_eq!( AuctionModule::auction_info(0), Some(AuctionInfo { diff --git a/authority/src/lib.rs b/authority/src/lib.rs index f9f242f7a..b7e6baf8f 100644 --- a/authority/src/lib.rs +++ b/authority/src/lib.rs @@ -184,22 +184,39 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(fn deposit_event)] pub enum Event { - /// A call is dispatched. [result] - Dispatched(DispatchResult), - /// A call is scheduled. [origin, index] - Scheduled(T::PalletsOrigin, ScheduleTaskIndex), - /// A scheduled call is fast tracked. [origin, index, when] - FastTracked(T::PalletsOrigin, ScheduleTaskIndex, T::BlockNumber), - /// A scheduled call is delayed. [origin, index, when] - Delayed(T::PalletsOrigin, ScheduleTaskIndex, T::BlockNumber), - /// A scheduled call is cancelled. [origin, index] - Cancelled(T::PalletsOrigin, ScheduleTaskIndex), - /// A call is authorized. \[hash, caller\] - AuthorizedCall(T::Hash, Option), - /// An authorized call was removed. \[hash\] - RemovedAuthorizedCall(T::Hash), - /// An authorized call was triggered. \[hash, caller\] - TriggeredCallBy(T::Hash, T::AccountId), + /// A call is dispatched. + Dispatched { result: DispatchResult }, + /// A call is scheduled. + Scheduled { + origin: T::PalletsOrigin, + index: ScheduleTaskIndex, + }, + /// A scheduled call is fast tracked. + FastTracked { + origin: T::PalletsOrigin, + index: ScheduleTaskIndex, + when: T::BlockNumber, + }, + /// A scheduled call is delayed. + Delayed { + origin: T::PalletsOrigin, + index: ScheduleTaskIndex, + when: T::BlockNumber, + }, + /// A scheduled call is cancelled. + Cancelled { + origin: T::PalletsOrigin, + index: ScheduleTaskIndex, + }, + /// A call is authorized. + AuthorizedCall { + hash: T::Hash, + caller: Option, + }, + /// An authorized call was removed. + RemovedAuthorizedCall { hash: T::Hash }, + /// An authorized call was triggered. + TriggeredCallBy { hash: T::Hash, caller: T::AccountId }, } #[pallet::storage] @@ -228,7 +245,9 @@ pub mod module { let e = call.dispatch(as_origin.into_origin().into()); - Self::deposit_event(Event::Dispatched(e.map(|_| ()).map_err(|e| e.error))); + Self::deposit_event(Event::Dispatched { + result: e.map(|_| ()).map_err(|e| e.error), + }); Ok(()) } @@ -276,7 +295,10 @@ pub mod module { ) .map_err(|_| Error::::FailedToSchedule)?; - Self::deposit_event(Event::Scheduled(pallets_origin, id)); + Self::deposit_event(Event::Scheduled { + origin: pallets_origin, + index: id, + }); Ok(()) } @@ -302,7 +324,11 @@ pub mod module { T::Scheduler::reschedule_named((&initial_origin, task_id).encode(), when) .map_err(|_| Error::::FailedToFastTrack)?; - Self::deposit_event(Event::FastTracked(*initial_origin, task_id, dispatch_at)); + Self::deposit_event(Event::FastTracked { + origin: *initial_origin, + index: task_id, + when: dispatch_at, + }); Ok(()) } @@ -325,7 +351,11 @@ pub mod module { let now = frame_system::Pallet::::block_number(); let dispatch_at = now.saturating_add(additional_delay); - Self::deposit_event(Event::Delayed(*initial_origin, task_id, dispatch_at)); + Self::deposit_event(Event::Delayed { + origin: *initial_origin, + index: task_id, + when: dispatch_at, + }); Ok(()) } @@ -339,7 +369,10 @@ pub mod module { T::AuthorityConfig::check_cancel_schedule(origin, &initial_origin)?; T::Scheduler::cancel_named((&initial_origin, task_id).encode()).map_err(|_| Error::::FailedToCancel)?; - Self::deposit_event(Event::Cancelled(*initial_origin, task_id)); + Self::deposit_event(Event::Cancelled { + origin: *initial_origin, + index: task_id, + }); Ok(()) } @@ -352,7 +385,7 @@ pub mod module { ensure_root(origin)?; let hash = T::Hashing::hash_of(&call); SavedCalls::::insert(hash, (call, caller.clone())); - Self::deposit_event(Event::AuthorizedCall(hash, caller)); + Self::deposit_event(Event::AuthorizedCall { hash, caller }); Ok(()) } @@ -373,7 +406,7 @@ pub mod module { ensure!(who == caller, Error::::CallNotAuthorized); } } - Self::deposit_event(Event::RemovedAuthorizedCall(hash)); + Self::deposit_event(Event::RemovedAuthorizedCall { hash }); Ok(()) }) } @@ -398,8 +431,10 @@ pub mod module { Error::::WrongCallWeightBound ); let result = call.dispatch(OriginFor::::root()); - Self::deposit_event(Event::TriggeredCallBy(hash, who)); - Self::deposit_event(Event::Dispatched(result.map(|_| ()).map_err(|e| e.error))); + Self::deposit_event(Event::TriggeredCallBy { hash, caller: who }); + Self::deposit_event(Event::Dispatched { + result: result.map(|_| ()).map_err(|e| e.error), + }); Ok(Pays::No.into()) }) } diff --git a/authority/src/tests.rs b/authority/src/tests.rs index a4b30f406..788ebff8c 100644 --- a/authority/src/tests.rs +++ b/authority/src/tests.rs @@ -75,13 +75,13 @@ fn schedule_dispatch_at_work() { true, Box::new(call.clone()) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 1, - ))); + index: 1, + })); run_to_block(2); System::assert_last_event(mock::Event::Scheduler(pallet_scheduler::Event::::Dispatched( @@ -98,10 +98,10 @@ fn schedule_dispatch_at_work() { false, Box::new(call) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::system(RawOrigin::Root), - 2, - ))); + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::system(RawOrigin::Root), + index: 2, + })); run_to_block(3); System::assert_last_event(mock::Event::Scheduler(pallet_scheduler::Event::::Dispatched( @@ -133,13 +133,13 @@ fn schedule_dispatch_after_work() { true, Box::new(call.clone()) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::Authority(DelayedOrigin { delay: 0, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 1, - ))); + index: 1, + })); run_to_block(2); System::assert_last_event(mock::Event::Scheduler(pallet_scheduler::Event::::Dispatched( @@ -156,10 +156,10 @@ fn schedule_dispatch_after_work() { false, Box::new(call) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::system(RawOrigin::Root), - 2, - ))); + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::system(RawOrigin::Root), + index: 2, + })); run_to_block(3); System::assert_last_event(mock::Event::Scheduler(pallet_scheduler::Event::::Dispatched( @@ -187,13 +187,13 @@ fn fast_track_scheduled_dispatch_work() { true, Box::new(call.clone()) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 0, - ))); + index: 0, + })); let schedule_origin = { let origin: ::Origin = Origin::root(); @@ -212,14 +212,14 @@ fn fast_track_scheduled_dispatch_work() { 0, DispatchTime::At(4), )); - System::assert_last_event(mock::Event::Authority(Event::FastTracked( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::FastTracked { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 0, - 4, - ))); + index: 0, + when: 4, + })); assert_ok!(Authority::schedule_dispatch( Origin::root(), @@ -228,10 +228,10 @@ fn fast_track_scheduled_dispatch_work() { false, Box::new(call) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::system(RawOrigin::Root), - 1, - ))); + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::system(RawOrigin::Root), + index: 1, + })); assert_ok!(Authority::fast_track_scheduled_dispatch( Origin::root(), @@ -239,11 +239,11 @@ fn fast_track_scheduled_dispatch_work() { 1, DispatchTime::At(4), )); - System::assert_last_event(mock::Event::Authority(Event::FastTracked( - OriginCaller::system(RawOrigin::Root), - 1, - 4, - ))); + System::assert_last_event(mock::Event::Authority(Event::FastTracked { + origin: OriginCaller::system(RawOrigin::Root), + index: 1, + when: 4, + })); }); } @@ -264,13 +264,13 @@ fn delay_scheduled_dispatch_work() { true, Box::new(call.clone()) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 0, - ))); + index: 0, + })); let schedule_origin = { let origin: ::Origin = Origin::root(); @@ -289,14 +289,14 @@ fn delay_scheduled_dispatch_work() { 0, 4, )); - System::assert_last_event(mock::Event::Authority(Event::Delayed( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Delayed { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 0, - 5, - ))); + index: 0, + when: 5, + })); assert_ok!(Authority::schedule_dispatch( Origin::root(), @@ -305,10 +305,10 @@ fn delay_scheduled_dispatch_work() { false, Box::new(call) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::system(RawOrigin::Root), - 1, - ))); + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::system(RawOrigin::Root), + index: 1, + })); assert_ok!(Authority::delay_scheduled_dispatch( Origin::root(), @@ -316,11 +316,11 @@ fn delay_scheduled_dispatch_work() { 1, 4, )); - System::assert_last_event(mock::Event::Authority(Event::Delayed( - OriginCaller::system(RawOrigin::Root), - 1, - 5, - ))); + System::assert_last_event(mock::Event::Authority(Event::Delayed { + origin: OriginCaller::system(RawOrigin::Root), + index: 1, + when: 5, + })); }); } @@ -340,13 +340,13 @@ fn cancel_scheduled_dispatch_work() { true, Box::new(call.clone()) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 0, - ))); + index: 0, + })); let schedule_origin = { let origin: ::Origin = Origin::root(); @@ -364,13 +364,13 @@ fn cancel_scheduled_dispatch_work() { Box::new(pallets_origin), 0 )); - System::assert_last_event(mock::Event::Authority(Event::Cancelled( - OriginCaller::Authority(DelayedOrigin { + System::assert_last_event(mock::Event::Authority(Event::Cancelled { + origin: OriginCaller::Authority(DelayedOrigin { delay: 1, origin: Box::new(OriginCaller::system(RawOrigin::Root)), }), - 0, - ))); + index: 0, + })); assert_ok!(Authority::schedule_dispatch( Origin::root(), @@ -379,20 +379,20 @@ fn cancel_scheduled_dispatch_work() { false, Box::new(call) )); - System::assert_last_event(mock::Event::Authority(Event::Scheduled( - OriginCaller::system(RawOrigin::Root), - 1, - ))); + System::assert_last_event(mock::Event::Authority(Event::Scheduled { + origin: OriginCaller::system(RawOrigin::Root), + index: 1, + })); assert_ok!(Authority::cancel_scheduled_dispatch( Origin::root(), Box::new(frame_system::RawOrigin::Root.into()), 1 )); - System::assert_last_event(mock::Event::Authority(Event::Cancelled( - OriginCaller::system(RawOrigin::Root), - 1, - ))); + System::assert_last_event(mock::Event::Authority(Event::Cancelled { + origin: OriginCaller::system(RawOrigin::Root), + index: 1, + })); }); } @@ -420,7 +420,7 @@ fn authorize_call_works() { // works without account assert_ok!(Authority::authorize_call(Origin::root(), Box::new(call.clone()), None)); assert_eq!(Authority::saved_calls(&hash), Some((call.clone(), None))); - System::assert_last_event(mock::Event::Authority(Event::AuthorizedCall(hash, None))); + System::assert_last_event(mock::Event::Authority(Event::AuthorizedCall { hash, caller: None })); // works with account assert_ok!(Authority::authorize_call( @@ -429,7 +429,7 @@ fn authorize_call_works() { Some(1) )); assert_eq!(Authority::saved_calls(&hash), Some((call.clone(), Some(1)))); - System::assert_last_event(mock::Event::Authority(Event::AuthorizedCall(hash, Some(1)))); + System::assert_last_event(mock::Event::Authority(Event::AuthorizedCall { hash, caller: Some(1) })); }); } @@ -463,8 +463,8 @@ fn trigger_call_works() { // works without caller assert_ok!(Authority::trigger_call(Origin::signed(1), hash, call_weight_bound)); assert_eq!(Authority::saved_calls(&hash), None); - System::assert_has_event(mock::Event::Authority(Event::TriggeredCallBy(hash, 1))); - System::assert_last_event(mock::Event::Authority(Event::Dispatched(Ok(())))); + System::assert_has_event(mock::Event::Authority(Event::TriggeredCallBy { hash, caller: 1 })); + System::assert_last_event(mock::Event::Authority(Event::Dispatched { result: Ok(()) })); // works with caller 1 assert_ok!(Authority::authorize_call( @@ -482,8 +482,8 @@ fn trigger_call_works() { // caller 1 triggering the call assert_ok!(Authority::trigger_call(Origin::signed(1), hash, call_weight_bound)); assert_eq!(Authority::saved_calls(&hash), None); - System::assert_has_event(mock::Event::Authority(Event::TriggeredCallBy(hash, 1))); - System::assert_last_event(mock::Event::Authority(Event::Dispatched(Ok(())))); + System::assert_has_event(mock::Event::Authority(Event::TriggeredCallBy { hash, caller: 1 })); + System::assert_last_event(mock::Event::Authority(Event::Dispatched { result: Ok(()) })); }); } diff --git a/currencies/src/lib.rs b/currencies/src/lib.rs index ed9438b3e..9c6c46992 100644 --- a/currencies/src/lib.rs +++ b/currencies/src/lib.rs @@ -112,14 +112,31 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// Currency transfer success. \[currency_id, from, to, amount\] - Transferred(CurrencyIdOf, T::AccountId, T::AccountId, BalanceOf), - /// Update balance success. \[currency_id, who, amount\] - BalanceUpdated(CurrencyIdOf, T::AccountId, AmountOf), - /// Deposit success. \[currency_id, who, amount\] - Deposited(CurrencyIdOf, T::AccountId, BalanceOf), - /// Withdraw success. \[currency_id, who, amount\] - Withdrawn(CurrencyIdOf, T::AccountId, BalanceOf), + /// Currency transfer success. + Transferred { + currency_id: CurrencyIdOf, + from: T::AccountId, + to: T::AccountId, + amount: BalanceOf, + }, + /// Update balance success. + BalanceUpdated { + currency_id: CurrencyIdOf, + who: T::AccountId, + amount: AmountOf, + }, + /// Deposit success. + Deposited { + currency_id: CurrencyIdOf, + who: T::AccountId, + amount: BalanceOf, + }, + /// Withdraw success. + Withdrawn { + currency_id: CurrencyIdOf, + who: T::AccountId, + amount: BalanceOf, + }, } #[pallet::pallet] @@ -161,7 +178,12 @@ pub mod module { let to = T::Lookup::lookup(dest)?; T::NativeCurrency::transfer(&from, &to, amount)?; - Self::deposit_event(Event::Transferred(T::GetNativeCurrencyId::get(), from, to, amount)); + Self::deposit_event(Event::Transferred { + currency_id: T::GetNativeCurrencyId::get(), + from, + to, + amount, + }); Ok(()) } @@ -241,7 +263,12 @@ impl MultiCurrency for Pallet { } else { T::MultiCurrency::transfer(currency_id, from, to, amount)?; } - Self::deposit_event(Event::Transferred(currency_id, from.clone(), to.clone(), amount)); + Self::deposit_event(Event::Transferred { + currency_id, + from: from.clone(), + to: to.clone(), + amount, + }); Ok(()) } @@ -254,7 +281,11 @@ impl MultiCurrency for Pallet { } else { T::MultiCurrency::deposit(currency_id, who, amount)?; } - Self::deposit_event(Event::Deposited(currency_id, who.clone(), amount)); + Self::deposit_event(Event::Deposited { + currency_id, + who: who.clone(), + amount, + }); Ok(()) } @@ -267,7 +298,11 @@ impl MultiCurrency for Pallet { } else { T::MultiCurrency::withdraw(currency_id, who, amount)?; } - Self::deposit_event(Event::Withdrawn(currency_id, who.clone(), amount)); + Self::deposit_event(Event::Withdrawn { + currency_id, + who: who.clone(), + amount, + }); Ok(()) } @@ -297,7 +332,11 @@ impl MultiCurrencyExtended for Pallet { } else { T::MultiCurrency::update_balance(currency_id, who, by_amount)?; } - Self::deposit_event(Event::BalanceUpdated(currency_id, who.clone(), by_amount)); + Self::deposit_event(Event::BalanceUpdated { + currency_id, + who: who.clone(), + amount: by_amount, + }); Ok(()) } } diff --git a/currencies/src/tests.rs b/currencies/src/tests.rs index f83edb7b5..5c391d64e 100644 --- a/currencies/src/tests.rs +++ b/currencies/src/tests.rs @@ -271,25 +271,43 @@ fn call_event_should_work() { assert_ok!(Currencies::transfer(Some(ALICE).into(), BOB, X_TOKEN_ID, 50)); assert_eq!(Currencies::free_balance(X_TOKEN_ID, &ALICE), 50); assert_eq!(Currencies::free_balance(X_TOKEN_ID, &BOB), 150); - System::assert_last_event(Event::Currencies(crate::Event::Transferred(X_TOKEN_ID, ALICE, BOB, 50))); + System::assert_last_event(Event::Currencies(crate::Event::Transferred { + currency_id: X_TOKEN_ID, + from: ALICE, + to: BOB, + amount: 50, + })); assert_ok!(>::transfer( X_TOKEN_ID, &ALICE, &BOB, 10 )); assert_eq!(Currencies::free_balance(X_TOKEN_ID, &ALICE), 40); assert_eq!(Currencies::free_balance(X_TOKEN_ID, &BOB), 160); - System::assert_last_event(Event::Currencies(crate::Event::Transferred(X_TOKEN_ID, ALICE, BOB, 10))); + System::assert_last_event(Event::Currencies(crate::Event::Transferred { + currency_id: X_TOKEN_ID, + from: ALICE, + to: BOB, + amount: 10, + })); assert_ok!(>::deposit( X_TOKEN_ID, &ALICE, 100 )); assert_eq!(Currencies::free_balance(X_TOKEN_ID, &ALICE), 140); - System::assert_last_event(Event::Currencies(crate::Event::Deposited(X_TOKEN_ID, ALICE, 100))); + System::assert_last_event(Event::Currencies(crate::Event::Deposited { + currency_id: X_TOKEN_ID, + who: ALICE, + amount: 100, + })); assert_ok!(>::withdraw( X_TOKEN_ID, &ALICE, 20 )); assert_eq!(Currencies::free_balance(X_TOKEN_ID, &ALICE), 120); - System::assert_last_event(Event::Currencies(crate::Event::Withdrawn(X_TOKEN_ID, ALICE, 20))); + System::assert_last_event(Event::Currencies(crate::Event::Withdrawn { + currency_id: X_TOKEN_ID, + who: ALICE, + amount: 20, + })); }); } diff --git a/gradually-update/src/lib.rs b/gradually-update/src/lib.rs index bbe0c45dc..240ffac88 100644 --- a/gradually-update/src/lib.rs +++ b/gradually-update/src/lib.rs @@ -109,12 +109,20 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// Gradually update added. [key, per_block, target_value] - GraduallyUpdateAdded(StorageKeyBytes, StorageValueBytes, StorageValueBytes), - /// Gradually update cancelled. [key] - GraduallyUpdateCancelled(StorageKeyBytes), - /// Gradually update applied. [block_number, key, target_value] - Updated(T::BlockNumber, StorageKeyBytes, StorageValueBytes), + /// Gradually update added. + GraduallyUpdateAdded { + key: StorageKeyBytes, + per_block: StorageValueBytes, + target_value: StorageValueBytes, + }, + /// Gradually update cancelled. + GraduallyUpdateCancelled { key: StorageKeyBytes }, + /// Gradually update applied. + Updated { + block_number: T::BlockNumber, + key: StorageKeyBytes, + target_value: StorageValueBytes, + }, } /// All the on-going updates @@ -182,11 +190,11 @@ pub mod module { Ok(()) })?; - Self::deposit_event(Event::GraduallyUpdateAdded( - update.key, - update.per_block, - update.target_value, - )); + Self::deposit_event(Event::GraduallyUpdateAdded { + key: update.key, + per_block: update.per_block, + target_value: update.target_value, + }); Ok(()) } @@ -204,7 +212,7 @@ pub mod module { Ok(()) })?; - Self::deposit_event(Event::GraduallyUpdateCancelled(key)); + Self::deposit_event(Event::GraduallyUpdateCancelled { key }); Ok(()) } } @@ -253,7 +261,11 @@ impl Pallet { let bounded_value: StorageValueBytes = value.to_vec().try_into().unwrap(); - Self::deposit_event(Event::Updated(now, update.key.clone(), bounded_value)); + Self::deposit_event(Event::Updated { + block_number: now, + key: update.key.clone(), + target_value: bounded_value, + }); keep }); diff --git a/gradually-update/src/tests.rs b/gradually-update/src/tests.rs index e5e8d630e..5e07adbc8 100644 --- a/gradually-update/src/tests.rs +++ b/gradually-update/src/tests.rs @@ -30,11 +30,11 @@ fn gradually_update_should_work() { per_block: vec![1].try_into().unwrap(), }; assert_ok!(GraduallyUpdateModule::gradually_update(Origin::root(), update.clone())); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateAdded( - update.key, - update.per_block, - update.target_value, - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateAdded { + key: update.key, + per_block: update.per_block, + target_value: update.target_value, + })); }); } @@ -88,19 +88,19 @@ fn cancel_gradually_update_should_work() { per_block: vec![1].try_into().unwrap(), }; assert_ok!(GraduallyUpdateModule::gradually_update(Origin::root(), update.clone())); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateAdded( - update.key.clone(), - update.per_block, - update.target_value, - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateAdded { + key: update.key.clone(), + per_block: update.per_block, + target_value: update.target_value, + })); assert_ok!(GraduallyUpdateModule::cancel_gradually_update( Origin::root(), update.key.clone() )); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateCancelled( - update.key, - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::GraduallyUpdateCancelled { + key: update.key, + })); }); } @@ -142,11 +142,11 @@ fn add_on_finalize_should_work() { GraduallyUpdateModule::on_finalize(10); assert_eq!(storage_get(&update.key), vec![10]); println!("Length {}", System::events().len()); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated( - 10, - update.key.clone(), - vec![10].try_into().unwrap(), - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated { + block_number: 10, + key: update.key.clone(), + target_value: vec![10].try_into().unwrap(), + })); assert_eq!(System::events().len(), 2); GraduallyUpdateModule::on_finalize(15); @@ -155,20 +155,20 @@ fn add_on_finalize_should_work() { GraduallyUpdateModule::on_finalize(20); assert_eq!(storage_get(&update.key), vec![20]); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated( - 20, - update.key.clone(), - vec![20].try_into().unwrap(), - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated { + block_number: 20, + key: update.key.clone(), + target_value: vec![20].try_into().unwrap(), + })); assert_eq!(System::events().len(), 3); GraduallyUpdateModule::on_finalize(40); assert_eq!(storage_get(&update.key), vec![30]); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated( - 40, - update.key, - vec![30].try_into().unwrap(), - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated { + block_number: 40, + key: update.key, + target_value: vec![30].try_into().unwrap(), + })); }); } @@ -189,11 +189,11 @@ fn sub_on_finalize_should_work() { GraduallyUpdateModule::on_finalize(10); assert_eq!(storage_get(&update.key), vec![20]); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated( - 10, - update.key.clone(), - vec![20].try_into().unwrap(), - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated { + block_number: 10, + key: update.key.clone(), + target_value: vec![20].try_into().unwrap(), + })); assert_eq!(System::events().len(), 2); GraduallyUpdateModule::on_finalize(15); @@ -202,20 +202,20 @@ fn sub_on_finalize_should_work() { GraduallyUpdateModule::on_finalize(20); assert_eq!(storage_get(&update.key), vec![10]); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated( - 20, - update.key.clone(), - vec![10].try_into().unwrap(), - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated { + block_number: 20, + key: update.key.clone(), + target_value: vec![10].try_into().unwrap(), + })); assert_eq!(System::events().len(), 3); GraduallyUpdateModule::on_finalize(40); assert_eq!(storage_get(&update.key), vec![5]); - System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated( - 40, - update.key, - vec![5].try_into().unwrap(), - ))); + System::assert_last_event(Event::GraduallyUpdateModule(crate::Event::Updated { + block_number: 40, + key: update.key, + target_value: vec![5].try_into().unwrap(), + })); }); } diff --git a/oracle/src/lib.rs b/oracle/src/lib.rs index 0a037dea7..7a4bd2281 100644 --- a/oracle/src/lib.rs +++ b/oracle/src/lib.rs @@ -106,8 +106,11 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event, I: 'static = ()> { - /// New feed data is submitted. [sender, values] - NewFeedData(T::AccountId, Vec<(T::OracleKey, T::OracleValue)>), + /// New feed data is submitted. + NewFeedData { + sender: T::AccountId, + values: Vec<(T::OracleKey, T::OracleValue)>, + }, } /// Raw values for each oracle operators @@ -246,7 +249,7 @@ impl, I: 'static> Pallet { T::OnNewData::on_new_data(&who, key, value); } - Self::deposit_event(Event::NewFeedData(who, values)); + Self::deposit_event(Event::NewFeedData { sender: who, values }); Ok(()) } } diff --git a/oracle/src/tests.rs b/oracle/src/tests.rs index 928e34b89..79ecfd9c1 100644 --- a/oracle/src/tests.rs +++ b/oracle/src/tests.rs @@ -21,10 +21,10 @@ fn should_feed_values_from_member() { .pays_fee, Pays::No ); - System::assert_last_event(Event::ModuleOracle(crate::Event::NewFeedData( - 1, - vec![(50, 1000), (51, 900), (52, 800)], - ))); + System::assert_last_event(Event::ModuleOracle(crate::Event::NewFeedData { + sender: 1, + values: vec![(50, 1000), (51, 900), (52, 800)], + })); assert_eq!( ModuleOracle::raw_values(&account_id, &50), diff --git a/tokens/src/lib.rs b/tokens/src/lib.rs index ff330c157..18bc489e8 100644 --- a/tokens/src/lib.rs +++ b/tokens/src/lib.rs @@ -229,27 +229,54 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// An account was created with some free balance. \[currency_id, - /// account, free_balance\] - Endowed(T::CurrencyId, T::AccountId, T::Balance), + /// An account was created with some free balance. + Endowed { + currency_id: T::CurrencyId, + who: T::AccountId, + amount: T::Balance, + }, /// An account was removed whose balance was non-zero but below - /// ExistentialDeposit, resulting in an outright loss. \[currency_id, - /// account, balance\] - DustLost(T::CurrencyId, T::AccountId, T::Balance), - /// Transfer succeeded. \[currency_id, from, to, value\] - Transfer(T::CurrencyId, T::AccountId, T::AccountId, T::Balance), + /// ExistentialDeposit, resulting in an outright loss. + DustLost { + currency_id: T::CurrencyId, + who: T::AccountId, + amount: T::Balance, + }, + /// Transfer succeeded. + Transfer { + currency_id: T::CurrencyId, + from: T::AccountId, + to: T::AccountId, + amount: T::Balance, + }, /// Some balance was reserved (moved from free to reserved). - /// \[currency_id, who, value\] - Reserved(T::CurrencyId, T::AccountId, T::Balance), + Reserved { + currency_id: T::CurrencyId, + who: T::AccountId, + amount: T::Balance, + }, /// Some balance was unreserved (moved from reserved to free). - /// \[currency_id, who, value\] - Unreserved(T::CurrencyId, T::AccountId, T::Balance), + Unreserved { + currency_id: T::CurrencyId, + who: T::AccountId, + amount: T::Balance, + }, /// Some reserved balance was repatriated (moved from reserved to /// another account). - /// \[currency_id, from, to, amount_actually_moved, status\] - RepatriatedReserve(T::CurrencyId, T::AccountId, T::AccountId, T::Balance, BalanceStatus), - /// A balance was set by root. \[who, free, reserved\] - BalanceSet(T::CurrencyId, T::AccountId, T::Balance, T::Balance), + RepatriatedReserve { + currency_id: T::CurrencyId, + from: T::AccountId, + to: T::AccountId, + amount: T::Balance, + status: BalanceStatus, + }, + /// A balance was set by root. + BalanceSet { + currency_id: T::CurrencyId, + who: T::AccountId, + free: T::Balance, + reserved: T::Balance, + }, } /// The total issuance of a token type. @@ -366,7 +393,12 @@ pub mod module { let to = T::Lookup::lookup(dest)?; Self::do_transfer(currency_id, &from, &to, amount, ExistenceRequirement::AllowDeath)?; - Self::deposit_event(Event::Transfer(currency_id, from, to, amount)); + Self::deposit_event(Event::Transfer { + currency_id, + from, + to, + amount, + }); Ok(()) } @@ -402,7 +434,12 @@ pub mod module { >::reducible_balance(currency_id, &from, keep_alive); >::transfer(currency_id, &from, &to, reducible_balance, keep_alive)?; - Self::deposit_event(Event::Transfer(currency_id, from, to, reducible_balance)); + Self::deposit_event(Event::Transfer { + currency_id, + from, + to, + amount: reducible_balance, + }); Ok(()) } @@ -428,7 +465,12 @@ pub mod module { let to = T::Lookup::lookup(dest)?; Self::do_transfer(currency_id, &from, &to, amount, ExistenceRequirement::KeepAlive)?; - Self::deposit_event(Event::Transfer(currency_id, from, to, amount)); + Self::deposit_event(Event::Transfer { + currency_id, + from, + to, + amount, + }); Ok(().into()) } @@ -454,7 +496,12 @@ pub mod module { let to = T::Lookup::lookup(dest)?; Self::do_transfer(currency_id, &from, &to, amount, ExistenceRequirement::AllowDeath)?; - Self::deposit_event(Event::Transfer(currency_id, from, to, amount)); + Self::deposit_event(Event::Transfer { + currency_id, + from, + to, + amount, + }); Ok(()) } @@ -506,7 +553,12 @@ pub mod module { })?; } - Self::deposit_event(Event::BalanceSet(currency_id, who.clone(), new_free, new_reserved)); + Self::deposit_event(Event::BalanceSet { + currency_id, + who: who.clone(), + free: new_free, + reserved: new_reserved, + }); Ok(()) }) } @@ -655,14 +707,22 @@ impl Pallet { } if let Some(endowed) = maybe_endowed { - Self::deposit_event(Event::Endowed(currency_id, who.clone(), endowed)); + Self::deposit_event(Event::Endowed { + currency_id, + who: who.clone(), + amount: endowed, + }); } if let Some(dust_amount) = maybe_dust { // `OnDust` maybe get/set storage `Accounts` of `who`, trigger handler here // to avoid some unexpected errors. T::OnDust::on_dust(who, currency_id, dust_amount); - Self::deposit_event(Event::DustLost(currency_id, who.clone(), dust_amount)); + Self::deposit_event(Event::DustLost { + currency_id, + who: who.clone(), + amount: dust_amount, + }); } result @@ -1135,7 +1195,11 @@ impl MultiReservableCurrency for Pallet { Self::mutate_account(who, currency_id, |account, _| { account.free -= value; account.reserved += value; - Self::deposit_event(Event::Reserved(currency_id, who.clone(), value)); + Self::deposit_event(Event::Reserved { + currency_id, + who: who.clone(), + amount: value, + }); Ok(()) }) } @@ -1153,7 +1217,11 @@ impl MultiReservableCurrency for Pallet { let actual = account.reserved.min(value); account.reserved -= actual; account.free += actual; - Self::deposit_event(Event::Unreserved(currency_id, who.clone(), actual)); + Self::deposit_event(Event::Unreserved { + currency_id, + who: who.clone(), + amount: actual, + }); value - actual }) } @@ -1195,13 +1263,13 @@ impl MultiReservableCurrency for Pallet { } } Self::set_reserved_balance(currency_id, slashed, from_account.reserved - actual); - Self::deposit_event(Event::::RepatriatedReserve( + Self::deposit_event(Event::::RepatriatedReserve { currency_id, - slashed.clone(), - beneficiary.clone(), - actual, + from: slashed.clone(), + to: beneficiary.clone(), + amount: actual, status, - )); + }); Ok(value - actual) } } diff --git a/tokens/src/tests.rs b/tokens/src/tests.rs index 60a1ce5d0..5fb3a37ef 100644 --- a/tokens/src/tests.rs +++ b/tokens/src/tests.rs @@ -36,7 +36,12 @@ fn transfer_should_work() { .build() .execute_with(|| { assert_ok!(Tokens::transfer(Some(ALICE).into(), BOB, DOT, 50)); - System::assert_last_event(Event::Tokens(crate::Event::Transfer(DOT, ALICE, BOB, 50))); + System::assert_last_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: ALICE, + to: BOB, + amount: 50, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 50); assert_eq!(Tokens::free_balance(DOT, &BOB), 150); assert_eq!(Tokens::total_issuance(DOT), 200); @@ -77,7 +82,12 @@ fn transfer_keep_alive_should_work() { ); assert_ok!(Tokens::transfer_keep_alive(Some(ALICE).into(), BOB, DOT, 98)); - System::assert_last_event(Event::Tokens(crate::Event::Transfer(DOT, ALICE, BOB, 98))); + System::assert_last_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: ALICE, + to: BOB, + amount: 98, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 2); assert_eq!(Tokens::free_balance(DOT, &BOB), 198); }); @@ -91,14 +101,24 @@ fn transfer_all_keep_alive_should_work() { .execute_with(|| { assert_eq!(Tokens::free_balance(DOT, &ALICE), 100); assert_ok!(Tokens::transfer_all(Some(ALICE).into(), CHARLIE, DOT, true)); - System::assert_has_event(Event::Tokens(crate::Event::Transfer(DOT, ALICE, CHARLIE, 98))); + System::assert_has_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: ALICE, + to: CHARLIE, + amount: 98, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 2); assert_ok!(Tokens::set_lock(ID_1, DOT, &BOB, 50)); assert_eq!(Tokens::accounts(&BOB, DOT).frozen, 50); assert_eq!(Tokens::free_balance(DOT, &BOB), 100); assert_ok!(Tokens::transfer_all(Some(BOB).into(), CHARLIE, DOT, true)); - System::assert_has_event(Event::Tokens(crate::Event::Transfer(DOT, BOB, CHARLIE, 50))); + System::assert_has_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: BOB, + to: CHARLIE, + amount: 50, + })); }); } @@ -111,7 +131,12 @@ fn transfer_all_allow_death_should_work() { assert!(Accounts::::contains_key(ALICE, DOT)); assert_eq!(Tokens::free_balance(DOT, &ALICE), 100); assert_ok!(Tokens::transfer_all(Some(ALICE).into(), CHARLIE, DOT, false)); - System::assert_last_event(Event::Tokens(crate::Event::Transfer(DOT, ALICE, CHARLIE, 100))); + System::assert_last_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: ALICE, + to: CHARLIE, + amount: 100, + })); assert!(!Accounts::::contains_key(ALICE, DOT)); assert_eq!(Tokens::free_balance(DOT, &ALICE), 0); @@ -119,7 +144,12 @@ fn transfer_all_allow_death_should_work() { assert_eq!(Tokens::accounts(&BOB, DOT).frozen, 50); assert_eq!(Tokens::free_balance(DOT, &BOB), 100); assert_ok!(Tokens::transfer_all(Some(BOB).into(), CHARLIE, DOT, false)); - System::assert_last_event(Event::Tokens(crate::Event::Transfer(DOT, BOB, CHARLIE, 50))); + System::assert_last_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: BOB, + to: CHARLIE, + amount: 50, + })); }); } @@ -139,7 +169,12 @@ fn force_transfer_should_work() { // imply AllowDeath assert_ok!(Tokens::force_transfer(RawOrigin::Root.into(), ALICE, BOB, DOT, 100)); - System::assert_last_event(Event::Tokens(crate::Event::Transfer(DOT, ALICE, BOB, 100))); + System::assert_last_event(Event::Tokens(crate::Event::Transfer { + currency_id: DOT, + from: ALICE, + to: BOB, + amount: 100, + })); assert!(!Accounts::::contains_key(ALICE, DOT)); assert_eq!(Tokens::free_balance(DOT, &ALICE), 0); assert_eq!(Tokens::free_balance(DOT, &BOB), 200); @@ -179,7 +214,12 @@ fn set_balance_should_work() { assert_eq!(Tokens::total_issuance(DOT), 200); assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), ALICE, DOT, 200, 100)); - System::assert_has_event(Event::Tokens(crate::Event::BalanceSet(DOT, ALICE, 200, 100))); + System::assert_has_event(Event::Tokens(crate::Event::BalanceSet { + currency_id: DOT, + who: ALICE, + free: 200, + reserved: 100, + })); assert!(Accounts::::contains_key(ALICE, DOT)); assert_eq!(Tokens::free_balance(DOT, &ALICE), 200); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 100); @@ -190,7 +230,12 @@ fn set_balance_should_work() { assert_eq!(Tokens::reserved_balance(DOT, &BOB), 0); assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB, DOT, 0, 0)); - System::assert_has_event(Event::Tokens(crate::Event::BalanceSet(DOT, BOB, 0, 0))); + System::assert_has_event(Event::Tokens(crate::Event::BalanceSet { + currency_id: DOT, + who: BOB, + free: 0, + reserved: 0, + })); assert!(!Accounts::::contains_key(BOB, DOT)); assert_eq!(Tokens::free_balance(DOT, &BOB), 0); assert_eq!(Tokens::reserved_balance(DOT, &BOB), 0); @@ -202,7 +247,12 @@ fn set_balance_should_work() { // below ED, assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), CHARLIE, DOT, 1, 0)); - System::assert_has_event(Event::Tokens(crate::Event::BalanceSet(DOT, CHARLIE, 0, 0))); + System::assert_has_event(Event::Tokens(crate::Event::BalanceSet { + currency_id: DOT, + who: CHARLIE, + free: 0, + reserved: 0, + })); assert!(!Accounts::::contains_key(CHARLIE, DOT)); assert_eq!(Tokens::free_balance(DOT, &CHARLIE), 0); assert_eq!(Tokens::reserved_balance(DOT, &CHARLIE), 0); @@ -946,7 +996,11 @@ fn endowed_account_work() { assert_eq!(System::providers(&ALICE), 0); assert!(!Accounts::::contains_key(ALICE, DOT)); Tokens::set_free_balance(DOT, &ALICE, 100); - System::assert_last_event(Event::Tokens(crate::Event::Endowed(DOT, ALICE, 100))); + System::assert_last_event(Event::Tokens(crate::Event::Endowed { + currency_id: DOT, + who: ALICE, + amount: 100, + })); assert_eq!(System::providers(&ALICE), 1); assert!(Accounts::::contains_key(ALICE, DOT)); }); @@ -1026,7 +1080,11 @@ fn dust_removal_work() { assert_eq!(Tokens::free_balance(DOT, &ALICE), 100); assert_eq!(Tokens::free_balance(DOT, &DustReceiver::get()), 0); Tokens::set_free_balance(DOT, &ALICE, 1); - System::assert_last_event(Event::Tokens(crate::Event::DustLost(DOT, ALICE, 1))); + System::assert_last_event(Event::Tokens(crate::Event::DustLost { + currency_id: DOT, + who: ALICE, + amount: 1, + })); assert_eq!(System::providers(&ALICE), 0); assert!(!Accounts::::contains_key(ALICE, DOT)); assert_eq!(Tokens::free_balance(DOT, &ALICE), 0); @@ -1041,7 +1099,11 @@ fn dust_removal_work() { assert!(Accounts::::contains_key(DAVE, DOT)); assert_eq!(System::providers(&DAVE), 1); assert_eq!(Tokens::free_balance(DOT, &DAVE), 1); - System::assert_last_event(Event::Tokens(crate::Event::Endowed(DOT, DAVE, 1))); + System::assert_last_event(Event::Tokens(crate::Event::Endowed { + currency_id: DOT, + who: DAVE, + amount: 1, + })); }); } @@ -1056,7 +1118,11 @@ fn account_survive_due_to_dust_transfer_failure() { assert!(!Accounts::::contains_key(ALICE, DOT)); Tokens::set_reserved_balance(DOT, &ALICE, 1); - System::assert_last_event(Event::Tokens(crate::Event::DustLost(DOT, ALICE, 1))); + System::assert_last_event(Event::Tokens(crate::Event::DustLost { + currency_id: DOT, + who: ALICE, + amount: 1, + })); assert_eq!(Tokens::free_balance(DOT, &dust_account), 0); assert_eq!(Tokens::total_balance(DOT, &ALICE), 1); assert_eq!(System::providers(&ALICE), 1); @@ -1259,7 +1325,11 @@ fn multi_reservable_currency_reserve_work() { assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 0); assert_eq!(Tokens::total_balance(DOT, &ALICE), 100); assert_ok!(Tokens::reserve(DOT, &ALICE, 50)); - System::assert_last_event(Event::Tokens(crate::Event::Reserved(DOT, ALICE, 50))); + System::assert_last_event(Event::Tokens(crate::Event::Reserved { + currency_id: DOT, + who: ALICE, + amount: 50, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 50); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 50); assert_eq!(Tokens::total_balance(DOT, &ALICE), 100); @@ -1269,9 +1339,14 @@ fn multi_reservable_currency_reserve_work() { assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 100); assert_eq!(Tokens::total_balance(DOT, &ALICE), 100); // ensure will not trigger Endowed event - assert!(System::events() - .iter() - .all(|record| !matches!(record.event, Event::Tokens(crate::Event::Endowed(DOT, ALICE, _))))); + assert!(System::events().iter().all(|record| !matches!( + record.event, + Event::Tokens(crate::Event::Endowed { + currency_id: DOT, + who: ALICE, + amount: _ + }) + ))); }); } @@ -1285,23 +1360,44 @@ fn multi_reservable_currency_unreserve_work() { assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 0); assert_eq!(Tokens::unreserve(DOT, &ALICE, 0), 0); assert_eq!(Tokens::unreserve(DOT, &ALICE, 50), 50); - System::assert_last_event(Event::Tokens(crate::Event::Unreserved(DOT, ALICE, 0))); + System::assert_last_event(Event::Tokens(crate::Event::Unreserved { + currency_id: DOT, + who: ALICE, + amount: 0, + })); assert_ok!(Tokens::reserve(DOT, &ALICE, 30)); - System::assert_last_event(Event::Tokens(crate::Event::Reserved(DOT, ALICE, 30))); + System::assert_last_event(Event::Tokens(crate::Event::Reserved { + currency_id: DOT, + who: ALICE, + amount: 30, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 70); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 30); assert_eq!(Tokens::unreserve(DOT, &ALICE, 15), 0); - System::assert_last_event(Event::Tokens(crate::Event::Unreserved(DOT, ALICE, 15))); + System::assert_last_event(Event::Tokens(crate::Event::Unreserved { + currency_id: DOT, + who: ALICE, + amount: 15, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 85); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 15); assert_eq!(Tokens::unreserve(DOT, &ALICE, 30), 15); - System::assert_last_event(Event::Tokens(crate::Event::Unreserved(DOT, ALICE, 15))); + System::assert_last_event(Event::Tokens(crate::Event::Unreserved { + currency_id: DOT, + who: ALICE, + amount: 15, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 100); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 0); // ensure will not trigger Endowed event - assert!(System::events() - .iter() - .all(|record| !matches!(record.event, Event::Tokens(crate::Event::Endowed(DOT, ALICE, _))))); + assert!(System::events().iter().all(|record| !matches!( + record.event, + Event::Tokens(crate::Event::Endowed { + currency_id: DOT, + who: ALICE, + amount: _ + }) + ))); }); } @@ -1322,7 +1418,11 @@ fn multi_reservable_currency_repatriate_reserved_work() { Ok(50) ); // Repatriating from and to the same account, fund is `unreserved`. - System::assert_last_event(Event::Tokens(crate::Event::Unreserved(DOT, ALICE, 0))); + System::assert_last_event(Event::Tokens(crate::Event::Unreserved { + currency_id: DOT, + who: ALICE, + amount: 0, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 100); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 0); @@ -1344,13 +1444,13 @@ fn multi_reservable_currency_repatriate_reserved_work() { Tokens::repatriate_reserved(DOT, &BOB, &ALICE, 30, BalanceStatus::Reserved), Ok(0) ); - System::assert_last_event(Event::Tokens(crate::Event::RepatriatedReserve( - DOT, - BOB, - ALICE, - 30, - BalanceStatus::Reserved, - ))); + System::assert_last_event(Event::Tokens(crate::Event::RepatriatedReserve { + currency_id: DOT, + from: BOB, + to: ALICE, + amount: 30, + status: BalanceStatus::Reserved, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 100); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 30); @@ -1363,13 +1463,13 @@ fn multi_reservable_currency_repatriate_reserved_work() { ); // Actual amount repatriated is 20. - System::assert_last_event(Event::Tokens(crate::Event::RepatriatedReserve( - DOT, - BOB, - ALICE, - 20, - BalanceStatus::Free, - ))); + System::assert_last_event(Event::Tokens(crate::Event::RepatriatedReserve { + currency_id: DOT, + from: BOB, + to: ALICE, + amount: 20, + status: BalanceStatus::Free, + })); assert_eq!(Tokens::free_balance(DOT, &ALICE), 120); assert_eq!(Tokens::reserved_balance(DOT, &ALICE), 30); diff --git a/unknown-tokens/src/lib.rs b/unknown-tokens/src/lib.rs index da0a04d32..ff081848c 100644 --- a/unknown-tokens/src/lib.rs +++ b/unknown-tokens/src/lib.rs @@ -24,10 +24,10 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// Deposit success. [asset, to] - Deposited(MultiAsset, MultiLocation), - /// Withdraw success. [asset, from] - Withdrawn(MultiAsset, MultiLocation), + /// Deposit success. + Deposited { asset: MultiAsset, who: MultiLocation }, + /// Withdraw success. + Withdrawn { asset: MultiAsset, who: MultiLocation }, } #[pallet::error] @@ -88,7 +88,10 @@ impl UnknownAsset for Pallet { _ => Err(Error::::UnhandledAsset.into()), }?; - Self::deposit_event(Event::Deposited(asset.clone(), to.clone())); + Self::deposit_event(Event::Deposited { + asset: asset.clone(), + who: to.clone(), + }); Ok(()) } @@ -112,7 +115,10 @@ impl UnknownAsset for Pallet { _ => Err(Error::::UnhandledAsset.into()), }?; - Self::deposit_event(Event::Withdrawn(asset.clone(), from.clone())); + Self::deposit_event(Event::Withdrawn { + asset: asset.clone(), + who: from.clone(), + }); Ok(()) } diff --git a/unknown-tokens/src/tests.rs b/unknown-tokens/src/tests.rs index a5d3704db..5a8fefc75 100644 --- a/unknown-tokens/src/tests.rs +++ b/unknown-tokens/src/tests.rs @@ -31,7 +31,10 @@ fn deposit_concrete_fungible_asset_works() { UnknownTokens::concrete_fungible_balances(&MOCK_RECIPIENT, &MOCK_CONCRETE_FUNGIBLE_ID), 3 ); - System::assert_last_event(Event::UnknownTokens(crate::Event::Deposited(asset, MOCK_RECIPIENT))); + System::assert_last_event(Event::UnknownTokens(crate::Event::Deposited { + asset, + who: MOCK_RECIPIENT, + })); // overflow case let max_asset = concrete_fungible(u128::max_value()); @@ -51,7 +54,10 @@ fn deposit_abstract_fungible_asset() { UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id()), 3 ); - System::assert_last_event(Event::UnknownTokens(crate::Event::Deposited(asset, MOCK_RECIPIENT))); + System::assert_last_event(Event::UnknownTokens(crate::Event::Deposited { + asset, + who: MOCK_RECIPIENT, + })); // overflow case let max_asset = abstract_fungible(u128::max_value()); @@ -93,10 +99,10 @@ fn withdraw_concrete_fungible_asset_works() { UnknownTokens::concrete_fungible_balances(&MOCK_RECIPIENT, &MOCK_CONCRETE_FUNGIBLE_ID), 0 ); - System::assert_last_event(Event::UnknownTokens(crate::Event::Withdrawn( - asset.clone(), - MOCK_RECIPIENT, - ))); + System::assert_last_event(Event::UnknownTokens(crate::Event::Withdrawn { + asset: asset.clone(), + who: MOCK_RECIPIENT, + })); // balance too low case assert_err!( @@ -117,10 +123,10 @@ fn withdraw_abstract_fungible_asset_works() { UnknownTokens::abstract_fungible_balances(&MOCK_RECIPIENT, &mock_abstract_fungible_id()), 0 ); - System::assert_last_event(Event::UnknownTokens(crate::Event::Withdrawn( - asset.clone(), - MOCK_RECIPIENT, - ))); + System::assert_last_event(Event::UnknownTokens(crate::Event::Withdrawn { + asset: asset.clone(), + who: MOCK_RECIPIENT, + })); // balance too low case assert_err!( diff --git a/vesting/src/lib.rs b/vesting/src/lib.rs index 0da83064f..b14ffe3e2 100644 --- a/vesting/src/lib.rs +++ b/vesting/src/lib.rs @@ -161,12 +161,16 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(fn deposit_event)] pub enum Event { - /// Added new vesting schedule. \[from, to, vesting_schedule\] - VestingScheduleAdded(T::AccountId, T::AccountId, VestingScheduleOf), - /// Claimed vesting. \[who, locked_amount\] - Claimed(T::AccountId, BalanceOf), - /// Updated vesting schedules. \[who\] - VestingSchedulesUpdated(T::AccountId), + /// Added new vesting schedule. + VestingScheduleAdded { + from: T::AccountId, + to: T::AccountId, + vesting_schedule: VestingScheduleOf, + }, + /// Claimed vesting. + Claimed { who: T::AccountId, amount: BalanceOf }, + /// Updated vesting schedules. + VestingSchedulesUpdated { who: T::AccountId }, } /// Vesting schedules of an account. @@ -241,7 +245,10 @@ pub mod module { let who = ensure_signed(origin)?; let locked_amount = Self::do_claim(&who); - Self::deposit_event(Event::Claimed(who, locked_amount)); + Self::deposit_event(Event::Claimed { + who, + amount: locked_amount, + }); Ok(()) } @@ -255,7 +262,11 @@ pub mod module { let to = T::Lookup::lookup(dest)?; Self::do_vested_transfer(&from, &to, schedule.clone())?; - Self::deposit_event(Event::VestingScheduleAdded(from, to, schedule)); + Self::deposit_event(Event::VestingScheduleAdded { + from, + to, + vesting_schedule: schedule, + }); Ok(()) } @@ -270,7 +281,7 @@ pub mod module { let account = T::Lookup::lookup(who)?; Self::do_update_vesting_schedules(&account, vesting_schedules)?; - Self::deposit_event(Event::VestingSchedulesUpdated(account)); + Self::deposit_event(Event::VestingSchedulesUpdated { who: account }); Ok(()) } @@ -280,7 +291,10 @@ pub mod module { let who = T::Lookup::lookup(dest)?; let locked_amount = Self::do_claim(&who); - Self::deposit_event(Event::Claimed(who, locked_amount)); + Self::deposit_event(Event::Claimed { + who, + amount: locked_amount, + }); Ok(()) } } diff --git a/vesting/src/tests.rs b/vesting/src/tests.rs index 60aa6b5ec..7c25cefdb 100644 --- a/vesting/src/tests.rs +++ b/vesting/src/tests.rs @@ -74,7 +74,11 @@ fn vested_transfer_works() { }; assert_ok!(Vesting::vested_transfer(Origin::signed(ALICE), BOB, schedule.clone())); assert_eq!(Vesting::vesting_schedules(&BOB), vec![schedule.clone()]); - System::assert_last_event(Event::Vesting(crate::Event::VestingScheduleAdded(ALICE, BOB, schedule))); + System::assert_last_event(Event::Vesting(crate::Event::VestingScheduleAdded { + from: ALICE, + to: BOB, + vesting_schedule: schedule, + })); }); } diff --git a/xcm/src/lib.rs b/xcm/src/lib.rs index 23f47d9da..441874772 100644 --- a/xcm/src/lib.rs +++ b/xcm/src/lib.rs @@ -31,7 +31,7 @@ pub mod module { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// XCM message sent. \[to, message\] - Sent(MultiLocation, Xcm<()>), + Sent { to: MultiLocation, message: Xcm<()> }, } #[pallet::error] @@ -64,7 +64,7 @@ pub mod module { SendError::CannotReachDestination(..) => Error::::Unreachable, _ => Error::::SendFailure, })?; - Self::deposit_event(Event::Sent(dest, message)); + Self::deposit_event(Event::Sent { to: dest, message }); Ok(()) } } diff --git a/xtokens/src/lib.rs b/xtokens/src/lib.rs index 86808c47b..6d2c61f17 100644 --- a/xtokens/src/lib.rs +++ b/xtokens/src/lib.rs @@ -103,14 +103,34 @@ pub mod module { #[pallet::event] #[pallet::generate_deposit(fn deposit_event)] pub enum Event { - /// Transferred. \[sender, currency_id, amount, dest\] - Transferred(T::AccountId, T::CurrencyId, T::Balance, MultiLocation), - /// Transferred with fee. \[sender, currency_id, amount, fee, dest\] - TransferredWithFee(T::AccountId, T::CurrencyId, T::Balance, T::Balance, MultiLocation), - /// Transferred `MultiAsset`. \[sender, asset, dest\] - TransferredMultiAsset(T::AccountId, MultiAsset, MultiLocation), - /// Transferred `MultiAsset` with fee. \[sender, asset, fee, dest\] - TransferredMultiAssetWithFee(T::AccountId, MultiAsset, MultiAsset, MultiLocation), + /// Transferred. + Transferred { + sender: T::AccountId, + currency_id: T::CurrencyId, + amount: T::Balance, + dest: MultiLocation, + }, + /// Transferred with fee. + TransferredWithFee { + sender: T::AccountId, + currency_id: T::CurrencyId, + amount: T::Balance, + fee: T::Balance, + dest: MultiLocation, + }, + /// Transferred `MultiAsset`. + TransferredMultiAsset { + sender: T::AccountId, + asset: MultiAsset, + dest: MultiLocation, + }, + /// Transferred `MultiAsset` with fee. + TransferredMultiAssetWithFee { + sender: T::AccountId, + asset: MultiAsset, + fee: MultiAsset, + dest: MultiLocation, + }, } #[pallet::error] @@ -305,7 +325,12 @@ pub mod module { let asset = (location, amount.into()).into(); Self::do_transfer_multiasset(who.clone(), asset, dest.clone(), dest_weight, false)?; - Self::deposit_event(Event::::Transferred(who, currency_id, amount, dest)); + Self::deposit_event(Event::::Transferred { + sender: who, + currency_id, + amount, + dest, + }); Ok(()) } @@ -324,7 +349,13 @@ pub mod module { let fee_asset: MultiAsset = (location, fee.into()).into(); Self::do_transfer_multiasset_with_fee(who.clone(), asset, fee_asset, dest.clone(), dest_weight, false)?; - Self::deposit_event(Event::::TransferredWithFee(who, currency_id, amount, fee, dest)); + Self::deposit_event(Event::::TransferredWithFee { + sender: who, + currency_id, + amount, + fee, + dest, + }); Ok(()) } @@ -364,7 +395,11 @@ pub mod module { })?; if deposit_event { - Self::deposit_event(Event::::TransferredMultiAsset(who, asset, dest)); + Self::deposit_event(Event::::TransferredMultiAsset { + sender: who, + asset, + dest, + }); } Ok(()) @@ -429,7 +464,12 @@ pub mod module { .map_err(|_| Error::::XcmExecutionFailed)?; if deposit_event { - Self::deposit_event(Event::::TransferredMultiAssetWithFee(who, asset, fee, dest)); + Self::deposit_event(Event::::TransferredMultiAssetWithFee { + sender: who, + asset, + fee, + dest, + }); } Ok(())