1use std::error::Error;
23use std::fmt::Debug;
24use std::str::FromStr;
25
26use bc::Tx;
27use commit_verify::mpc;
28use strict_encoding::{StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize};
29
30use crate::LIB_NAME_BPCORE;
31
32pub trait DbcMethod:
35 Copy
36 + Eq
37 + Ord
38 + std::hash::Hash
39 + strict_encoding::StrictDumb
40 + strict_encoding::StrictEncode
41 + strict_encoding::StrictDecode
42{
43}
44
45#[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)]
47#[display(doc_comments)]
48pub struct MethodParseError(pub String);
49
50#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
52#[cfg_attr(
53 feature = "serde",
54 derive(Serialize, Deserialize),
55 serde(crate = "serde_crate", rename_all = "camelCase")
56)]
57#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
58#[strict_type(lib = LIB_NAME_BPCORE, tags = repr, into_u8, try_from_u8)]
59#[repr(u8)]
60pub enum Method {
61 #[display("opret1st")]
64 #[strict_type(dumb)]
65 OpretFirst = 0x00,
66
67 #[display("tapret1st")]
70 TapretFirst = 0x01,
71}
72
73impl DbcMethod for Method {}
74
75impl FromStr for Method {
76 type Err = MethodParseError;
77
78 fn from_str(s: &str) -> Result<Self, Self::Err> {
79 Ok(match s.to_lowercase() {
80 s if s == Method::OpretFirst.to_string() => Method::OpretFirst,
81 s if s == Method::TapretFirst.to_string() => Method::TapretFirst,
82 _ => return Err(MethodParseError(s.to_owned())),
83 })
84 }
85}
86
87pub trait Proof<M: DbcMethod = Method>:
89 Clone + Eq + Debug + StrictSerialize + StrictDeserialize + StrictDumb
90{
91 type Error: Error;
93
94 fn method(&self) -> M;
96
97 fn verify(&self, msg: &mpc::Commitment, tx: &Tx) -> Result<(), Self::Error>;
99}