use rgb::seals::txout::{BlindSeal, CloseMethod, SealTxid};
use rgb::secp256k1::rand::{thread_rng, RngCore};
use rgb::{GraphSeal, SecretSeal, TxoSeal, Vout};
use crate::LIB_NAME_RGB_OPS;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_OPS)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct VoutSeal {
pub method: CloseMethod,
pub vout: Vout,
pub blinding: u64,
}
impl VoutSeal {
#[inline]
pub fn new(method: CloseMethod, vout: impl Into<Vout>) -> Self {
VoutSeal::with(method, vout, thread_rng().next_u64())
}
#[inline]
pub fn new_opret(vout: impl Into<Vout>) -> Self { VoutSeal::new(CloseMethod::OpretFirst, vout) }
#[inline]
pub fn new_tapret(vout: impl Into<Vout>) -> Self {
VoutSeal::new(CloseMethod::TapretFirst, vout)
}
#[inline]
pub fn with_opret(vout: impl Into<Vout>, blinding: u64) -> Self {
VoutSeal::with(CloseMethod::OpretFirst, vout, blinding)
}
#[inline]
pub fn with_tapret(vout: impl Into<Vout>, blinding: u64) -> Self {
VoutSeal::with(CloseMethod::TapretFirst, vout, blinding)
}
#[inline]
pub fn with(method: CloseMethod, vout: impl Into<Vout>, blinding: u64) -> Self {
VoutSeal {
method,
vout: vout.into(),
blinding,
}
}
}
impl From<VoutSeal> for GraphSeal {
fn from(seal: VoutSeal) -> Self { Self::with_blinded_vout(seal.vout, seal.blinding) }
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From)]
pub enum BuilderSeal<Seal: TxoSeal + Ord> {
Revealed(Seal),
#[from]
Concealed(SecretSeal),
}
impl<Id: SealTxid> From<BlindSeal<Id>> for BuilderSeal<BlindSeal<Id>> {
fn from(seal: BlindSeal<Id>) -> Self { BuilderSeal::Revealed(seal) }
}