diff --git a/types/src/row_namespace_data.rs b/types/src/row_namespace_data.rs index 40bc953b..77e13be9 100644 --- a/types/src/row_namespace_data.rs +++ b/types/src/row_namespace_data.rs @@ -41,7 +41,7 @@ pub struct RowNamespaceDataId { /// It is constructed out of the ExtendedDataSquare. If, for particular EDS, shares from the namespace span multiple rows, /// one needs multiple RowNamespaceData instances to cover the whole range. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(into = "RawRowNamespaceData")] +#[serde(into = "RawRowNamespaceData", try_from = "RawRowNamespaceData")] pub struct RowNamespaceData { /// Proof of data inclusion pub proof: NamespaceProof, @@ -172,6 +172,23 @@ impl From for RawRowNamespaceData { } } +impl TryFrom for RowNamespaceData { + type Error = Error; + + fn try_from(value: RawRowNamespaceData) -> std::result::Result { + let Some(proof) = value.proof else { + return Err(Error::MissingProof); + }; + let proof = proof.try_into()?; + + let mut shares = Vec::with_capacity(value.shares.len()); + for raw_share in value.shares { + shares.push(Share::try_from(raw_share)?); + } + Ok(RowNamespaceData { proof, shares }) + } +} + impl RowNamespaceDataId { /// Create a new [`RowNamespaceDataId`] for given block, row and the [`Namespace`]. ///