diff --git a/sdk/src/types/block/payload/mod.rs b/sdk/src/types/block/payload/mod.rs index 639f0c4a83..8a86eb63e4 100644 --- a/sdk/src/types/block/payload/mod.rs +++ b/sdk/src/types/block/payload/mod.rs @@ -31,10 +31,10 @@ use crate::types::block::{protocol::ProtocolParameters, Error}; /// A generic payload that can represent different types defining block payloads. #[derive(Clone, Eq, PartialEq, From)] pub enum Payload { - /// A signed transaction payload. - SignedTransaction(Box), /// A tagged data payload. TaggedData(Box), + /// A signed transaction payload. + SignedTransaction(Box), /// A candidacy announcement payload. CandidacyAnnouncement(CandidacyAnnouncementPayload), } @@ -42,31 +42,31 @@ pub enum Payload { impl core::fmt::Debug for Payload { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - Self::SignedTransaction(payload) => payload.fmt(f), Self::TaggedData(payload) => payload.fmt(f), + Self::SignedTransaction(payload) => payload.fmt(f), Self::CandidacyAnnouncement(payload) => payload.fmt(f), } } } -impl From for Payload { - fn from(payload: SignedTransactionPayload) -> Self { - Self::SignedTransaction(Box::new(payload)) - } -} - impl From for Payload { fn from(payload: TaggedDataPayload) -> Self { Self::TaggedData(Box::new(payload)) } } +impl From for Payload { + fn from(payload: SignedTransactionPayload) -> Self { + Self::SignedTransaction(Box::new(payload)) + } +} + impl Payload { /// Returns the payload kind of a `Payload`. pub fn kind(&self) -> u8 { match self { - Self::SignedTransaction(_) => SignedTransactionPayload::KIND, Self::TaggedData(_) => TaggedDataPayload::KIND, + Self::SignedTransaction(_) => SignedTransactionPayload::KIND, Self::CandidacyAnnouncement(_) => CandidacyAnnouncementPayload::KIND, } } @@ -80,14 +80,14 @@ impl Packable for Payload { fn pack(&self, packer: &mut P) -> Result<(), P::Error> { match self { - Self::SignedTransaction(transaction) => { - SignedTransactionPayload::KIND.pack(packer)?; - transaction.pack(packer) - } Self::TaggedData(tagged_data) => { TaggedDataPayload::KIND.pack(packer)?; tagged_data.pack(packer) } + Self::SignedTransaction(transaction) => { + SignedTransactionPayload::KIND.pack(packer)?; + transaction.pack(packer) + } Self::CandidacyAnnouncement(_) => CandidacyAnnouncementPayload::KIND.pack(packer), }?; @@ -99,10 +99,10 @@ impl Packable for Payload { visitor: &Self::UnpackVisitor, ) -> Result> { Ok(match u8::unpack::<_, VERIFY>(unpacker, &()).coerce()? { + TaggedDataPayload::KIND => Self::from(TaggedDataPayload::unpack::<_, VERIFY>(unpacker, &()).coerce()?), SignedTransactionPayload::KIND => { Self::from(SignedTransactionPayload::unpack::<_, VERIFY>(unpacker, visitor).coerce()?) } - TaggedDataPayload::KIND => Self::from(TaggedDataPayload::unpack::<_, VERIFY>(unpacker, &()).coerce()?), CandidacyAnnouncementPayload::KIND => Self::from(CandidacyAnnouncementPayload), k => return Err(UnpackError::Packable(Error::InvalidPayloadKind(k))), }) @@ -197,30 +197,30 @@ pub mod dto { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum PayloadDto { - SignedTransaction(Box), TaggedData(Box), + SignedTransaction(Box), CandidacyAnnouncement, } - impl From for PayloadDto { - fn from(payload: SignedTransactionPayloadDto) -> Self { - Self::SignedTransaction(Box::new(payload)) - } - } - impl From for PayloadDto { fn from(payload: TaggedDataPayload) -> Self { Self::TaggedData(Box::new(payload)) } } + impl From for PayloadDto { + fn from(payload: SignedTransactionPayloadDto) -> Self { + Self::SignedTransaction(Box::new(payload)) + } + } + impl From<&Payload> for PayloadDto { fn from(value: &Payload) -> Self { match value { + Payload::TaggedData(p) => Self::TaggedData(p.clone()), Payload::SignedTransaction(p) => { Self::SignedTransaction(Box::new(SignedTransactionPayloadDto::from(p.as_ref()))) } - Payload::TaggedData(p) => Self::TaggedData(p.clone()), Payload::CandidacyAnnouncement(_) => Self::CandidacyAnnouncement, } } @@ -232,10 +232,10 @@ pub mod dto { fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { Ok(match dto { + PayloadDto::TaggedData(p) => Self::from(*p), PayloadDto::SignedTransaction(p) => { Self::from(SignedTransactionPayload::try_from_dto_with_params_inner(*p, params)?) } - PayloadDto::TaggedData(p) => Self::from(*p), PayloadDto::CandidacyAnnouncement => Self::from(CandidacyAnnouncementPayload), }) }