From 20388f2e099b3d39b99fda83570be33ec4f913d4 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 18 Dec 2023 19:00:06 +0100 Subject: [PATCH] containers: improve partial types confinements --- src/containers/partials.rs | 16 ++++++++++++---- src/persistence/inventory.rs | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/containers/partials.rs b/src/containers/partials.rs index 334d353c..9283846c 100644 --- a/src/containers/partials.rs +++ b/src/containers/partials.rs @@ -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}; @@ -160,7 +160,7 @@ impl BatchItem { )] pub struct Batch { pub main: BatchItem, - pub blanks: MediumVec, + pub blanks: Confined, 0, { U24 - 1 }>, } impl StrictSerialize for Batch {} @@ -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", @@ -190,8 +190,16 @@ impl IntoIterator for Batch { )] pub struct Fascia { pub anchor: XAnchor, - pub bundles: MediumVec, + pub bundles: Confined, 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 {} diff --git a/src/persistence/inventory.rs b/src/persistence/inventory.rs index 4ec5e831..cf05f94c 100644 --- a/src/persistence/inventory.rs +++ b/src/persistence/inventory.rs @@ -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}; @@ -818,7 +818,7 @@ pub trait Inventory: Deref { } } // Construct blank transitions - let mut blanks = MediumVec::with_capacity(spent_state.len()); + let mut blanks = Confined::, 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());