use std::error::Error;
use std::fmt::Debug;
use std::str::FromStr;
use bitcoin::Transaction as Tx;
use strict_encoding::{StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize};
use crate::commit_verify::mpc;
use crate::LIB_NAME_BPCORE;
pub trait DbcMethod:
Copy
+ Eq
+ Ord
+ std::hash::Hash
+ strict_encoding::StrictDumb
+ strict_encoding::StrictEncode
+ strict_encoding::StrictDecode
{
}
#[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)]
#[display(doc_comments)]
pub struct MethodParseError(pub String);
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BPCORE, tags = repr, into_u8, try_from_u8)]
#[repr(u8)]
pub enum Method {
#[display("opret1st")]
#[strict_type(dumb)]
OpretFirst = 0x00,
#[display("tapret1st")]
TapretFirst = 0x01,
}
impl DbcMethod for Method {}
impl FromStr for Method {
type Err = MethodParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s.to_lowercase() {
s if s == Method::OpretFirst.to_string() => Method::OpretFirst,
s if s == Method::TapretFirst.to_string() => Method::TapretFirst,
_ => return Err(MethodParseError(s.to_owned())),
})
}
}
pub trait Proof<M: DbcMethod = Method>:
Clone + Eq + Debug + StrictSerialize + StrictDeserialize + StrictDumb
{
type Error: Error;
fn method(&self) -> M;
fn verify(&self, msg: &mpc::Commitment, tx: &Tx) -> Result<(), Self::Error>;
}