pub trait Market<RelayBlockNumber, Balance, AccountId> {
type Error: Into<DispatchError>;
type BidId: Copy + Debug + Codec + MaxEncodedLen + TypeInfo + Eq;
type InitData: Parameter;
type Configuration: Parameter;
type CoreRangeProvider: CoreRangeProvider;
type TimesliceProvider: TimesliceProvider;
// Required methods
fn configure(configuration: Self::Configuration) -> Result<(), Self::Error>;
fn start_sales(
block_number: RelayBlockNumber,
init_data: Self::InitData,
) -> Result<SalesStarted<RelayBlockNumber>, Self::Error>;
fn place_order(
block_number: RelayBlockNumber,
who: &AccountId,
price_limit: Balance,
) -> Result<OrderResult<Balance, Self::BidId>, Self::Error>;
fn place_renewal_order(
block_number: RelayBlockNumber,
who: &AccountId,
renewal: PotentialRenewalId,
) -> Result<RenewalOrderResult<Balance, Self::BidId>, Self::Error>;
fn adjust_bid(
block_number: RelayBlockNumber,
id: Self::BidId,
who: &AccountId,
new_price: Option<Balance>,
) -> Result<AdjustBidResult<Balance>, Self::Error>;
fn tick(
now: RelayBlockNumber,
weight_meter: &mut WeightMeter,
) -> Vec<TickAction<AccountId, Balance, RelayBlockNumber>>;
}Expand description
Trait representing generic coretime market logic.
§Assumptions about the market implementations
- There are two types of orders: purchase and renewal.
- Every successful order either creates a bid or is resolved immediately.
- Coretime regions are equivalent from the user’s perspective.
§Market lifecycle
Market::start_sales— initializes the market (if required).Market::place_order,Market::place_renewal_order, andMarket::adjust_bid— users purchase or bid for coretime regions and renew existing ones.Market::tick— called fromon_initializehook to execute time-dependent logic.
Required Associated Types§
Sourcetype BidId: Copy + Debug + Codec + MaxEncodedLen + TypeInfo + Eq
type BidId: Copy + Debug + Codec + MaxEncodedLen + TypeInfo + Eq
Unique identifier assigned to each bid.
Sourcetype InitData: Parameter
type InitData: Parameter
Initialization data used in Market::start_sales.
Sourcetype Configuration: Parameter
type Configuration: Parameter
Configuration of the market.
Can be set in the Market::configure.
Sourcetype CoreRangeProvider: CoreRangeProvider
type CoreRangeProvider: CoreRangeProvider
Provides information about available cores.
Sourcetype TimesliceProvider: TimesliceProvider
type TimesliceProvider: TimesliceProvider
Provides information about timeslice scheduling.
Required Methods§
Sourcefn start_sales(
block_number: RelayBlockNumber,
init_data: Self::InitData,
) -> Result<SalesStarted<RelayBlockNumber>, Self::Error>
fn start_sales( block_number: RelayBlockNumber, init_data: Self::InitData, ) -> Result<SalesStarted<RelayBlockNumber>, Self::Error>
Start the coretime sales.
§Parameters
block_number: Current relay chain block number.init_data: Market-specific initialization data.
Sourcefn place_order(
block_number: RelayBlockNumber,
who: &AccountId,
price_limit: Balance,
) -> Result<OrderResult<Balance, Self::BidId>, Self::Error>
fn place_order( block_number: RelayBlockNumber, who: &AccountId, price_limit: Balance, ) -> Result<OrderResult<Balance, Self::BidId>, Self::Error>
Place an order to purchase one coretime region.
Depending on the implementation, this either: places a bid, or immediately executes the purchase.
§Parameters
block_number: Current relay chain block number.who: Account placing the order.price_limit: Maximum price the buyer is willing to pay.
Sourcefn place_renewal_order(
block_number: RelayBlockNumber,
who: &AccountId,
renewal: PotentialRenewalId,
) -> Result<RenewalOrderResult<Balance, Self::BidId>, Self::Error>
fn place_renewal_order( block_number: RelayBlockNumber, who: &AccountId, renewal: PotentialRenewalId, ) -> Result<RenewalOrderResult<Balance, Self::BidId>, Self::Error>
Place an order to renew a coretime region.
Depending on the implementation, this either: places a bid, or immediately executes the purchase.
§Parameters
block_number: Current relay chain block number.who: Account placing the order.renewal: Renewal identifier.
Sourcefn adjust_bid(
block_number: RelayBlockNumber,
id: Self::BidId,
who: &AccountId,
new_price: Option<Balance>,
) -> Result<AdjustBidResult<Balance>, Self::Error>
fn adjust_bid( block_number: RelayBlockNumber, id: Self::BidId, who: &AccountId, new_price: Option<Balance>, ) -> Result<AdjustBidResult<Balance>, Self::Error>
Adjust the price of an existing bid.
This call may fail if the market does not allow increasing, decreasing, or withdrawing bids.
§Parameters
block_number: Current relay chain block number.id: The identifier of the bid to adjust.who: Account adjusting the bid.new_price: The new bid price. IfNoneis provided, the bid will be withdrawn.
Sourcefn tick(
now: RelayBlockNumber,
weight_meter: &mut WeightMeter,
) -> Vec<TickAction<AccountId, Balance, RelayBlockNumber>>
fn tick( now: RelayBlockNumber, weight_meter: &mut WeightMeter, ) -> Vec<TickAction<AccountId, Balance, RelayBlockNumber>>
Execute time-based market logic.
This function is called from the on_initialize hook by pallet-broker.
§Parameters
now: Current relay chain block number.weight_meter: Used for advanced weight accounting.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.