From 0a9c92ef073ac3c3c61390cebe94aa0da341e86d Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 26 Feb 2024 20:50:29 +0100 Subject: [PATCH] containers: make bindle content immutable --- src/containers/bindle.rs | 6 +----- src/persistence/inventory.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/containers/bindle.rs b/src/containers/bindle.rs index 7eb0ae23..fcfa4e67 100644 --- a/src/containers/bindle.rs +++ b/src/containers/bindle.rs @@ -26,7 +26,7 @@ use std::collections::BTreeMap; use std::fmt::{Debug, Display}; use std::io::{self, Read}; -use std::ops::{Deref, DerefMut}; +use std::ops::Deref; use std::str::FromStr; use amplify::confinement::{self, Confined, TinyVec, U24 as U24MAX}; @@ -157,10 +157,6 @@ impl Deref for Bindle { fn deref(&self) -> &Self::Target { &self.data } } -impl DerefMut for Bindle { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.data } -} - impl From for Bindle { fn from(data: C) -> Self { Bindle::new(data) } } diff --git a/src/persistence/inventory.rs b/src/persistence/inventory.rs index 2a3ad446..24d4d23c 100644 --- a/src/persistence/inventory.rs +++ b/src/persistence/inventory.rs @@ -39,8 +39,8 @@ use strict_encoding::TypeName; use crate::accessors::{BundleExt, MergeRevealError, RevealError}; use crate::containers::{ - Batch, Bindle, BuilderSeal, Cert, Consignment, ContentId, Contract, Fascia, Terminal, - TerminalSeal, Transfer, TransitionInfo, + Batch, Bindle, BindleContent, BuilderSeal, Cert, Consignment, ContentId, Contract, Fascia, + Terminal, TerminalSeal, Transfer, TransitionInfo, }; use crate::interface::{ BuilderError, ContractIface, Iface, IfaceId, IfaceImpl, IfacePair, IfaceWrapper, @@ -595,14 +595,11 @@ pub trait Inventory: Deref { contract_id: ContractId, outputs: impl AsRef<[XOutputSeal]>, secret_seals: impl AsRef<[XChain]>, - ) -> Result< - Bindle, - ConsignerError::Target as Stash>::Error>, - > { + ) -> Result::Target as Stash>::Error>> + { let mut consignment = self.consign(contract_id, outputs, secret_seals)?; consignment.transfer = true; - Ok(consignment.into()) - // TODO: Add known sigs to the bindle + Ok(consignment) } fn consign( @@ -704,6 +701,11 @@ pub trait Inventory: Deref { Ok(consignment) } + fn bindle(&self, content: C) -> Bindle { + // TODO: Add known sigs to the bindle + Bindle::from(content) + } + /// Composes a batch of state transitions updating state for the provided /// set of previous outputs, satisfying requirements of the invoice, paying /// the change back and including the necessary blank state transitions.