Skip to content

Commit 624e84c

Browse files
committed
persistence: add access to type system
1 parent 46694a5 commit 624e84c

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/persistence/stash.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,15 @@ impl<P: StashProvider> Stash<P> {
304304
Ok(Scripts::from_checked(scripts))
305305
}
306306

307-
pub(super) fn extract<'a>(
307+
pub(super) fn type_system(&self, iface: &Iface) -> Result<TypeSystem, StashError<P>> {
308+
Ok(self
309+
.provider
310+
.type_system()
311+
.map_err(StashError::ReadProvider)?
312+
.extract(iface.types())?)
313+
}
314+
315+
pub(super) fn types_scripts<'a>(
308316
&self,
309317
schema: &Schema,
310318
ifaces: impl IntoIterator<Item = &'a Iface>,
@@ -344,7 +352,7 @@ impl<P: StashProvider> Stash<P> {
344352
.get(iface_id)
345353
.ok_or(StashDataError::NoIfaceImpl(schema_id, iface_id))?;
346354

347-
let (types, scripts) = self.extract(&schema_ifaces.schema, [iface])?;
355+
let (types, scripts) = self.types_scripts(&schema_ifaces.schema, [iface])?;
348356

349357
let builder = ContractBuilder::with(
350358
issuer,
@@ -370,7 +378,7 @@ impl<P: StashProvider> Stash<P> {
370378
.get(iface.iface_id())
371379
.ok_or(StashDataError::NoIfaceImpl(schema.schema_id(), iface.iface_id()))?;
372380

373-
let (types, _) = self.extract(&schema_ifaces.schema, [iface])?;
381+
let types = self.type_system(iface)?;
374382
let scripts = self.scripts(iimpl.state_abi.lib_ids())?;
375383

376384
let builder = if let Some(transition_name) = transition_name {
@@ -409,7 +417,7 @@ impl<P: StashProvider> Stash<P> {
409417
if schema_ifaces.iimpls.is_empty() {
410418
return Err(StashDataError::NoIfaceImpl(schema.schema_id(), iface.iface_id()).into());
411419
}
412-
let (types, _) = self.extract(&schema_ifaces.schema, [iface])?;
420+
let types = self.type_system(iface)?;
413421

414422
let builder = if let Some(iimpl) = schema_ifaces.get(iface.iface_id()) {
415423
TransitionBuilder::blank_transition(

src/persistence/stock.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use rgb::{
3939
SchemaId, SecretSeal, Transition, TxoSeal, XChain, XOutpoint, XOutputSeal, XWitnessId,
4040
};
4141
use strict_encoding::FieldName;
42+
use strict_types::TypeSystem;
4243

4344
use super::{
4445
ContractStateRead, Index, IndexError, IndexInconsistency, IndexProvider, IndexReadProvider,
@@ -494,6 +495,9 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
494495
pub fn iface(&self, iface: impl Into<IfaceRef>) -> Result<&Iface, StockError<S, H, P>> {
495496
Ok(self.stash.iface(iface)?)
496497
}
498+
pub fn type_system(&self, iface: &Iface) -> Result<TypeSystem, StockError<S, H, P>> {
499+
Ok(self.stash.type_system(iface)?)
500+
}
497501
pub fn schemata(&self) -> Result<impl Iterator<Item = SchemaInfo> + '_, StockError<S, H, P>> {
498502
Ok(self.stash.schemata()?.map(SchemaInfo::with))
499503
}
@@ -573,7 +577,7 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
573577
let iimpl = self.stash.impl_for::<C>(schema_ifaces)?;
574578

575579
let iface = self.stash.iface(iimpl.iface_id)?;
576-
let (types, _) = self.stash.extract(&schema_ifaces.schema, [iface])?;
580+
let types = self.stash.type_system(iface)?;
577581

578582
Ok(C::Wrapper::with(ContractIface {
579583
state,
@@ -599,7 +603,7 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
599603
ContractIfaceError::NoAbstractImpl(iface_id, schema_ifaces.schema.schema_id())
600604
})?;
601605

602-
let (types, _) = self.stash.extract(&schema_ifaces.schema, [iface])?;
606+
let types = self.stash.type_system(iface)?;
603607

604608
Ok(ContractIface {
605609
state,
@@ -678,7 +682,9 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
678682
kit.iimpls
679683
.extend(schema_ifaces.iimpls.values().cloned())
680684
.expect("type guarantees");
681-
let (types, scripts) = self.stash.extract(&schema_ifaces.schema, &kit.ifaces)?;
685+
let (types, scripts) = self
686+
.stash
687+
.types_scripts(&schema_ifaces.schema, &kit.ifaces)?;
682688
kit.scripts
683689
.extend(scripts.into_values())
684690
.expect("type guarantees");
@@ -843,7 +849,9 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
843849
let terminals =
844850
Confined::try_from(terminals).map_err(|_| ConsignError::TooManyTerminals)?;
845851

846-
let (types, scripts) = self.stash.extract(&schema_ifaces.schema, ifaces.keys())?;
852+
let (types, scripts) = self
853+
.stash
854+
.types_scripts(&schema_ifaces.schema, ifaces.keys())?;
847855
let scripts = Confined::from_iter_checked(scripts.into_values());
848856
let supplements =
849857
Confined::try_from(supplements).map_err(|_| ConsignError::TooManySupplements)?;

0 commit comments

Comments
 (0)