1use super::Body;
4use crate::Any;
5use tendermint::block;
6
7#[derive(Clone, Debug, Default)]
10pub struct BodyBuilder {
11 body: Body,
13}
14
15impl BodyBuilder {
16 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn msg(&mut self, msg: impl Into<Any>) -> &mut Self {
23 self.body.messages.push(msg.into());
24 self
25 }
26
27 pub fn msgs(&mut self, msgs: impl IntoIterator<Item = Any>) -> &mut Self {
29 self.body.messages.extend(msgs);
30 self
31 }
32
33 pub fn memo(&mut self, memo: impl Into<String>) -> &mut Self {
35 self.body.memo = memo.into();
36 self
37 }
38
39 pub fn timeout_height(&mut self, height: impl Into<block::Height>) -> &mut Self {
41 self.body.timeout_height = height.into();
42 self
43 }
44
45 pub fn extension_option(&mut self, option: impl Into<Any>) -> &mut Self {
47 self.body.extension_options.push(option.into());
48 self
49 }
50
51 pub fn non_critical_extension_option(&mut self, option: impl Into<Any>) -> &mut Self {
53 self.body.non_critical_extension_options.push(option.into());
54 self
55 }
56
57 pub fn finish(&self) -> Body {
59 self.into()
60 }
61}
62
63impl From<BodyBuilder> for Body {
64 fn from(builder: BodyBuilder) -> Body {
65 builder.body
66 }
67}
68
69impl From<&BodyBuilder> for Body {
70 fn from(builder: &BodyBuilder) -> Body {
71 builder.body.clone()
72 }
73}