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