diff --git a/src/persistence/hoard.rs b/src/persistence/hoard.rs index 8ca818f4..827012d0 100644 --- a/src/persistence/hoard.rs +++ b/src/persistence/hoard.rs @@ -52,6 +52,10 @@ pub enum ConsumeError { #[from] MergeReveal(MergeRevealError), + + /// bundle {1} for contract {0} contains invalid transitioon input map + #[display(doc_comments)] + InvalidBundle(ContractId, BundleId), } impl From for InventoryError { diff --git a/src/persistence/inventory.rs b/src/persistence/inventory.rs index 6df0ac1a..8242c223 100644 --- a/src/persistence/inventory.rs +++ b/src/persistence/inventory.rs @@ -355,21 +355,22 @@ pub trait Inventory: Deref { /// /// Must be called before the consignment is created, when witness /// transaction is not yet mined. - fn consume(&mut self, _fascia: Fascia) -> Result<(), InventoryError> { - todo!(); - /* + fn consume(&mut self, fascia: Fascia) -> Result<(), InventoryError> { let witness_id = fascia.anchor.witness_id(); unsafe { self.consume_anchor(fascia.anchor)? }; - for bundle in fascia.bundles { - let ids1 = bundle.known_transitions.keys().copied().collect::>(); + for (contract_id, bundle) in fascia.bundles { + let ids1 = bundle + .known_transitions + .keys() + .copied() + .collect::>(); let ids2 = bundle.input_map.values().copied().collect::>(); if !ids1.is_subset(&ids2) { - + return Err(ConsumeError::InvalidBundle(contract_id, bundle.bundle_id()).into()); } - unsafe { self.consume_bundle(fascia.contract_id, bundle, witness_id)? }; + unsafe { self.consume_bundle(contract_id, bundle, witness_id)? }; } Ok(()) - */ } #[doc(hidden)]