mithril_common/messages/message_parts/
cardano_transactions_set_proof.rs1use 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#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
13#[cfg_attr(target_family = "wasm", wasm_bindgen(getter_with_clone))]
14pub struct CardanoTransactionsSetProofMessagePart {
15 pub transactions_hashes: Vec<TransactionHash>,
17
18 pub proof: HexEncodedKey,
20}
21
22impl CardanoTransactionsSetProofMessagePart {
23 cfg_test_tools! {
24 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}