Skip to content

Commit

Permalink
persistence: use XOupoint instead of XOutputSeal in the APIs
Browse files Browse the repository at this point in the history
Closes #290
  • Loading branch information
dr-orlovsky committed Jan 6, 2025
1 parent 14ca8d8 commit af5a31b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/persistence/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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}.
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<P: IndexProvider> Index<P> {

pub(super) fn contracts_assigning(
&self,
outputs: BTreeSet<XOutputSeal>,
outputs: BTreeSet<XOutpoint>,

Check warning on line 300 in src/persistence/index.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/index.rs#L300

Added line #L300 was not covered by tests
) -> Result<impl Iterator<Item = ContractId> + '_, IndexError<P>> {
self.provider
.contracts_assigning(outputs)
Expand All @@ -314,7 +314,7 @@ impl<P: IndexProvider> Index<P> {
pub(super) fn opouts_by_outputs(
&self,
contract_id: ContractId,
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
outputs: impl IntoIterator<Item = impl Into<XOutpoint>>,

Check warning on line 317 in src/persistence/index.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/index.rs#L317

Added line #L317 was not covered by tests
) -> Result<BTreeSet<Opout>, IndexError<P>> {
Ok(self.provider.opouts_by_outputs(contract_id, outputs)?)
}
Expand Down Expand Up @@ -368,7 +368,7 @@ pub trait IndexReadProvider {

fn contracts_assigning(
&self,
outputs: BTreeSet<XOutputSeal>,
outputs: BTreeSet<XOutpoint>,
) -> Result<impl Iterator<Item = ContractId> + '_, Self::Error>;

fn public_opouts(
Expand All @@ -379,7 +379,7 @@ pub trait IndexReadProvider {
fn opouts_by_outputs(
&self,
contract_id: ContractId,
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
outputs: impl IntoIterator<Item = impl Into<XOutpoint>>,
) -> Result<BTreeSet<Opout>, IndexReadError<Self::Error>>;

fn opouts_by_terminals(
Expand Down
18 changes: 12 additions & 6 deletions src/persistence/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,14 +1273,18 @@ impl IndexReadProvider for MemIndex {

fn contracts_assigning(
&self,
outputs: BTreeSet<XOutputSeal>,
outpoints: BTreeSet<XOutpoint>,

Check warning on line 1276 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1276

Added line #L1276 was not covered by tests
) -> Result<impl Iterator<Item = ContractId> + '_, 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)

Check warning on line 1286 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1282-L1286

Added lines #L1282 - L1286 were not covered by tests
{
Some(*contract_id)
} else {
None
Expand All @@ -1303,17 +1307,19 @@ impl IndexReadProvider for MemIndex {
fn opouts_by_outputs(
&self,
contract_id: ContractId,
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
outpoints: impl IntoIterator<Item = impl Into<XOutpoint>>,

Check warning on line 1310 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1310

Added line #L1310 was not covered by tests
) -> Result<BTreeSet<Opout>, IndexReadError<Self::Error>> {
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()) {

Check warning on line 1317 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1317

Added line #L1317 was not covered by tests
let set = index
.outpoint_opouts
.get(&output)
.iter()
.find(|(seal, _)| seal.to_outpoint() == output)
.map(|(_, set)| set.to_unconfined())

Check warning on line 1322 in src/persistence/memory.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/memory.rs#L1320-L1322

Added lines #L1320 - L1322 were not covered by tests
.ok_or(IndexInconsistency::OutpointUnknown(output, contract_id))?;
opouts.extend(set)
}
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
/// output seals.
pub fn contracts_assigning(
&self,
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
outputs: impl IntoIterator<Item = impl Into<XOutpoint>>,

Check warning on line 529 in src/persistence/stock.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L529

Added line #L529 was not covered by tests
) -> Result<impl Iterator<Item = ContractId> + '_, StockError<S, H, P>> {
let outputs = outputs
.into_iter()
Expand Down

0 comments on commit af5a31b

Please sign in to comment.