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
use crate::common::RoundInfo;
use frame_support::{pallet_prelude::Weight, sp_runtime::traits::Zero};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_std::marker::PhantomData;

pub trait Clock<T: frame_system::Config> {
    fn current_round() -> RoundInfo<BlockNumberFor<T>>;
    fn round_duration() -> BlockNumberFor<T>;
}

pub struct ClockMock<T> {
    _phantom: PhantomData<T>,
}

impl<T: frame_system::Config> Clock<T> for ClockMock<T> {
    fn current_round() -> RoundInfo<BlockNumberFor<T>> {
        Default::default()
    }

    fn round_duration() -> BlockNumberFor<T> {
        Zero::zero()
    }
}

pub trait OnHookQueues<T: frame_system::Config> {
    // Process the queues for the given block number, handle the intervals internally.
    fn process(n: BlockNumberFor<T>, hook_weight_limit: Weight) -> Weight;
    // Process the queues once per week.
    fn process_weekly(n: BlockNumberFor<T>, hook_weight_limit: Weight) -> Weight;
    // Process the queues once per 2 weeks.
    fn process_bi_weekly(n: BlockNumberFor<T>, hook_weight_limit: Weight) -> Weight;
    // Process the queues once per day.
    fn process_daily(n: BlockNumberFor<T>, hook_weight_limit: Weight) -> Weight;
    // Process the queues once per hour.
    fn process_hourly(n: BlockNumberFor<T>, hook_weight_limit: Weight) -> Weight;
}

pub struct EmptyOnHookQueues<T> {
    _phantom: PhantomData<T>,
}

impl<T: frame_system::Config> OnHookQueues<T> for EmptyOnHookQueues<T> {
    fn process(_n: BlockNumberFor<T>, _hook_weight_limit: Weight) -> Weight {
        Zero::zero()
    }

    fn process_weekly(_n: BlockNumberFor<T>, _hook_weight_limit: Weight) -> Weight {
        Zero::zero()
    }

    fn process_bi_weekly(_n: BlockNumberFor<T>, _hook_weight_limit: Weight) -> Weight {
        Zero::zero()
    }

    fn process_daily(_n: BlockNumberFor<T>, _hook_weight_limit: Weight) -> Weight {
        Zero::zero()
    }

    fn process_hourly(_n: BlockNumberFor<T>, _hook_weight_limit: Weight) -> Weight {
        Zero::zero()
    }
}