use super::Body;
use crate::Any;
use tendermint::block;
#[derive(Clone, Debug, Default)]
pub struct BodyBuilder {
body: Body,
}
impl BodyBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn msg(&mut self, msg: impl Into<Any>) -> &mut Self {
self.body.messages.push(msg.into());
self
}
pub fn msgs(&mut self, msgs: impl IntoIterator<Item = Any>) -> &mut Self {
self.body.messages.extend(msgs);
self
}
pub fn memo(&mut self, memo: impl Into<String>) -> &mut Self {
self.body.memo = memo.into();
self
}
pub fn timeout_height(&mut self, height: impl Into<block::Height>) -> &mut Self {
self.body.timeout_height = height.into();
self
}
pub fn extension_option(&mut self, option: impl Into<Any>) -> &mut Self {
self.body.extension_options.push(option.into());
self
}
pub fn non_critical_extension_option(&mut self, option: impl Into<Any>) -> &mut Self {
self.body.non_critical_extension_options.push(option.into());
self
}
pub fn finish(&self) -> Body {
self.into()
}
}
impl From<BodyBuilder> for Body {
fn from(builder: BodyBuilder) -> Body {
builder.body
}
}
impl From<&BodyBuilder> for Body {
fn from(builder: &BodyBuilder) -> Body {
builder.body.clone()
}
}