Skip to content

Commit 5d73988

Browse files
authored
Tightly coupled market-commons with prediction markets. (#900)
* Remove use of MarketCommonsApi from prediction markets pallet * Fix build * Changes as per review comments * Move MarketCommonsPalletApi trait to primitives and fixes as per review comment. * Changes as per review comments * Fix clippy warning
1 parent 7ec79a9 commit 5d73988

File tree

8 files changed

+147
-148
lines changed

8 files changed

+147
-148
lines changed

primitives/src/traits.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.
1717

1818
mod dispute_api;
19+
mod market_commons_pallet_api;
1920
mod market_id;
2021
mod swaps;
2122
mod zeitgeist_multi_reservable_currency;
2223

2324
pub use dispute_api::DisputeApi;
25+
pub use market_commons_pallet_api::MarketCommonsPalletApi;
2426
pub use market_id::MarketId;
2527
pub use swaps::Swaps;
2628
pub use zeitgeist_multi_reservable_currency::ZeitgeistAssetManager;

zrml/market-commons/src/market_commons_pallet_api.rs renamed to primitives/src/traits/market_commons_pallet_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.
1717

1818
#![allow(clippy::type_complexity)]
19+
use crate::types::{Market, PoolId};
1920
use frame_support::{
2021
dispatch::{DispatchError, DispatchResult},
2122
pallet_prelude::{MaybeSerializeDeserialize, Member},
@@ -25,7 +26,6 @@ use frame_support::{
2526
};
2627
use parity_scale_codec::MaxEncodedLen;
2728
use sp_runtime::traits::AtLeast32Bit;
28-
use zeitgeist_primitives::types::{Market, PoolId};
2929

3030
/// Simple disputes - Pallet Api
3131
pub trait MarketCommonsPalletApi {

runtime/common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ macro_rules! impl_config_traits {
988988
// NoopLiquidityMining will be applied only to mainnet once runtimes are separated.
989989
type LiquidityMining = NoopLiquidityMining;
990990
// type LiquidityMining = LiquidityMining;
991-
type MarketCommons = MarketCommons;
992991
type MaxCategories = MaxCategories;
993992
type MaxDisputes = MaxDisputes;
994993
type MinDisputeDuration = MinDisputeDuration;

zrml/market-commons/src/lib.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020

2121
extern crate alloc;
2222

23-
mod market_commons_pallet_api;
2423
pub mod migrations;
2524
mod mock;
2625
mod tests;
2726

28-
pub use market_commons_pallet_api::MarketCommonsPalletApi;
2927
pub use pallet::*;
28+
pub use zeitgeist_primitives::traits::MarketCommonsPalletApi;
3029

3130
#[frame_support::pallet]
3231
mod pallet {
@@ -55,6 +54,12 @@ mod pallet {
5554

5655
pub type MomentOf<T> = <<T as Config>::Timestamp as frame_support::traits::Time>::Moment;
5756

57+
type MarketOf<T> = Market<
58+
<T as frame_system::Config>::AccountId,
59+
<T as frame_system::Config>::BlockNumber,
60+
MomentOf<T>,
61+
>;
62+
5863
#[pallet::call]
5964
impl<T: Config> Pallet<T> {}
6065

@@ -115,7 +120,7 @@ mod pallet {
115120
// on the storage so next following calls will return yet another incremented number.
116121
//
117122
// Returns `Err` if `MarketId` addition overflows.
118-
fn next_market_id() -> Result<T::MarketId, DispatchError> {
123+
pub fn next_market_id() -> Result<T::MarketId, DispatchError> {
119124
let id = MarketCounter::<T>::get();
120125
let new_counter = id.checked_add(&1u8.into()).ok_or(ArithmeticError::Overflow)?;
121126
<MarketCounter<T>>::put(new_counter);
@@ -145,25 +150,17 @@ mod pallet {
145150
}
146151
}
147152

148-
fn market_iter() -> PrefixIterator<(
149-
Self::MarketId,
150-
Market<Self::AccountId, Self::BlockNumber, Self::Moment>,
151-
)> {
153+
fn market_iter() -> PrefixIterator<(Self::MarketId, MarketOf<T>)> {
152154
<Markets<T>>::iter()
153155
}
154156

155-
fn market(
156-
market_id: &Self::MarketId,
157-
) -> Result<Market<Self::AccountId, Self::BlockNumber, Self::Moment>, DispatchError>
158-
{
157+
fn market(market_id: &Self::MarketId) -> Result<MarketOf<T>, DispatchError> {
159158
<Markets<T>>::try_get(market_id).map_err(|_err| Error::<T>::MarketDoesNotExist.into())
160159
}
161160

162161
fn mutate_market<F>(market_id: &Self::MarketId, cb: F) -> DispatchResult
163162
where
164-
F: FnOnce(
165-
&mut Market<Self::AccountId, Self::BlockNumber, Self::Moment>,
166-
) -> DispatchResult,
163+
F: FnOnce(&mut MarketOf<T>) -> DispatchResult,
167164
{
168165
<Markets<T>>::try_mutate(market_id, |opt| {
169166
if let Some(market) = opt {
@@ -174,9 +171,7 @@ mod pallet {
174171
})
175172
}
176173

177-
fn push_market(
178-
market: Market<Self::AccountId, Self::BlockNumber, Self::Moment>,
179-
) -> Result<Self::MarketId, DispatchError> {
174+
fn push_market(market: MarketOf<T>) -> Result<Self::MarketId, DispatchError> {
180175
let market_id = Self::next_market_id()?;
181176
<Markets<T>>::insert(market_id, market);
182177
Ok(market_id)
@@ -228,12 +223,7 @@ mod pallet {
228223

229224
/// Holds all markets
230225
#[pallet::storage]
231-
pub type Markets<T: Config> = StorageMap<
232-
_,
233-
Blake2_128Concat,
234-
T::MarketId,
235-
Market<T::AccountId, T::BlockNumber, MomentOf<T>>,
236-
>;
226+
pub type Markets<T: Config> = StorageMap<_, Blake2_128Concat, T::MarketId, MarketOf<T>>;
237227

238228
/// The number of markets that have been created (including removed markets) and the next
239229
/// identifier for a created market.

zrml/market-commons/src/tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
#![cfg(test)]
1919

2020
use crate::{
21-
market_commons_pallet_api::MarketCommonsPalletApi,
2221
mock::{ExtBuilder, MarketCommons, Runtime},
2322
MarketCounter, Markets,
2423
};
2524
use frame_support::{assert_err, assert_noop, assert_ok};
2625
use sp_runtime::DispatchError;
27-
use zeitgeist_primitives::types::{
28-
AccountIdTest, BlockNumber, Deadlines, Market, MarketCreation, MarketDisputeMechanism,
29-
MarketPeriod, MarketStatus, MarketType, Moment, ScoringRule,
26+
use zeitgeist_primitives::{
27+
traits::MarketCommonsPalletApi,
28+
types::{
29+
AccountIdTest, BlockNumber, Deadlines, Market, MarketCreation, MarketDisputeMechanism,
30+
MarketPeriod, MarketStatus, MarketType, Moment, ScoringRule,
31+
},
3032
};
3133

3234
const MARKET_DUMMY: Market<AccountIdTest, BlockNumber, Moment> = Market {

0 commit comments

Comments
 (0)