diff --git a/tendermint/src/abci/event.rs b/tendermint/src/abci/event.rs index 8b69ba2ff..a24431523 100644 --- a/tendermint/src/abci/event.rs +++ b/tendermint/src/abci/event.rs @@ -139,59 +139,64 @@ impl, V: Into> From<(K, V)> for EventAttribute { // Protobuf conversions // ============================================================================= -use core::convert::{TryFrom, TryInto}; - -use tendermint_proto::{abci as pb, Protobuf}; - -impl From for pb::EventAttribute { - fn from(event: EventAttribute) -> Self { - Self { - key: event.key.into(), - value: event.value.into(), - index: event.index, +mod v0_34 { + use super::{Event, EventAttribute}; + use crate::prelude::*; + use core::convert::{TryFrom, TryInto}; + + use tendermint_proto::v0_34::abci as pb; + use tendermint_proto::Protobuf; + + impl From for pb::EventAttribute { + fn from(event: EventAttribute) -> Self { + Self { + key: event.key.into(), + value: event.value.into(), + index: event.index, + } } } -} -impl TryFrom for EventAttribute { - type Error = crate::Error; - - fn try_from(event: pb::EventAttribute) -> Result { - // We insist that keys and values are strings, like tm 0.35 did. - Ok(Self { - key: String::from_utf8(event.key.to_vec()) - .map_err(|e| crate::Error::parse(e.to_string()))?, - value: String::from_utf8(event.value.to_vec()) - .map_err(|e| crate::Error::parse(e.to_string()))?, - index: event.index, - }) + impl TryFrom for EventAttribute { + type Error = crate::Error; + + fn try_from(event: pb::EventAttribute) -> Result { + // We insist that keys and values are strings, like tm 0.35 did. + Ok(Self { + key: String::from_utf8(event.key.to_vec()) + .map_err(|e| crate::Error::parse(e.to_string()))?, + value: String::from_utf8(event.value.to_vec()) + .map_err(|e| crate::Error::parse(e.to_string()))?, + index: event.index, + }) + } } -} -impl Protobuf for EventAttribute {} + impl Protobuf for EventAttribute {} -impl From for pb::Event { - fn from(event: Event) -> Self { - Self { - r#type: event.kind, - attributes: event.attributes.into_iter().map(Into::into).collect(), + impl From for pb::Event { + fn from(event: Event) -> Self { + Self { + r#type: event.kind, + attributes: event.attributes.into_iter().map(Into::into).collect(), + } } } -} -impl TryFrom for Event { - type Error = crate::Error; - - fn try_from(event: pb::Event) -> Result { - Ok(Self { - kind: event.r#type, - attributes: event - .attributes - .into_iter() - .map(TryInto::try_into) - .collect::>()?, - }) + impl TryFrom for Event { + type Error = crate::Error; + + fn try_from(event: pb::Event) -> Result { + Ok(Self { + kind: event.r#type, + attributes: event + .attributes + .into_iter() + .map(TryInto::try_into) + .collect::>()?, + }) + } } -} -impl Protobuf for Event {} + impl Protobuf for Event {} +} diff --git a/tendermint/src/abci/request.rs b/tendermint/src/abci/request.rs index 990b567d9..23cea370f 100644 --- a/tendermint/src/abci/request.rs +++ b/tendermint/src/abci/request.rs @@ -18,7 +18,7 @@ // This is also why certain submodules have #[allow(unused)] imports to bring // items into scope for doc links, rather than changing the doc links -- it // allows the doc comments to be copied without editing. -use core::convert::{TryFrom, TryInto}; +use core::convert::TryFrom; // bring into scope for doc links #[allow(unused)] @@ -257,56 +257,65 @@ impl TryFrom for SnapshotRequest { // Protobuf conversions // ============================================================================= -use tendermint_proto::{abci as pb, Protobuf}; +mod v0_34 { + use super::Request; + use crate::{prelude::*, Error}; + use tendermint_proto::v0_34::abci as pb; + use tendermint_proto::Protobuf; -impl From for pb::Request { - fn from(request: Request) -> pb::Request { - use pb::request::Value; - let value = match request { - Request::Echo(x) => Some(Value::Echo(x.into())), - Request::Flush => Some(Value::Flush(Default::default())), - Request::Info(x) => Some(Value::Info(x.into())), - Request::SetOption(x) => Some(Value::SetOption(x.into())), - Request::InitChain(x) => Some(Value::InitChain(x.into())), - Request::Query(x) => Some(Value::Query(x.into())), - Request::BeginBlock(x) => Some(Value::BeginBlock(x.into())), - Request::CheckTx(x) => Some(Value::CheckTx(x.into())), - Request::DeliverTx(x) => Some(Value::DeliverTx(x.into())), - Request::EndBlock(x) => Some(Value::EndBlock(x.into())), - Request::Commit => Some(Value::Commit(Default::default())), - Request::ListSnapshots => Some(Value::ListSnapshots(Default::default())), - Request::OfferSnapshot(x) => Some(Value::OfferSnapshot(x.into())), - Request::LoadSnapshotChunk(x) => Some(Value::LoadSnapshotChunk(x.into())), - Request::ApplySnapshotChunk(x) => Some(Value::ApplySnapshotChunk(x.into())), - }; - pb::Request { value } + impl From for pb::Request { + fn from(request: Request) -> pb::Request { + use pb::request::Value; + let value = match request { + Request::Echo(x) => Some(Value::Echo(x.into())), + Request::Flush => Some(Value::Flush(Default::default())), + Request::Info(x) => Some(Value::Info(x.into())), + Request::SetOption(x) => Some(Value::SetOption(x.into())), + Request::InitChain(x) => Some(Value::InitChain(x.into())), + Request::Query(x) => Some(Value::Query(x.into())), + Request::BeginBlock(x) => Some(Value::BeginBlock(x.into())), + Request::CheckTx(x) => Some(Value::CheckTx(x.into())), + Request::DeliverTx(x) => Some(Value::DeliverTx(x.into())), + Request::EndBlock(x) => Some(Value::EndBlock(x.into())), + Request::Commit => Some(Value::Commit(Default::default())), + Request::ListSnapshots => Some(Value::ListSnapshots(Default::default())), + Request::OfferSnapshot(x) => Some(Value::OfferSnapshot(x.into())), + Request::LoadSnapshotChunk(x) => Some(Value::LoadSnapshotChunk(x.into())), + Request::ApplySnapshotChunk(x) => Some(Value::ApplySnapshotChunk(x.into())), + }; + pb::Request { value } + } } -} -impl TryFrom for Request { - type Error = Error; + impl TryFrom for Request { + type Error = Error; - fn try_from(request: pb::Request) -> Result { - use pb::request::Value; - match request.value { - Some(Value::Echo(x)) => Ok(Request::Echo(x.try_into()?)), - Some(Value::Flush(pb::RequestFlush {})) => Ok(Request::Flush), - Some(Value::Info(x)) => Ok(Request::Info(x.try_into()?)), - Some(Value::SetOption(x)) => Ok(Request::SetOption(x.try_into()?)), - Some(Value::InitChain(x)) => Ok(Request::InitChain(x.try_into()?)), - Some(Value::Query(x)) => Ok(Request::Query(x.try_into()?)), - Some(Value::BeginBlock(x)) => Ok(Request::BeginBlock(x.try_into()?)), - Some(Value::CheckTx(x)) => Ok(Request::CheckTx(x.try_into()?)), - Some(Value::DeliverTx(x)) => Ok(Request::DeliverTx(x.try_into()?)), - Some(Value::EndBlock(x)) => Ok(Request::EndBlock(x.try_into()?)), - Some(Value::Commit(pb::RequestCommit {})) => Ok(Request::Commit), - Some(Value::ListSnapshots(pb::RequestListSnapshots {})) => Ok(Request::ListSnapshots), - Some(Value::OfferSnapshot(x)) => Ok(Request::OfferSnapshot(x.try_into()?)), - Some(Value::LoadSnapshotChunk(x)) => Ok(Request::LoadSnapshotChunk(x.try_into()?)), - Some(Value::ApplySnapshotChunk(x)) => Ok(Request::ApplySnapshotChunk(x.try_into()?)), - None => Err(crate::Error::missing_data()), + fn try_from(request: pb::Request) -> Result { + use pb::request::Value; + match request.value { + Some(Value::Echo(x)) => Ok(Request::Echo(x.try_into()?)), + Some(Value::Flush(pb::RequestFlush {})) => Ok(Request::Flush), + Some(Value::Info(x)) => Ok(Request::Info(x.try_into()?)), + Some(Value::SetOption(x)) => Ok(Request::SetOption(x.try_into()?)), + Some(Value::InitChain(x)) => Ok(Request::InitChain(x.try_into()?)), + Some(Value::Query(x)) => Ok(Request::Query(x.try_into()?)), + Some(Value::BeginBlock(x)) => Ok(Request::BeginBlock(x.try_into()?)), + Some(Value::CheckTx(x)) => Ok(Request::CheckTx(x.try_into()?)), + Some(Value::DeliverTx(x)) => Ok(Request::DeliverTx(x.try_into()?)), + Some(Value::EndBlock(x)) => Ok(Request::EndBlock(x.try_into()?)), + Some(Value::Commit(pb::RequestCommit {})) => Ok(Request::Commit), + Some(Value::ListSnapshots(pb::RequestListSnapshots {})) => { + Ok(Request::ListSnapshots) + }, + Some(Value::OfferSnapshot(x)) => Ok(Request::OfferSnapshot(x.try_into()?)), + Some(Value::LoadSnapshotChunk(x)) => Ok(Request::LoadSnapshotChunk(x.try_into()?)), + Some(Value::ApplySnapshotChunk(x)) => { + Ok(Request::ApplySnapshotChunk(x.try_into()?)) + }, + None => Err(crate::Error::missing_data()), + } } } -} -impl Protobuf for Request {} + impl Protobuf for Request {} +} diff --git a/tendermint/src/abci/request/echo.rs b/tendermint/src/abci/request/echo.rs index 3ae62456e..469096367 100644 --- a/tendermint/src/abci/request/echo.rs +++ b/tendermint/src/abci/request/echo.rs @@ -11,26 +11,56 @@ pub struct Echo { // Protobuf conversions // ============================================================================= -use core::convert::TryFrom; +mod v0_34 { + use tendermint_proto::v0_34::abci as pb; + use tendermint_proto::Protobuf; -use tendermint_proto::{abci as pb, Protobuf}; + use super::Echo; -impl From for pb::RequestEcho { - fn from(echo: Echo) -> Self { - Self { - message: echo.message, + impl From for pb::RequestEcho { + fn from(echo: Echo) -> Self { + Self { + message: echo.message, + } } } -} -impl TryFrom for Echo { - type Error = crate::Error; + impl TryFrom for Echo { + type Error = crate::Error; - fn try_from(echo: pb::RequestEcho) -> Result { - Ok(Self { - message: echo.message, - }) + fn try_from(echo: pb::RequestEcho) -> Result { + Ok(Self { + message: echo.message, + }) + } } + + impl Protobuf for Echo {} } -impl Protobuf for Echo {} +mod v0_37 { + use tendermint_proto::v0_37::abci as pb; + use tendermint_proto::Protobuf; + + use super::Echo; + + impl From for pb::RequestEcho { + fn from(echo: Echo) -> Self { + Self { + message: echo.message, + } + } + } + + impl TryFrom for Echo { + type Error = crate::Error; + + fn try_from(echo: pb::RequestEcho) -> Result { + Ok(Self { + message: echo.message, + }) + } + } + + impl Protobuf for Echo {} +}