Skip to content

Commit

Permalink
contract: add convenience convertors for txid-based seals to outpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jan 29, 2024
1 parent c51af67 commit 8262b86
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
28 changes: 13 additions & 15 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = [ "all" ]

[patch.crates-io]
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
13 changes: 11 additions & 2 deletions src/contract/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use commit_verify::{mpc, strategies, CommitEncode, CommitStrategy, Conceal};
use single_use_seals::SealWitness;
use strict_encoding::{StrictDecode, StrictDumb, StrictEncode, StrictType};

use crate::{XChain, LIB_NAME_RGB};
use crate::{XChain, XOutpoint, LIB_NAME_RGB};

pub type GenesisSeal = SingleBlindSeal<Method>;
pub type GraphSeal = ChainBlindSeal<Method>;
Expand Down Expand Up @@ -117,8 +117,17 @@ impl<Seal: TxoSeal> TxoSeal for XChain<Seal> {
pub struct SealPreimage(Bytes32);
*/

impl From<XChain<GenesisSeal>> for XOutpoint {
#[inline]
fn from(seal: XChain<GenesisSeal>) -> Self { seal.to_outpoint() }
}

impl XChain<GenesisSeal> {
pub fn transmutate(self) -> XChain<GraphSeal> { self.map(|seal| seal.transmutate()) }
pub fn transmutate(self) -> XChain<GraphSeal> { self.map_ref(|seal| seal.transmutate()) }

/// Converts seal into a transaction outpoint.
#[inline]
pub fn to_outpoint(&self) -> XOutpoint { self.map_ref(GenesisSeal::to_outpoint) }
}

impl<U: ExposedSeal> XChain<U> {
Expand Down
9 changes: 8 additions & 1 deletion src/contract/xchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ pub const XCHAIN_LIQUID_PREFIX: &str = "lq";
pub type XOutpoint = XChain<Outpoint>;

impl From<XOutputSeal> for XOutpoint {
fn from(seal: XChain<OutputSeal>) -> Self { seal.map(Outpoint::from) }
#[inline]
fn from(seal: XChain<OutputSeal>) -> Self { seal.to_outpoint() }
}

impl XOutputSeal {
/// Converts seal into a transaction outpoint.
#[inline]
pub fn to_outpoint(&self) -> XOutpoint { self.map_ref(OutputSeal::to_outpoint) }
}

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

0 comments on commit 8262b86

Please sign in to comment.