/
market_commons_pallet_api.rs
92 lines (76 loc) · 3.36 KB
/
market_commons_pallet_api.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2021-2022 Zeitgeist PM LLC.
//
// This file is part of Zeitgeist.
//
// Zeitgeist is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// Zeitgeist is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.
#![allow(clippy::type_complexity)]
use crate::types::{Market, PoolId};
use frame_support::{
dispatch::{DispatchError, DispatchResult},
pallet_prelude::{MaybeSerializeDeserialize, Member},
storage::PrefixIterator,
traits::NamedReservableCurrency,
Parameter,
};
use parity_scale_codec::MaxEncodedLen;
use sp_runtime::traits::AtLeast32Bit;
/// Simple disputes - Pallet Api
pub trait MarketCommonsPalletApi {
type AccountId;
type BlockNumber: AtLeast32Bit;
type Currency: NamedReservableCurrency<Self::AccountId, ReserveIdentifier = [u8; 8]>;
type MarketId: AtLeast32Bit
+ Copy
+ Default
+ MaybeSerializeDeserialize
+ MaxEncodedLen
+ Member
+ Parameter;
type Moment: AtLeast32Bit + Copy + Default + Parameter + MaxEncodedLen;
// Market
/// Latest attributed auto-generated ID
///
/// Returns `Err` if no market has bees created
fn latest_market_id() -> Result<Self::MarketId, DispatchError>;
/// Return an iterator over the key-value pairs of markets. Altering market storage during
/// iteration results in undefined behavior.
fn market_iter()
-> PrefixIterator<(Self::MarketId, Market<Self::AccountId, Self::BlockNumber, Self::Moment>)>;
/// Gets a market from the storage.
fn market(
market_id: &Self::MarketId,
) -> Result<Market<Self::AccountId, Self::BlockNumber, Self::Moment>, DispatchError>;
/// Mutates a given market storage
fn mutate_market<F>(market_id: &Self::MarketId, cb: F) -> DispatchResult
where
F: FnOnce(&mut Market<Self::AccountId, Self::BlockNumber, Self::Moment>) -> DispatchResult;
/// Pushes a new market into the storage, returning its related auto-incremented ID.
fn push_market(
market: Market<Self::AccountId, Self::BlockNumber, Self::Moment>,
) -> Result<Self::MarketId, DispatchError>;
/// Removes a market from the storage.
fn remove_market(market_id: &Self::MarketId) -> DispatchResult;
/// Return the account id of a market's prize pool.
fn market_account(market_id: Self::MarketId) -> Self::AccountId;
// MarketPool
/// Connects a pool identified by `pool_id` to a market identified by `market_id`.
fn insert_market_pool(market_id: Self::MarketId, pool_id: PoolId) -> DispatchResult;
/// Removes the pool id associated with a given `market_id`
fn remove_market_pool(market_id: &Self::MarketId) -> DispatchResult;
/// Fetches the pool id associated with a given `market_id`.
fn market_pool(market_id: &Self::MarketId) -> Result<PoolId, DispatchError>;
// Etc
/// Returns the current UTC time (milliseconds)
fn now() -> Self::Moment;
}