Skip to content

Commit

Permalink
TryFrom to From
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 24, 2023
1 parent 7605bf4 commit dfa695f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions sdk/src/types/block/output/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,17 @@ mod dto {
latest_commitment_id: SlotCommitmentId,
}

impl TryFrom<OutputMetadataDto> for OutputMetadata {
type Error = crate::types::block::Error;

fn try_from(value: OutputMetadataDto) -> Result<Self, Self::Error> {
Ok(Self {
impl From<OutputMetadataDto> for OutputMetadata {
fn from(value: OutputMetadataDto) -> Self {
Self {
block_id: value.block_id,
output_id: OutputId::new(value.transaction_id, value.output_index),
is_spent: value.is_spent,
commitment_id_spent: value.commitment_id_spent,
transaction_id_spent: value.transaction_id_spent,
included_commitment_id: value.included_commitment_id,
latest_commitment_id: value.latest_commitment_id,
})
}
}
}

Expand All @@ -153,7 +151,7 @@ mod dto {

impl<'de> Deserialize<'de> for OutputMetadata {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
OutputMetadataDto::deserialize(d).and_then(|dto| dto.try_into().map_err(serde::de::Error::custom))
Ok(OutputMetadataDto::deserialize(d)?.into())
}
}

Expand Down

0 comments on commit dfa695f

Please sign in to comment.