use bc::opcodes::OP_RETURN;
use bc::ScriptPubkey;
use commit_verify::mpc::Commitment;
use commit_verify::{EmbedCommitProof, EmbedCommitVerify, EmbedVerifyError};
use crate::opret::{OpretError, OpretFirst, OpretProof};
impl EmbedCommitProof<Commitment, ScriptPubkey, OpretFirst> for OpretProof {
fn restore_original_container(
&self,
commit_container: &ScriptPubkey,
) -> Result<ScriptPubkey, EmbedVerifyError<OpretError>> {
if !commit_container.is_op_return() {
return Err(OpretError::NoOpretOutput.into());
}
if commit_container.len() != 34 {
return Err(OpretError::InvalidOpretScript.into());
}
Ok(ScriptPubkey::from_checked(vec![OP_RETURN]))
}
}
impl EmbedCommitVerify<Commitment, OpretFirst> for ScriptPubkey {
type Proof = OpretProof;
type CommitError = OpretError;
fn embed_commit(&mut self, msg: &Commitment) -> Result<Self::Proof, Self::CommitError> {
if !self.is_op_return() {
return Err(OpretError::NoOpretOutput);
}
if self.len() != 1 {
return Err(OpretError::InvalidOpretScript);
}
*self = ScriptPubkey::op_return(msg.as_slice());
Ok(OpretProof::default())
}
}