Skip to content

Commit

Permalink
Merge pull request #81 from availproject/miguel/recover_protocol_sequ…
Browse files Browse the repository at this point in the history
…ence

Add conversion from `DataProof` to `MerkleProof`
  • Loading branch information
fmiguelgarcia authored Mar 19, 2024
2 parents 56b0d5c + d3297aa commit 6c1932c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions core/src/data_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ pub enum SubTrie {
}

#[derive(Debug, Clone, Copy, Encode, Decode, PartialEq, Eq, Default, TypeInfo)]
#[cfg_attr(
feature = "serde",
serde(rename_all = "camelCase"),
derive(Serialize, Deserialize)
)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct TxDataRoots {
/// Global Merkle root
pub data_root: H256,
Expand Down Expand Up @@ -126,4 +123,23 @@ impl DataProof {
leaf_index: m_proof.leaf_index as u32,
}
}

pub fn as_sub_merkle_proof(
&self,
sub_trie: SubTrie,
leaf: Vec<u8>,
) -> MerkleProof<H256, Vec<u8>> {
let root = match sub_trie {
SubTrie::DataSubmit => self.roots.blob_root,
SubTrie::Bridge => self.roots.bridge_root,
};

MerkleProof {
root,
proof: self.proof.clone(),
leaf,
number_of_leaves: self.number_of_leaves as usize,
leaf_index: self.leaf_index as usize,
}
}
}

0 comments on commit 6c1932c

Please sign in to comment.