use bc::{Outpoint, Vout};
use commit_verify::{Sha256, StrictHash};
use crate::{Noise, TxoSealExt};
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = dbc::LIB_NAME_BPCORE, tags = custom, dumb = Self::Wout(strict_dumb!()))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(untagged))]
pub enum WOutpoint {
#[display("~:{0}")]
#[strict_type(tag = 0)]
Wout(Vout),
#[display(inner)]
#[strict_type(tag = 1)]
Extern(Outpoint),
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display)]
#[display("{primary}/{secondary}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = dbc::LIB_NAME_BPCORE)]
#[derive(CommitEncode)]
#[commit_encode(strategy = strict, id = StrictHash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct WTxoSeal {
pub primary: WOutpoint,
pub secondary: TxoSealExt,
}
impl WTxoSeal {
pub fn vout_no_fallback(vout: Vout, noise_engine: Sha256, nonce: u64) -> Self {
Self::with(WOutpoint::Wout(vout), noise_engine, nonce)
}
pub fn no_fallback(outpoint: Outpoint, noise_engine: Sha256, nonce: u64) -> Self {
Self::with(WOutpoint::Extern(outpoint), noise_engine, nonce)
}
pub fn with(outpoint: WOutpoint, noise_engine: Sha256, nonce: u64) -> Self {
Self {
primary: outpoint,
secondary: TxoSealExt::Noise(Noise::with(outpoint, noise_engine, nonce)),
}
}
}