Skip to content

Commit

Permalink
containers: improve partial types confinements
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 18, 2023
1 parent 920440e commit 20388f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/containers/partials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::ops::{BitOr, BitOrAssign};
use std::vec;

use amplify::confinement;
use amplify::confinement::{Confined, MediumVec, U24};
use amplify::confinement::{Confined, U24};
use bp::seals::txout::CloseMethod;
use commit_verify::mpc;
use rgb::{OpId, Operation, OutputSeal, Transition, TransitionBundle, XAnchor};
Expand Down Expand Up @@ -160,7 +160,7 @@ impl BatchItem {
)]
pub struct Batch {
pub main: BatchItem,
pub blanks: MediumVec<BatchItem>,
pub blanks: Confined<Vec<BatchItem>, 0, { U24 - 1 }>,
}

impl StrictSerialize for Batch {}
Expand All @@ -181,7 +181,7 @@ impl IntoIterator for Batch {
/// of finalized state transitions (under multiple contracts), packed into
/// bundles, and anchored to a single layer 1 transaction.
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
#[cfg_attr(
feature = "serde",
Expand All @@ -190,8 +190,16 @@ impl IntoIterator for Batch {
)]
pub struct Fascia {
pub anchor: XAnchor<mpc::MerkleBlock>,
pub bundles: MediumVec<TransitionBundle>,
pub bundles: Confined<Vec<TransitionBundle>, 1, U24>,
}

impl StrictDumb for Fascia {
fn strict_dumb() -> Self {
Fascia {
anchor: strict_dumb!(),
bundles: confined_vec![strict_dumb!()],
}
}
}
impl StrictSerialize for Fascia {}
impl StrictDeserialize for Fascia {}
4 changes: 2 additions & 2 deletions src/persistence/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::error::Error;
use std::ops::Deref;

use amplify::confinement::{self, Confined, MediumVec};
use amplify::confinement::{self, Confined, MediumVec, U24};
use bp::seals::txout::blind::SingleBlindSeal;
use bp::seals::txout::CloseMethod;
use bp::{Txid, Vout};
Expand Down Expand Up @@ -818,7 +818,7 @@ pub trait Inventory: Deref<Target = Self::Stash> {
}
}
// Construct blank transitions
let mut blanks = MediumVec::with_capacity(spent_state.len());
let mut blanks = Confined::<Vec<_>, 0, { U24 - 1 }>::with_capacity(spent_state.len());
for (id, opouts) in spent_state {
let mut blank_builder = self.blank_builder(id, iface.clone())?;
let mut outputs = Vec::with_capacity(opouts.len());
Expand Down

0 comments on commit 20388f2

Please sign in to comment.