From 1b2df0533e6e975136b04726ce6c5363fefcc8b9 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 23 Dec 2024 02:12:07 +0100 Subject: [PATCH] seals: introduce TxoSealDef simplified type --- seals/src/lib.rs | 4 +++- seals/src/txout.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/seals/src/lib.rs b/seals/src/lib.rs index 697153d2..7f9694e6 100644 --- a/seals/src/lib.rs +++ b/seals/src/lib.rs @@ -45,4 +45,6 @@ extern crate serde; mod txout; -pub use txout::{mmb, mpc, Anchor, AnchorError, AnchorMergeError, Noise, TxoSeal, TxoSealExt}; +pub use txout::{ + mmb, mpc, Anchor, AnchorError, AnchorMergeError, Noise, TxoSeal, TxoSealDef, TxoSealExt, +}; diff --git a/seals/src/txout.rs b/seals/src/txout.rs index d4ea25d5..2f1287ad 100644 --- a/seals/src/txout.rs +++ b/seals/src/txout.rs @@ -227,6 +227,27 @@ impl StrictDumb for TxoSealExt { fn strict_dumb() -> Self { TxoSealExt::Noise(Noise::from(Bytes::from_byte_array([0u8; 40]))) } } +/// Seal definition which is not specific to a used single-use seal protocol. +/// +/// Seals of this type can't be used in seal validation or in closing seals, and are used for +/// informational purposes only. For all other uses please check [`TxoSeal`]. +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display)] +#[display("{primary}/{secondary}")] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct TxoSealDef { + pub primary: Outpoint, + pub secondary: TxoSealExt, +} + +impl From> for TxoSealDef { + fn from(seal: TxoSeal) -> Self { + TxoSealDef { + primary: seal.primary, + secondary: seal.secondary, + } + } +} + #[derive(Clone, Eq, PartialEq, Hash, Debug, Display)] #[display("{primary}/{secondary}")] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] @@ -274,6 +295,16 @@ impl TxoSeal { _phantom: PhantomData, } } + + pub fn from_definition(seal: TxoSealDef) -> Self { + Self { + primary: seal.primary, + secondary: seal.secondary, + _phantom: PhantomData, + } + } + + pub fn to_definition(&self) -> TxoSealDef { TxoSealDef::from(*self) } } impl SingleUseSeal for TxoSeal {