From af5a31bf8ee8ffc879ec358f31e976338739e02c Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 6 Jan 2025 15:20:34 +0100 Subject: [PATCH] persistence: use XOupoint instead of XOutputSeal in the APIs Closes #290 --- src/persistence/index.rs | 12 ++++++------ src/persistence/memory.rs | 18 ++++++++++++------ src/persistence/stock.rs | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/persistence/index.rs b/src/persistence/index.rs index b07b831c..7291eba0 100644 --- a/src/persistence/index.rs +++ b/src/persistence/index.rs @@ -27,7 +27,7 @@ use amplify::confinement; use nonasync::persistence::{CloneNoPersistence, Persisting}; use rgb::{ Assign, AssignmentType, BundleId, ContractId, ExposedState, Extension, Genesis, GenesisSeal, - GraphSeal, OpId, Operation, Opout, TransitionBundle, TypedAssigns, XChain, XOutputSeal, + GraphSeal, OpId, Operation, Opout, TransitionBundle, TypedAssigns, XChain, XOutpoint, XWitnessId, }; @@ -99,7 +99,7 @@ pub enum IndexInconsistency { BundleAbsent(OpId), /// outpoint {0} is not part of the contract {1}. - OutpointUnknown(XOutputSeal, ContractId), + OutpointUnknown(XOutpoint, ContractId), /// index already contains information about bundle {bundle_id} which /// specifies contract {present} instead of contract {expected}. @@ -297,7 +297,7 @@ impl Index

{ pub(super) fn contracts_assigning( &self, - outputs: BTreeSet, + outputs: BTreeSet, ) -> Result + '_, IndexError

> { self.provider .contracts_assigning(outputs) @@ -314,7 +314,7 @@ impl Index

{ pub(super) fn opouts_by_outputs( &self, contract_id: ContractId, - outputs: impl IntoIterator>, + outputs: impl IntoIterator>, ) -> Result, IndexError

> { Ok(self.provider.opouts_by_outputs(contract_id, outputs)?) } @@ -368,7 +368,7 @@ pub trait IndexReadProvider { fn contracts_assigning( &self, - outputs: BTreeSet, + outputs: BTreeSet, ) -> Result + '_, Self::Error>; fn public_opouts( @@ -379,7 +379,7 @@ pub trait IndexReadProvider { fn opouts_by_outputs( &self, contract_id: ContractId, - outputs: impl IntoIterator>, + outputs: impl IntoIterator>, ) -> Result, IndexReadError>; fn opouts_by_terminals( diff --git a/src/persistence/memory.rs b/src/persistence/memory.rs index 930cb2ea..4126daa2 100644 --- a/src/persistence/memory.rs +++ b/src/persistence/memory.rs @@ -1273,14 +1273,18 @@ impl IndexReadProvider for MemIndex { fn contracts_assigning( &self, - outputs: BTreeSet, + outpoints: BTreeSet, ) -> Result + '_, Self::Error> { Ok(self .contract_index .iter() .flat_map(move |(contract_id, index)| { - outputs.clone().into_iter().filter_map(|outpoint| { - if index.outpoint_opouts.contains_key(&outpoint) { + outpoints.clone().into_iter().filter_map(|outpoint| { + if index + .outpoint_opouts + .keys() + .any(|seal| seal.to_outpoint() == outpoint) + { Some(*contract_id) } else { None @@ -1303,17 +1307,19 @@ impl IndexReadProvider for MemIndex { fn opouts_by_outputs( &self, contract_id: ContractId, - outputs: impl IntoIterator>, + outpoints: impl IntoIterator>, ) -> Result, IndexReadError> { let index = self .contract_index .get(&contract_id) .ok_or(IndexInconsistency::ContractAbsent(contract_id))?; let mut opouts = BTreeSet::new(); - for output in outputs.into_iter().map(|o| o.into()) { + for output in outpoints.into_iter().map(|o| o.into()) { let set = index .outpoint_opouts - .get(&output) + .iter() + .find(|(seal, _)| seal.to_outpoint() == output) + .map(|(_, set)| set.to_unconfined()) .ok_or(IndexInconsistency::OutpointUnknown(output, contract_id))?; opouts.extend(set) } diff --git a/src/persistence/stock.rs b/src/persistence/stock.rs index c05774bb..b43427ee 100644 --- a/src/persistence/stock.rs +++ b/src/persistence/stock.rs @@ -526,7 +526,7 @@ impl Stock { /// output seals. pub fn contracts_assigning( &self, - outputs: impl IntoIterator>, + outputs: impl IntoIterator>, ) -> Result + '_, StockError> { let outputs = outputs .into_iter()