Skip to content

Commit

Permalink
seals: introduce TxoSealDef simplified type
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 23, 2024
1 parent 749ad5a commit 1b2df05
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion seals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
31 changes: 31 additions & 0 deletions seals/src/txout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D: dbc::Proof> From<TxoSeal<D>> for TxoSealDef {
fn from(seal: TxoSeal<D>) -> Self {
TxoSealDef {
primary: seal.primary,
secondary: seal.secondary,
}
}

Check warning on line 248 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L243-L248

Added lines #L243 - L248 were not covered by tests
}

#[derive(Clone, Eq, PartialEq, Hash, Debug, Display)]
#[display("{primary}/{secondary}")]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]

Check warning on line 253 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L253

Added line #L253 was not covered by tests
Expand Down Expand Up @@ -274,6 +295,16 @@ impl<D: dbc::Proof> TxoSeal<D> {
_phantom: PhantomData,
}
}

Check warning on line 297 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L286-L297

Added lines #L286 - L297 were not covered by tests

pub fn from_definition(seal: TxoSealDef) -> Self {
Self {
primary: seal.primary,
secondary: seal.secondary,
_phantom: PhantomData,
}
}

Check warning on line 305 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L299-L305

Added lines #L299 - L305 were not covered by tests

pub fn to_definition(&self) -> TxoSealDef { TxoSealDef::from(*self) }

Check warning on line 307 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L307

Added line #L307 was not covered by tests
}

impl<D: dbc::Proof> SingleUseSeal for TxoSeal<D> {
Expand Down

0 comments on commit 1b2df05

Please sign in to comment.