mithril_common/messages/message_parts/
cardano_transactions_set_proof.rs

1use crate::{
2    crypto_helper::ProtocolMkProof,
3    entities::{CardanoTransactionsSetProof, HexEncodedKey, TransactionHash},
4    StdError,
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 CardanoTransactionsSetProofMessagePart {
23    cfg_test_tools! {
24        /// Retrieve a dummy proof (for test only)
25        pub fn dummy() -> Self {
26            crate::entities::CardanoTransactionsSetProof::dummy().try_into().unwrap()
27        }
28    }
29}
30
31impl TryFrom<CardanoTransactionsSetProof> for CardanoTransactionsSetProofMessagePart {
32    type Error = StdError;
33
34    fn try_from(proof: CardanoTransactionsSetProof) -> Result<Self, Self::Error> {
35        Ok(Self {
36            transactions_hashes: proof.transactions_hashes,
37            proof: proof.transactions_proof.to_json_hex()?,
38        })
39    }
40}
41
42impl TryFrom<CardanoTransactionsSetProofMessagePart> for CardanoTransactionsSetProof {
43    type Error = StdError;
44
45    fn try_from(proof: CardanoTransactionsSetProofMessagePart) -> Result<Self, Self::Error> {
46        Ok(Self {
47            transactions_hashes: proof.transactions_hashes,
48            transactions_proof: ProtocolMkProof::from_json_hex(&proof.proof)?,
49        })
50    }
51}