Skip to content

Commit

Permalink
seals: support anchor merge procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 22, 2024
1 parent cdacf2a commit 749ad5a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ extern crate serde;

mod txout;

pub use txout::{mmb, mpc, Anchor, AnchorError, Noise, TxoSeal, TxoSealExt};
pub use txout::{mmb, mpc, Anchor, AnchorError, AnchorMergeError, Noise, TxoSeal, TxoSealExt};
27 changes: 27 additions & 0 deletions seals/src/txout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//! spending that output ("TxOut seals").
use core::cmp::Ordering;
use core::error::Error;
use core::fmt::Debug;
use core::marker::PhantomData;

Expand Down Expand Up @@ -323,6 +324,32 @@ impl<D: dbc::Proof> ClientSideWitness for Anchor<D> {
dbc_proof: self.dbc_proof.clone(),
})
}

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

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L314-L326

Added lines #L314 - L326 were not covered by tests

fn merge(&mut self, other: Self) -> Result<(), impl Error>
where Self: Sized {
if self.mpc_protocol != other.mpc_protocol
|| self.mpc_proof != other.mpc_proof
|| self.dbc_proof != other.dbc_proof
|| self.fallback_proof != other.fallback_proof

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

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L328-L333

Added lines #L328 - L333 were not covered by tests
{
return Err(AnchorMergeError::AnchorMismatch);
}
self.mmb_proof
.map
.extend(other.mmb_proof.map)
.map_err(|_| AnchorMergeError::TooManyInputs)?;
Ok(())
}

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

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L335-L342

Added lines #L335 - L342 were not covered by tests
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Error, Debug, Display, From)]
#[display(doc_comments)]
pub enum AnchorMergeError {
/// anchor mismatch in merge procedure
AnchorMismatch,

/// anchor is invalid: too many inputs
TooManyInputs,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Error, Debug, Display, From)]
Expand Down

0 comments on commit 749ad5a

Please sign in to comment.