transaction_pool/ready.rs
1// Copyright 2020 Parity Technologies
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9/// Transaction readiness.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum Readiness {
12 /// The transaction is stale (and should/will be removed from the pool).
13 Stale,
14 /// The transaction is ready to be included in pending set.
15 Ready,
16 /// The transaction is not yet ready.
17 Future,
18}
19
20/// A readiness indicator.
21pub trait Ready<T> {
22 /// Returns true if transaction is ready to be included in pending block,
23 /// given all previous transactions that were ready are already included.
24 ///
25 /// NOTE: readiness of transactions will be checked according to `Score` ordering,
26 /// the implementation should maintain a state of already checked transactions.
27 fn is_ready(&mut self, tx: &T) -> Readiness;
28}
29
30impl<T, F> Ready<T> for F
31where
32 F: FnMut(&T) -> Readiness,
33{
34 fn is_ready(&mut self, tx: &T) -> Readiness {
35 (*self)(tx)
36 }
37}
38
39impl<T, A, B> Ready<T> for (A, B)
40where
41 A: Ready<T>,
42 B: Ready<T>,
43{
44 fn is_ready(&mut self, tx: &T) -> Readiness {
45 match self.0.is_ready(tx) {
46 Readiness::Ready => self.1.is_ready(tx),
47 r => r,
48 }
49 }
50}