mithril_common/messages/message_parts/
cardano_transactions_set_proof.rs

1use crate::{
2    StdError,
3    crypto_helper::ProtocolMkProof,
4    entities::{CardanoTransactionsSetProof, HexEncodedKey, TransactionHash},
5};
6use serde::{Deserialize, Serialize};
7
8#[cfg(target_family = "wasm")]
9use wasm_bindgen::prelude::*;
10
11/// A cryptographic proof of a set of Cardano transactions is included in the global Cardano transactions set
12#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
13#[cfg_attr(target_family = "wasm", wasm_bindgen(getter_with_clone))]
14pub struct CardanoTransactionsSetProofMessagePart {
15    /// Hashes of the certified transactions
16    pub transactions_hashes: Vec<TransactionHash>,
17
18    /// Proof of the transactions
19    pub proof: HexEncodedKey,
20}
21
22impl TryFrom<CardanoTransactionsSetProof> for CardanoTransactionsSetProofMessagePart {
23    type Error = StdError;
24
25    fn try_from(proof: CardanoTransactionsSetProof) -> Result<Self, Self::Error> {
26        Ok(Self {
27            transactions_hashes: proof.transactions_hashes,
28            proof: proof.transactions_proof.to_json_hex()?,
29        })
30    }
31}
32
33impl TryFrom<CardanoTransactionsSetProofMessagePart> for CardanoTransactionsSetProof {
34    type Error = StdError;
35
36    fn try_from(proof: CardanoTransactionsSetProofMessagePart) -> Result<Self, Self::Error> {
37        Ok(Self {
38            transactions_hashes: proof.transactions_hashes,
39            transactions_proof: ProtocolMkProof::from_json_hex(&proof.proof)?,
40        })
41    }
42}