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
use crate::{prost_ext::MessageExt, proto, ErrorReport, Result};
use prost_types::Any;
use tendermint::block;
#[derive(Clone, Debug, PartialEq)]
pub struct Body {
pub messages: Vec<Any>,
pub memo: String,
pub timeout_height: block::Height,
pub extension_options: Vec<Any>,
pub non_critical_extension_options: Vec<Any>,
}
impl Body {
pub fn new<I>(
messages: I,
memo: impl Into<String>,
timeout_height: impl Into<block::Height>,
) -> Self
where
I: IntoIterator<Item = Any>,
{
Body {
messages: messages.into_iter().map(Into::into).collect(),
memo: memo.into(),
timeout_height: timeout_height.into(),
extension_options: Default::default(),
non_critical_extension_options: Default::default(),
}
}
pub fn into_proto(self) -> proto::cosmos::tx::v1beta1::TxBody {
self.into()
}
pub fn into_bytes(self) -> Result<Vec<u8>> {
self.into_proto().to_bytes()
}
}
impl From<Body> for proto::cosmos::tx::v1beta1::TxBody {
fn from(body: Body) -> proto::cosmos::tx::v1beta1::TxBody {
proto::cosmos::tx::v1beta1::TxBody {
messages: body.messages.into_iter().map(Into::into).collect(),
memo: body.memo,
timeout_height: body.timeout_height.into(),
extension_options: body.extension_options,
non_critical_extension_options: body.non_critical_extension_options,
}
}
}
impl TryFrom<proto::cosmos::tx::v1beta1::TxBody> for Body {
type Error = ErrorReport;
fn try_from(proto: proto::cosmos::tx::v1beta1::TxBody) -> Result<Body> {
Ok(Body {
messages: proto.messages.into_iter().map(Into::into).collect(),
memo: proto.memo,
timeout_height: proto.timeout_height.try_into()?,
extension_options: proto.extension_options,
non_critical_extension_options: proto.non_critical_extension_options,
})
}
}