From d511ba032049c3ac1d9d87831f45a61e4e8e7e55 Mon Sep 17 00:00:00 2001
From: Xiliang Chen <xlchen1291@gmail.com>
Date: Thu, 19 Mar 2020 14:33:24 +1300
Subject: [PATCH] remove Default from Call (#126)

* remove Default from Call

* break line a bit
---
 schedule-update/src/lib.rs  | 22 +++++++++-------------
 schedule-update/src/mock.rs |  6 ------
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/schedule-update/src/lib.rs b/schedule-update/src/lib.rs
index 606ed0c..0c74f91 100644
--- a/schedule-update/src/lib.rs
+++ b/schedule-update/src/lib.rs
@@ -30,7 +30,7 @@ type CallOf<T> = <T as Trait>::Call;
 
 pub trait Trait: frame_system::Trait {
 	type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
-	type Call: Parameter + Default + Dispatchable<Origin = <Self as frame_system::Trait>::Origin> + GetDispatchInfo;
+	type Call: Parameter + Dispatchable<Origin = <Self as frame_system::Trait>::Origin> + GetDispatchInfo;
 	type MaxScheduleDispatchWeight: Get<Weight>;
 }
 
@@ -66,8 +66,10 @@ decl_error! {
 decl_storage! {
 	trait Store for Module<T: Trait> as ScheduleUpdate {
 		pub NextId get(fn next_id): DispatchId;
-		pub DelayedNormalDispatches get(fn delayed_normal_dispatches): double_map hasher(twox_64_concat) T::BlockNumber, hasher(twox_64_concat) DispatchId => (Option<T::AccountId>, CallOf<T>, DispatchId);
-		pub DelayedOperationalDispatches get(fn delayed_operational_dispatches): double_map hasher(twox_64_concat) T::BlockNumber, hasher(twox_64_concat) DispatchId => (Option<T::AccountId>, CallOf<T>, DispatchId);
+		pub DelayedNormalDispatches get(fn delayed_normal_dispatches):
+			double_map hasher(twox_64_concat) T::BlockNumber, hasher(twox_64_concat) DispatchId => Option<(Option<T::AccountId>, CallOf<T>, DispatchId)>;
+		pub DelayedOperationalDispatches get(fn delayed_operational_dispatches):
+			double_map hasher(twox_64_concat) T::BlockNumber, hasher(twox_64_concat) DispatchId => Option<(Option<T::AccountId>, CallOf<T>, DispatchId)>;
 	}
 }
 
@@ -115,22 +117,16 @@ decl_module! {
 		pub fn cancel_deplayed_dispatch(origin, at: T::BlockNumber, id: DispatchId) {
 			let is_root = ensure_root(origin.clone()).is_ok();
 
-			if <DelayedNormalDispatches<T>>::contains_key(at, id) {
+			if let Some((who, _, _)) = <DelayedNormalDispatches<T>>::get(at, id) {
 				if !is_root {
 					let w = ensure_signed(origin)?;
-					let (who, _, _) = <DelayedNormalDispatches<T>>::get(at, id);
-					if Some(w) != who {
-						return Err(Error::<T>::NoPermission.into());
-					}
+					ensure!(Some(w) == who, Error::<T>::NoPermission);
 				}
 				<DelayedNormalDispatches<T>>::remove(at, id);
-			} else if <DelayedOperationalDispatches<T>>::contains_key(at, id) {
+			} else if let Some((who, _, _)) = <DelayedOperationalDispatches<T>>::get(at, id) {
 				if !is_root {
 					let w = ensure_signed(origin)?;
-					let (who, _, _) = <DelayedOperationalDispatches<T>>::get(at, id);
-					if Some(w) != who {
-						return Err(Error::<T>::NoPermission.into());
-					}
+					ensure!(Some(w) == who, Error::<T>::NoPermission);
 				}
 				<DelayedOperationalDispatches<T>>::remove(at, id);
 			} else {
diff --git a/schedule-update/src/mock.rs b/schedule-update/src/mock.rs
index 81831d6..cddd132 100644
--- a/schedule-update/src/mock.rs
+++ b/schedule-update/src/mock.rs
@@ -31,12 +31,6 @@ impl_outer_dispatch! {
 	}
 }
 
-impl Default for Call {
-	fn default() -> Call {
-		Default::default()
-	}
-}
-
 // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
 #[derive(Clone, PartialEq, Eq, Debug)]
 pub struct Runtime;
-- 
GitLab