Skip to content

Commit c00aa3b

Browse files
authored
Merge pull request RGB-WG#291 from RGB-WG/fix/290
Use XOupoint instead of XOutputSeal in the APIs
2 parents b374468 + af5a31b commit c00aa3b

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

src/containers/partials.rs

+4
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ impl Hash for TransitionInfo {
156156
}
157157

158158
impl TransitionInfo {
159+
/// # Panics
160+
///
161+
/// If the number of provided seals is zero.
159162
pub fn new(
160163
transition: Transition,
161164
seals: impl AsRef<[XOutputSeal]>,
162165
) -> Result<Self, TransitionInfoError> {
163166
let id = transition.id();
164167
let seals = seals.as_ref();
168+
assert!(!seals.is_empty(), "empty seals provided to transition info constructor");
165169
let inputs = Confined::<BTreeSet<_>, 1, U24>::try_from_iter(
166170
seals.iter().copied().map(XOutpoint::from),
167171
)

src/persistence/index.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use amplify::confinement;
2727
use nonasync::persistence::{CloneNoPersistence, Persisting};
2828
use rgb::{
2929
Assign, AssignmentType, BundleId, ContractId, ExposedState, Extension, Genesis, GenesisSeal,
30-
GraphSeal, OpId, Operation, Opout, TransitionBundle, TypedAssigns, XChain, XOutputSeal,
30+
GraphSeal, OpId, Operation, Opout, TransitionBundle, TypedAssigns, XChain, XOutpoint,
3131
XWitnessId,
3232
};
3333

@@ -99,7 +99,7 @@ pub enum IndexInconsistency {
9999
BundleAbsent(OpId),
100100

101101
/// outpoint {0} is not part of the contract {1}.
102-
OutpointUnknown(XOutputSeal, ContractId),
102+
OutpointUnknown(XOutpoint, ContractId),
103103

104104
/// index already contains information about bundle {bundle_id} which
105105
/// specifies contract {present} instead of contract {expected}.
@@ -297,7 +297,7 @@ impl<P: IndexProvider> Index<P> {
297297

298298
pub(super) fn contracts_assigning(
299299
&self,
300-
outputs: BTreeSet<XOutputSeal>,
300+
outputs: BTreeSet<XOutpoint>,
301301
) -> Result<impl Iterator<Item = ContractId> + '_, IndexError<P>> {
302302
self.provider
303303
.contracts_assigning(outputs)
@@ -314,7 +314,7 @@ impl<P: IndexProvider> Index<P> {
314314
pub(super) fn opouts_by_outputs(
315315
&self,
316316
contract_id: ContractId,
317-
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
317+
outputs: impl IntoIterator<Item = impl Into<XOutpoint>>,
318318
) -> Result<BTreeSet<Opout>, IndexError<P>> {
319319
Ok(self.provider.opouts_by_outputs(contract_id, outputs)?)
320320
}
@@ -368,7 +368,7 @@ pub trait IndexReadProvider {
368368

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

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

385385
fn opouts_by_terminals(

src/persistence/memory.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1273,14 +1273,18 @@ impl IndexReadProvider for MemIndex {
12731273

12741274
fn contracts_assigning(
12751275
&self,
1276-
outputs: BTreeSet<XOutputSeal>,
1276+
outpoints: BTreeSet<XOutpoint>,
12771277
) -> Result<impl Iterator<Item = ContractId> + '_, Self::Error> {
12781278
Ok(self
12791279
.contract_index
12801280
.iter()
12811281
.flat_map(move |(contract_id, index)| {
1282-
outputs.clone().into_iter().filter_map(|outpoint| {
1283-
if index.outpoint_opouts.contains_key(&outpoint) {
1282+
outpoints.clone().into_iter().filter_map(|outpoint| {
1283+
if index
1284+
.outpoint_opouts
1285+
.keys()
1286+
.any(|seal| seal.to_outpoint() == outpoint)
1287+
{
12841288
Some(*contract_id)
12851289
} else {
12861290
None
@@ -1303,17 +1307,19 @@ impl IndexReadProvider for MemIndex {
13031307
fn opouts_by_outputs(
13041308
&self,
13051309
contract_id: ContractId,
1306-
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
1310+
outpoints: impl IntoIterator<Item = impl Into<XOutpoint>>,
13071311
) -> Result<BTreeSet<Opout>, IndexReadError<Self::Error>> {
13081312
let index = self
13091313
.contract_index
13101314
.get(&contract_id)
13111315
.ok_or(IndexInconsistency::ContractAbsent(contract_id))?;
13121316
let mut opouts = BTreeSet::new();
1313-
for output in outputs.into_iter().map(|o| o.into()) {
1317+
for output in outpoints.into_iter().map(|o| o.into()) {
13141318
let set = index
13151319
.outpoint_opouts
1316-
.get(&output)
1320+
.iter()
1321+
.find(|(seal, _)| seal.to_outpoint() == output)
1322+
.map(|(_, set)| set.to_unconfined())
13171323
.ok_or(IndexInconsistency::OutpointUnknown(output, contract_id))?;
13181324
opouts.extend(set)
13191325
}

src/persistence/stock.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
526526
/// output seals.
527527
pub fn contracts_assigning(
528528
&self,
529-
outputs: impl IntoIterator<Item = impl Into<XOutputSeal>>,
529+
outputs: impl IntoIterator<Item = impl Into<XOutpoint>>,
530530
) -> Result<impl Iterator<Item = ContractId> + '_, StockError<S, H, P>> {
531531
let outputs = outputs
532532
.into_iter()
@@ -1214,25 +1214,27 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
12141214
.map_err(|_| ComposeError::TooManyBlanks)?;
12151215
}
12161216

1217-
let (first_builder, second_builder) =
1217+
let (first_builder, first_inputs, second_builder, second_inputs) =
12181218
match (main_builder.has_inputs(), alt_builder.has_inputs()) {
1219-
(true, true) => (main_builder, Some(alt_builder)),
1220-
(true, false) => (main_builder, None),
1221-
(false, true) => (alt_builder, None),
1219+
(true, true) => (main_builder, main_inputs, Some(alt_builder), alt_inputs),
1220+
(true, false) => (main_builder, main_inputs, None, alt_inputs),
1221+
(false, true) => (alt_builder, alt_inputs, None, main_inputs),
12221222
(false, false) => return Err(ComposeError::InsufficientState.into()),
12231223
};
1224-
let first = TransitionInfo::new(first_builder.complete_transition()?, main_inputs)
1224+
let first = TransitionInfo::new(first_builder.complete_transition()?, first_inputs)
12251225
.map_err(|e| {
12261226
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
12271227
ComposeError::TooManyInputs
12281228
})?;
12291229
let second = if let Some(second_builder) = second_builder {
1230-
Some(TransitionInfo::new(second_builder.complete_transition()?, alt_inputs).map_err(
1231-
|e| {
1232-
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
1233-
ComposeError::TooManyInputs
1234-
},
1235-
)?)
1230+
Some(
1231+
TransitionInfo::new(second_builder.complete_transition()?, second_inputs).map_err(
1232+
|e| {
1233+
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
1234+
ComposeError::TooManyInputs
1235+
},
1236+
)?,
1237+
)
12361238
} else {
12371239
None
12381240
};

0 commit comments

Comments
 (0)