cfxcore/pos/mempool/core_mempool/
transaction.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use diem_crypto::HashValue;
9use diem_types::{
10    account_address::AccountAddress, transaction::SignedTransaction,
11};
12use serde::{Deserialize, Serialize};
13use std::time::Duration;
14
15#[derive(Clone)]
16pub struct MempoolTransaction {
17    pub txn: SignedTransaction,
18    // System expiration time of the transaction. It should be removed from
19    // mempool by that time.
20    pub expiration_time: Duration,
21    pub timeline_state: TimelineState,
22}
23
24impl MempoolTransaction {
25    pub(crate) fn new(
26        txn: SignedTransaction, expiration_time: Duration,
27        timeline_state: TimelineState,
28    ) -> Self {
29        Self {
30            txn,
31            expiration_time,
32            timeline_state,
33        }
34    }
35
36    pub(crate) fn get_hash(&self) -> HashValue { self.txn.hash() }
37
38    pub(crate) fn get_sender(&self) -> AccountAddress { self.txn.sender() }
39}
40
41#[derive(Clone, Copy, PartialEq, Eq, Debug, Deserialize, Hash, Serialize)]
42pub enum TimelineState {
43    // The transaction is ready for broadcast.
44    // Associated integer represents it's position in the log of such
45    // transactions.
46    Ready(u64),
47    // Transaction is not yet ready for broadcast, but it might change in a
48    // future.
49    NotReady,
50    // Transaction will never be qualified for broadcasting.
51    // Currently we don't broadcast transactions originated on other peers.
52    NonQualified,
53}