From c436445b689a1d48d098cc3bac012cf863f9870e Mon Sep 17 00:00:00 2001 From: Armando Dutra Date: Thu, 26 Oct 2023 02:05:20 -0300 Subject: [PATCH] fix: generate blank transition to others iimpls --- std/src/persistence/inventory.rs | 33 +++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/std/src/persistence/inventory.rs b/std/src/persistence/inventory.rs index 0786e595..abd7eb36 100644 --- a/std/src/persistence/inventory.rs +++ b/std/src/persistence/inventory.rs @@ -410,13 +410,32 @@ pub trait Inventory: Deref { let schema_ifaces = self.contract_schema(contract_id)?; let iface = self.iface_by_name(&iface.into())?; let schema = &schema_ifaces.schema; - let iimpl = schema_ifaces - .iimpls - .get(&iface.iface_id()) - .ok_or(DataError::NoIfaceImpl(schema.schema_id(), iface.iface_id()))?; - let builder = - TransitionBuilder::blank_transition(iface.clone(), schema.clone(), iimpl.clone()) - .expect("internal inconsistency"); + + if schema_ifaces.iimpls.is_empty() { + return Err(InventoryError::DataError(DataError::NoIfaceImpl( + schema.schema_id(), + iface.iface_id(), + ))); + } + + let builder = if let Some(iimpl) = schema_ifaces.iimpls.get(&iface.iface_id()) { + let builder = + TransitionBuilder::blank_transition(iface.clone(), schema.clone(), iimpl.clone()) + .expect("internal inconsistency"); + builder + } else { + let (default_iface_id, default_iimpl) = schema_ifaces.iimpls.first_key_value().unwrap(); + let default_iface = self.iface_by_id(default_iface_id.clone())?; + + let builder = TransitionBuilder::blank_transition( + default_iface.clone(), + schema.clone(), + default_iimpl.clone(), + ) + .expect("internal inconsistency"); + builder + }; + Ok(builder) }