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
use core::fmt;
use ibc_proto::google::protobuf::Any;
use uuid::Uuid;
#[derive(Copy, Clone, Debug)]
pub enum TrackingId {
Uuid(Uuid),
Static(&'static str),
}
impl TrackingId {
pub fn new_uuid() -> Self {
Self::Uuid(Uuid::new_v4())
}
pub fn new_static(s: &'static str) -> Self {
Self::Static(s)
}
}
impl fmt::Display for TrackingId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TrackingId::Uuid(u) => {
let mut s = u.to_string();
s.truncate(8);
s.fmt(f)
}
TrackingId::Static(s) => s.fmt(f),
}
}
}
#[derive(Debug, Clone)]
pub struct TrackedMsgs {
pub msgs: Vec<Any>,
pub tracking_id: TrackingId,
}
impl TrackedMsgs {
pub fn new(msgs: Vec<Any>, tracking_id: TrackingId) -> Self {
Self { msgs, tracking_id }
}
pub fn new_static(msgs: Vec<Any>, tracking_id: &'static str) -> Self {
Self {
msgs,
tracking_id: TrackingId::Static(tracking_id),
}
}
pub fn new_uuid(msgs: Vec<Any>, tracking_id: Uuid) -> Self {
Self {
msgs,
tracking_id: TrackingId::Uuid(tracking_id),
}
}
pub fn new_single(msg: Any, tracking_id: &'static str) -> Self {
Self {
msgs: vec![msg],
tracking_id: TrackingId::Static(tracking_id),
}
}
pub fn new_single_uuid(msg: Any, tracking_id: Uuid) -> Self {
Self {
msgs: vec![msg],
tracking_id: TrackingId::Uuid(tracking_id),
}
}
pub fn messages(&self) -> &Vec<Any> {
&self.msgs
}
pub fn tracking_id(&self) -> TrackingId {
self.tracking_id
}
}