Skip to content

Commit

Permalink
Implement symmetrical deserialization for RowNamespaceData
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Dec 24, 2024
1 parent 7304017 commit b205e76
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion types/src/row_namespace_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -172,6 +172,23 @@ impl From<RowNamespaceData> for RawRowNamespaceData {
}
}

impl TryFrom<RawRowNamespaceData> for RowNamespaceData {
type Error = Error;

fn try_from(value: RawRowNamespaceData) -> std::result::Result<Self, Self::Error> {
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`].
///
Expand Down

0 comments on commit b205e76

Please sign in to comment.