Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Issue #17 - breaking changes on master #18

Merged
merged 4 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
46 changes: 24 additions & 22 deletions src/brackets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ where
Item: Codec + EncodeLike,
C: StorageValue<Bracket, Query = Bracket>,
B: StorageMap<Bracket, (BufferIndex, BufferIndex), Query = (BufferIndex, BufferIndex)>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = ItemKey>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Item>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = Option<ItemKey>>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Option<Item>>,
{
index_vector: BufferIndexVector,
_phantom: PhantomData<(ItemKey, Item, C, B, M, N)>,
Expand All @@ -86,8 +86,8 @@ where
Item: Codec + EncodeLike,
C: StorageValue<Bracket, Query = Bracket>,
B: StorageMap<Bracket, (BufferIndex, BufferIndex), Query = (BufferIndex, BufferIndex)>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = ItemKey>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Item>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = Option<ItemKey>>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Option<Item>>,
{
/// Create a new `BracketsTransient` that backs the brackets implementation.
///
Expand All @@ -103,7 +103,10 @@ where
index_vector.push((start, end));
}

BracketsTransient { index_vector, _phantom: PhantomData }
BracketsTransient {
index_vector,
_phantom: PhantomData,
}
}
}

Expand All @@ -113,8 +116,8 @@ where
Item: Codec + EncodeLike,
C: StorageValue<Bracket, Query = Bracket>,
B: StorageMap<Bracket, (BufferIndex, BufferIndex), Query = (BufferIndex, BufferIndex)>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = ItemKey>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Item>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = Option<ItemKey>>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Option<Item>>,
{
/// Commit on `drop`.
fn drop(&mut self) {
Expand All @@ -130,8 +133,8 @@ where
Item: Codec + EncodeLike,
C: StorageValue<Bracket, Query = Bracket>,
B: StorageMap<Bracket, (BufferIndex, BufferIndex), Query = (BufferIndex, BufferIndex)>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = ItemKey>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Item>,
M: StorageDoubleMap<Bracket, BufferIndex, ItemKey, Query = Option<ItemKey>>,
N: StorageDoubleMap<Bracket, ItemKey, Item, Query = Option<Item>>,
{
/// Commit the (potentially) changed bounds to storage.
fn commit(&self) {
Expand All @@ -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;
}
}

Expand All @@ -178,19 +181,18 @@ where
/// Will remove the item, but will not update the bounds in storage.
fn pop(&mut self, bracket: Bracket) -> Option<Item> {
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.
Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountId> {
account: AccountId,
}
Expand Down Expand Up @@ -100,7 +100,7 @@ pub mod pallet {
Blake2_128Concat,
BufferIndex,
T::AccountId,
ValueQuery,
OptionQuery,
>;

#[pallet::storage]
Expand All @@ -112,7 +112,7 @@ pub mod pallet {
Blake2_128Concat,
T::AccountId,
PlayerStruct<T::AccountId>,
ValueQuery,
OptionQuery,
>;

// Pallets use events to inform users when important changes are made.
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
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));
Expand Down Expand Up @@ -195,23 +195,23 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
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
Expand Down
6 changes: 5 additions & 1 deletion src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand All @@ -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::<Test>().unwrap().into()
system::GenesisConfig::default()
.build_storage::<Test>()
.unwrap()
.into()
}