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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use aptos_types::{account_address::AccountAddress, transaction::SignedTransaction};
use serde::{Deserialize, Serialize};
use std::fmt;
pub type Round = u64;
pub type Author = AccountAddress;
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct TransactionSummary {
pub sender: AccountAddress,
pub sequence_number: u64,
}
impl fmt::Display for TransactionSummary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.sender, self.sequence_number,)
}
}
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
pub enum Payload {
DirectMempool(Vec<SignedTransaction>),
InQuorumStore(Vec<ProofOfStore>),
}
impl Payload {
pub fn new_empty() -> Self {
Payload::DirectMempool(Vec::new())
}
pub fn len(&self) -> usize {
match self {
Payload::DirectMempool(txns) => txns.len(),
Payload::InQuorumStore(_poavs) => todo!(),
}
}
pub fn is_empty(&self) -> bool {
match self {
Payload::DirectMempool(txns) => txns.is_empty(),
Payload::InQuorumStore(_poavs) => todo!(),
}
}
}
impl IntoIterator for Payload {
type Item = SignedTransaction;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
match self {
Payload::DirectMempool(txns) => txns.into_iter(),
Payload::InQuorumStore(_poavs) => todo!(),
}
}
}
impl fmt::Display for Payload {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Payload::DirectMempool(txns) => {
write!(f, "InMemory txns: {}", txns.len())
}
Payload::InQuorumStore(_poavs) => todo!(),
}
}
}
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
pub enum PayloadFilter {
DirectMempool(Vec<TransactionSummary>),
InQuorumStore(Vec<ProofOfStore>),
}
impl From<&Vec<&Payload>> for PayloadFilter {
fn from(exclude_payloads: &Vec<&Payload>) -> Self {
if exclude_payloads.is_empty() {
return PayloadFilter::DirectMempool(vec![]);
}
match exclude_payloads.first().unwrap() {
Payload::DirectMempool(_) => {
let mut exclude_txns = vec![];
for payload in exclude_payloads {
if let Payload::DirectMempool(txns) = payload {
for txn in txns {
exclude_txns.push(TransactionSummary {
sender: txn.sender(),
sequence_number: txn.sequence_number(),
});
}
}
}
PayloadFilter::DirectMempool(exclude_txns)
}
Payload::InQuorumStore(_) => todo!(),
}
}
}
impl fmt::Display for PayloadFilter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PayloadFilter::DirectMempool(excluded_txns) => {
let mut txns_str = "".to_string();
for tx in excluded_txns.iter() {
txns_str += &format!("{} ", tx);
}
write!(f, "{}", txns_str)
}
PayloadFilter::InQuorumStore(_poavs) => todo!(),
}
}
}
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ProofOfStore {
placeholder: u64,
}