espresso_types/v0/
txproof.rs1use hotshot_query_service::{availability::VerifiableInclusion, VidCommon};
2use hotshot_types::data::VidCommitment;
3use serde::{Deserialize, Serialize};
4
5use super::{v0_1::ADVZTxProof, v0_3::AvidMTxProof, Index, NsTable, Payload, Transaction};
6use crate::SeqTypes;
7
8#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9pub enum TxProof {
10 V0(ADVZTxProof),
11 V1(AvidMTxProof),
12}
13
14impl TxProof {
15 pub fn new(
16 index: &Index,
17 payload: &Payload,
18 common: &VidCommon,
19 ) -> Option<(Transaction, Self)> {
20 match common {
21 VidCommon::V0(common) => {
22 ADVZTxProof::new(index, payload, common).map(|(tx, proof)| (tx, TxProof::V0(proof)))
23 },
24 VidCommon::V1(common) => AvidMTxProof::new(index, payload, common)
25 .map(|(tx, proof)| (tx, TxProof::V1(proof))),
26 }
27 }
28}
29
30impl VerifiableInclusion<SeqTypes> for TxProof {
31 fn verify(
32 &self,
33 ns_table: &NsTable,
34 tx: &Transaction,
35 commit: &VidCommitment,
36 common: &VidCommon,
37 ) -> bool {
38 match self {
39 TxProof::V0(tx_proof) => tx_proof.verify(ns_table, tx, commit, common),
40 TxProof::V1(tx_proof) => tx_proof.verify(ns_table, tx, commit, common),
41 }
42 }
43}