From 8262b8667ddde0c946b60197de2486ca99fe7758 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 20 Jan 2024 12:23:40 +0100 Subject: [PATCH] contract: add convenience convertors for txid-based seals to outpoints --- Cargo.lock | 28 +++++++++++++--------------- Cargo.toml | 3 +++ src/contract/seal.rs | 13 +++++++++++-- src/contract/xchain.rs | 9 ++++++++- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09d17247..92ea2fa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,13 +196,12 @@ dependencies = [ [[package]] name = "bp-consensus" version = "0.11.0-beta.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190ac89a2a3c79d5bfb677f48e5393691832c540973341831572edaffdce0881" +source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#02b26aeccf66c1c5a92427cd05550e49fde7f5eb" dependencies = [ "amplify", "chrono", "commit_verify", - "secp256k1 0.28.0", + "secp256k1 0.28.1", "serde", "strict_encoding", "strict_types", @@ -211,31 +210,31 @@ dependencies = [ [[package]] name = "bp-core" version = "0.11.0-beta.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69269d27e32d784e37f7ca7cdf964fe5e30c5bff1ca2e229a118c84c8efdd179" +source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#02b26aeccf66c1c5a92427cd05550e49fde7f5eb" dependencies = [ "amplify", "bp-consensus", "bp-dbc", "bp-seals", "commit_verify", + "getrandom", "serde", "single_use_seals", "strict_encoding", "strict_types", + "wasm-bindgen", ] [[package]] name = "bp-dbc" version = "0.11.0-beta.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cef9a98c7ae4f1bb333ad8e55c9d8a91f071c347d35b62e19959faa07572b11" +source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#02b26aeccf66c1c5a92427cd05550e49fde7f5eb" dependencies = [ "amplify", "base85", "bp-consensus", "commit_verify", - "secp256k1 0.28.0", + "secp256k1 0.28.1", "serde", "strict_encoding", ] @@ -243,8 +242,7 @@ dependencies = [ [[package]] name = "bp-seals" version = "0.11.0-beta.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d211bb77e320abf4bba6c272fc85d73e5203140ca39e299271f4714d8b6029fe" +source = "git+https://github.com/BP-WG/bp-core?branch=v0.11#02b26aeccf66c1c5a92427cd05550e49fde7f5eb" dependencies = [ "amplify", "baid58", @@ -653,12 +651,12 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5" +checksum = "3f622567e3b4b38154fb8190bcf6b160d7a4301d70595a49195b48c116007a27" dependencies = [ "rand", - "secp256k1-sys 0.9.1", + "secp256k1-sys 0.9.2", "serde", ] @@ -673,9 +671,9 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd97a086ec737e30053fd5c46f097465d25bb81dd3608825f65298c4c98be83" +checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 7b3d4593..f44f66ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/src/contract/seal.rs b/src/contract/seal.rs index 887fb921..3bb0c6a2 100644 --- a/src/contract/seal.rs +++ b/src/contract/seal.rs @@ -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; pub type GraphSeal = ChainBlindSeal; @@ -117,8 +117,17 @@ impl TxoSeal for XChain { pub struct SealPreimage(Bytes32); */ +impl From> for XOutpoint { + #[inline] + fn from(seal: XChain) -> Self { seal.to_outpoint() } +} + impl XChain { - pub fn transmutate(self) -> XChain { self.map(|seal| seal.transmutate()) } + pub fn transmutate(self) -> XChain { 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 XChain { diff --git a/src/contract/xchain.rs b/src/contract/xchain.rs index 1025a847..4510f0eb 100644 --- a/src/contract/xchain.rs +++ b/src/contract/xchain.rs @@ -42,7 +42,14 @@ pub const XCHAIN_LIQUID_PREFIX: &str = "lq"; pub type XOutpoint = XChain; impl From for XOutpoint { - fn from(seal: XChain) -> Self { seal.map(Outpoint::from) } + #[inline] + fn from(seal: XChain) -> 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)]