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
use crate::Change;
use codec::FullCodec;
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AtLeast32Bit, Bounded, MaybeSerializeDeserialize},
DispatchError, DispatchResult, RuntimeDebug,
};
use sp_std::{
cmp::{Eq, PartialEq},
fmt::Debug,
result,
};
#[cfg_attr(feature = "std", derive(PartialEq, Eq))]
#[derive(Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct AuctionInfo<AccountId, Balance, BlockNumber> {
pub bid: Option<(AccountId, Balance)>,
pub start: BlockNumber,
pub end: Option<BlockNumber>,
}
pub trait Auction<AccountId, BlockNumber> {
type AuctionId: FullCodec + Default + Copy + Eq + PartialEq + MaybeSerializeDeserialize + Bounded + Debug;
type Balance: AtLeast32Bit + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default;
fn auction_info(id: Self::AuctionId) -> Option<AuctionInfo<AccountId, Self::Balance, BlockNumber>>;
fn update_auction(id: Self::AuctionId, info: AuctionInfo<AccountId, Self::Balance, BlockNumber>) -> DispatchResult;
fn new_auction(start: BlockNumber, end: Option<BlockNumber>) -> result::Result<Self::AuctionId, DispatchError>;
fn remove_auction(id: Self::AuctionId);
}
pub struct OnNewBidResult<BlockNumber> {
pub accept_bid: bool,
pub auction_end_change: Change<Option<BlockNumber>>,
}
pub trait AuctionHandler<AccountId, Balance, BlockNumber, AuctionId> {
fn on_new_bid(
now: BlockNumber,
id: AuctionId,
new_bid: (AccountId, Balance),
last_bid: Option<(AccountId, Balance)>,
) -> OnNewBidResult<BlockNumber>;
fn on_auction_ended(id: AuctionId, winner: Option<(AccountId, Balance)>);
}