espresso_types/v0/
txproof.rs

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