Skip to content

Commit

Permalink
Merge pull request #139 from RGB-WG/v0.11
Browse files Browse the repository at this point in the history
Improve deterministic contract creation. Add convenient RGB20 contract builder
  • Loading branch information
dr-orlovsky authored Feb 4, 2024
2 parents fea6b66 + 1e36eee commit 57df659
Show file tree
Hide file tree
Showing 17 changed files with 769 additions and 222 deletions.
219 changes: 99 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ wasm-bindgen-test = "0.3"
features = [ "all" ]

[patch.crates-io]
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.11" }
20 changes: 20 additions & 0 deletions invoice/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ impl Amount {
pub fn saturating_sub_assign(&mut self, other: impl Into<Self>) {
*self = self.0.saturating_sub(other.into().0).into();
}

#[must_use]
pub fn checked_add(&self, other: impl Into<Self>) -> Option<Self> {
self.0.checked_add(other.into().0).map(Self)
}
#[must_use]
pub fn checked_sub(&self, other: impl Into<Self>) -> Option<Self> {
self.0.checked_sub(other.into().0).map(Self)
}

#[must_use]
pub fn checked_add_assign(&mut self, other: impl Into<Self>) -> Option<()> {
*self = self.0.checked_add(other.into().0).map(Self)?;
Some(())
}
#[must_use]
pub fn checked_sub_assign(&mut self, other: impl Into<Self>) -> Option<()> {
*self = self.0.checked_sub(other.into().0).map(Self)?;
Some(())
}
}

impl Sum<u64> for Amount {
Expand Down
4 changes: 2 additions & 2 deletions invoice/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl FromStr for RgbInvoice {
let beneficiary = XChainNet::<Beneficiary>::from_str(beneficiary_str)?;
let mut query_params = map_query_params(&uri)?;

let transports = if let Some(endpoints) = query_params.remove(ENDPOINTS) {
let transports = if let Some(endpoints) = query_params.shift_remove(ENDPOINTS) {
let tokens = endpoints.split(TRANSPORT_SEP);
let mut transport_vec: Vec<RgbTransport> = vec![];
for token in tokens {
Expand All @@ -382,7 +382,7 @@ impl FromStr for RgbInvoice {
};

let mut expiry = None;
if let Some(exp) = query_params.remove(EXPIRY) {
if let Some(exp) = query_params.shift_remove(EXPIRY) {
let timestamp = exp
.parse::<i64>()
.map_err(|e| InvoiceParseError::InvalidExpiration(e.to_string()))?;
Expand Down
8 changes: 7 additions & 1 deletion src/containers/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rgb::{
};
use strict_encoding::{StrictDeserialize, StrictDumb, StrictSerialize};

use super::{ContainerVer, ContentId, ContentSigs, Terminal};
use super::{Bindle, BindleContent, ContainerVer, ContentId, ContentSigs, Terminal};
use crate::accessors::BundleExt;
use crate::interface::{ContractSuppl, IfaceId, IfacePair};
use crate::resolvers::ResolveHeight;
Expand Down Expand Up @@ -252,4 +252,10 @@ impl<const TYPE: bool> Consignment<TYPE> {
signatures: self.signatures,
}
}

#[inline]
pub fn unsigned_bindle(self) -> Bindle<Self>
where Self: BindleContent {
Bindle::new(self)
}
}
11 changes: 10 additions & 1 deletion src/containers/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use bp::seals::txout::{BlindSeal, CloseMethod, SealTxid};
use bp::secp256k1::rand::{thread_rng, RngCore};
use bp::Vout;
use commit_verify::Conceal;
use rgb::{GraphSeal, SecretSeal, TxoSeal, XChain};
use rgb::{GraphSeal, Layer1, SecretSeal, TxoSeal, XChain};

use crate::LIB_NAME_RGB_STD;

Expand Down Expand Up @@ -175,3 +175,12 @@ pub enum BuilderSeal<Seal: TxoSeal + Ord> {
impl<Id: SealTxid> From<XChain<BlindSeal<Id>>> for BuilderSeal<BlindSeal<Id>> {
fn from(seal: XChain<BlindSeal<Id>>) -> Self { BuilderSeal::Revealed(seal) }
}

impl<Seal: TxoSeal + Ord> BuilderSeal<Seal> {
pub fn layer1(&self) -> Layer1 {
match self {
BuilderSeal::Revealed(x) => x.layer1(),
BuilderSeal::Concealed(x) => x.layer1(),
}
}
}
Loading

0 comments on commit 57df659

Please sign in to comment.