diff --git a/Cargo.toml b/Cargo.toml index 710fdf0..65c1758 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,18 +17,18 @@ codec = {default-features = false, features = ['derive','max-encoded-len'], pack scale-info = {default-features = false, features = ['derive'], version = '1.0'} # primitives -sp-std = {default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} +sp-std = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf'} # Substrate dependencies -frame-benchmarking = {default-features = false, optional = true, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} -frame-support = {default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} -frame-system = {default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} +frame-benchmarking = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf', optional = true} +frame-support = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf'} +frame-system = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf'} [dev-dependencies] serde = '1.0.126' -sp-runtime = {default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} -sp-core = {default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} -sp-io = {default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'master'} +sp-runtime = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf'} +sp-core = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf'} +sp-io = {default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '2a7a734c373d0b28c6c658667effd3fb8c9e35bf'} [features] default = ['std'] diff --git a/src/brackets.rs b/src/brackets.rs index 5df9581..ed1b753 100644 --- a/src/brackets.rs +++ b/src/brackets.rs @@ -73,8 +73,8 @@ where Item: Codec + EncodeLike, C: StorageValue, B: StorageMap, - M: StorageDoubleMap, - N: StorageDoubleMap, + M: StorageDoubleMap>, + N: StorageDoubleMap>, { index_vector: BufferIndexVector, _phantom: PhantomData<(ItemKey, Item, C, B, M, N)>, @@ -86,8 +86,8 @@ where Item: Codec + EncodeLike, C: StorageValue, B: StorageMap, - M: StorageDoubleMap, - N: StorageDoubleMap, + M: StorageDoubleMap>, + N: StorageDoubleMap>, { /// Create a new `BracketsTransient` that backs the brackets implementation. /// @@ -103,7 +103,10 @@ where index_vector.push((start, end)); } - BracketsTransient { index_vector, _phantom: PhantomData } + BracketsTransient { + index_vector, + _phantom: PhantomData, + } } } @@ -113,8 +116,8 @@ where Item: Codec + EncodeLike, C: StorageValue, B: StorageMap, - M: StorageDoubleMap, - N: StorageDoubleMap, + M: StorageDoubleMap>, + N: StorageDoubleMap>, { /// Commit on `drop`. fn drop(&mut self) { @@ -130,8 +133,8 @@ where Item: Codec + EncodeLike, C: StorageValue, B: StorageMap, - M: StorageDoubleMap, - N: StorageDoubleMap, + M: StorageDoubleMap>, + N: StorageDoubleMap>, { /// Commit the (potentially) changed bounds to storage. fn commit(&self) { @@ -151,7 +154,7 @@ where // check all brackets if key is queued for i in 0..self.index_vector.len() { if N::contains_key(i as Bracket, &item_key) { - return false + return false; } } @@ -178,19 +181,18 @@ where /// Will remove the item, but will not update the bounds in storage. fn pop(&mut self, bracket: Bracket) -> Option { if self.is_empty(bracket) { - return None + return None; } let (mut v_start, v_end) = self.index_vector[bracket as usize]; - let item_key = M::take(bracket, v_start); - let item = N::take(bracket, item_key); - - v_start = v_start.wrapping_add(1 as u16); - - self.index_vector[bracket as usize] = (v_start, v_end); - - item.into() + M::take(bracket, v_start) + .and_then(|item_key| N::take(bracket, item_key)) + .and_then(|item| { + v_start = v_start.wrapping_add(1 as u16); + self.index_vector[bracket as usize] = (v_start, v_end); + Some(item) + }) } /// Return whether to consider the queue empty. @@ -205,9 +207,9 @@ where let (v_start, v_end) = self.index_vector[bracket as usize]; if v_start <= v_end { - return v_end - v_start + return v_end - v_start; } else { - return (BufferIndex::MAX - v_start) + v_end + return (BufferIndex::MAX - v_start) + v_end; } } @@ -216,7 +218,7 @@ where // check all brackets if key is queued for i in 0..self.index_vector.len() { if N::contains_key(i as Bracket, &item_key) { - return true + return true; } } diff --git a/src/lib.rs b/src/lib.rs index ef97f9a..9424847 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ pub enum MatchingType { Mix, } -#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)] +#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)] pub struct PlayerStruct { account: AccountId, } @@ -100,7 +100,7 @@ pub mod pallet { Blake2_128Concat, BufferIndex, T::AccountId, - ValueQuery, + OptionQuery, >; #[pallet::storage] @@ -112,7 +112,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, PlayerStruct, - ValueQuery, + OptionQuery, >; // Pallets use events to inform users when important changes are made. @@ -164,7 +164,7 @@ impl, I: 'static> Pallet { let player = PlayerStruct { account }; // duplicate check if we can add key to the queue if !queue.push(bracket, player.account.clone(), player.clone()) { - return false + return false; } Self::deposit_event(Event::Queued(player)); @@ -195,23 +195,23 @@ impl, I: 'static> Pallet { for i in 0..Self::brackets_count() { // skip if bracket is empty if queue.size(i) == 0 { - continue + continue; } // iterate for each slot occupied and fill, till player match size reached for _j in 0..queue.size(i) { if brackets.len() == max_players as usize { - break + break; } brackets.push(i); } // leave if brackets is filled with brackets if brackets.len() == max_players as usize { - break + break; } } // vec not filled with enough brackets leave if brackets.len() < max_players as usize { - return result + return result; } // pop from the harvested brackets players diff --git a/src/mock.rs b/src/mock.rs index bee8d6f..751a96f 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -51,6 +51,7 @@ impl system::Config for Test { type SystemWeightInfo = (); type SS58Prefix = SS58Prefix; type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<1>; } parameter_types! { @@ -66,5 +67,8 @@ impl pallet_matchmaker::Config for Test { // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default().build_storage::().unwrap().into() + system::GenesisConfig::default() + .build_storage::() + .unwrap() + .into() }