Skip to content

Commit

Permalink
fix: blank transition to other iimpls
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Jan 9, 2024
1 parent cc84079 commit 9e7b89d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/interface/rgb21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl Allocation {
pub fn with(index: TokenIndex, fraction: OwnedFraction) -> Allocation {
Allocation(index, fraction)
}

pub fn token_index(self) -> TokenIndex { self.0 }

pub fn fraction(self) -> OwnedFraction { self.1 }
}

impl StrictSerialize for Allocation {}
Expand Down
10 changes: 9 additions & 1 deletion src/persistence/hoard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ use strict_encoding::TypeName;

use crate::accessors::{MergeReveal, MergeRevealError};
use crate::containers::{Cert, Consignment, ContentId, ContentSigs};
use crate::interface::{rgb20, ContractSuppl, Iface, IfaceId, IfacePair, SchemaIfaces};
use crate::interface::{
rgb20, rgb21, rgb25, ContractSuppl, Iface, IfaceId, IfacePair, SchemaIfaces,
};
use crate::persistence::{InventoryError, Stash, StashError, StashInconsistency};
use crate::LIB_NAME_RGB_STD;

Expand Down Expand Up @@ -86,10 +88,16 @@ impl Hoard {
pub fn preset() -> Self {
let rgb20 = rgb20();
let rgb20_id = rgb20.iface_id();
let rgb21 = rgb21();
let rgb21_id = rgb21.iface_id();
let rgb25 = rgb25();
let rgb25_id = rgb25.iface_id();
Hoard {
schemata: none!(),
ifaces: tiny_bmap! {
rgb20_id => rgb20,
rgb21_id => rgb21,
rgb25_id => rgb25,
},
geneses: none!(),
suppl: none!(),
Expand Down
27 changes: 21 additions & 6 deletions src/persistence/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,28 @@ pub trait Inventory: Deref<Target = Self::Stash> {
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 =
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()) {
TransitionBuilder::blank_transition(iface.clone(), schema.clone(), iimpl.clone())
.expect("internal inconsistency");
.expect("internal inconsistency")
} else {
let (default_iface_id, default_iimpl) = schema_ifaces.iimpls.first_key_value().unwrap();
let default_iface = self.iface_by_id(*default_iface_id)?;

TransitionBuilder::blank_transition(
default_iface.clone(),
schema.clone(),
default_iimpl.clone(),
)
.expect("internal inconsistency")
};

Ok(builder)
}

Expand Down

0 comments on commit 9e7b89d

Please sign in to comment.