Skip to content

Commit

Permalink
iface: remove OwnedIface, change owned state inheritance mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 17, 2024
1 parent 10ee5cc commit 46694a5
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 354 deletions.
14 changes: 4 additions & 10 deletions src/interface/contractum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ use rgb::Occurrences;
use strict_encoding::{FieldName, TypeName, VariantName};
use strict_types::{SemId, SymbolicSys};

use super::{
ArgMap, ExtensionIface, GenesisIface, Iface, IfaceId, Modifier, OwnedIface, TransitionIface,
};
use super::{ArgMap, ExtensionIface, GenesisIface, Iface, IfaceId, Modifier, TransitionIface};

struct ArgMapDisplay<'a>(&'a ArgMap);

Expand Down Expand Up @@ -266,13 +264,9 @@ impl<'a> Display for IfaceDisplay<'a> {
write!(f, "{fname}")?;
sugar(f, a.required, a.multiple)?;
f.write_str(": ")?;
match a.owned_state {
OwnedIface::Any => write!(f, "AnyType")?,
OwnedIface::Amount => write!(f, "Zk64")?,
OwnedIface::AnyData => write!(f, "Any")?,
OwnedIface::AnyAttach => write!(f, "AnyAttachment")?,
OwnedIface::Rights => write!(f, "Rights")?,
OwnedIface::Data(id) => resolve(f, self.types, id)?,
match a.state_ty {
None => write!(f, "T any => T")?,
Some(id) => resolve(f, self.types, id)?,
}
writeln!(f)?;
}
Expand Down
47 changes: 9 additions & 38 deletions src/interface/iface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,60 +200,35 @@ impl GlobalIface {
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct AssignIface {
pub owned_state: OwnedIface,
pub state_ty: Option<SemId>,
pub attach: Option<bool>,
pub public: bool,
pub required: bool,
pub multiple: bool,
}

impl AssignIface {
pub fn public(owned_state: OwnedIface, req: Req) -> Self {
pub fn public(state_ty: Option<SemId>, attach: Option<bool>, req: Req) -> Self {
AssignIface {
owned_state,
state_ty,
attach,
public: true,
required: req.is_required(),
multiple: req.is_multiple(),
}
}

pub fn private(owned_state: OwnedIface, req: Req) -> Self {
pub fn private(state_ty: Option<SemId>, attach: Option<bool>, req: Req) -> Self {
AssignIface {
owned_state,
state_ty,
attach,
public: false,
required: req.is_required(),
multiple: req.is_multiple(),
}
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD, tags = order)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub enum OwnedIface {
#[strict_type(dumb)]
Any,
Rights,
Amount,
AnyData,
AnyAttach,
Data(SemId),
}

impl OwnedIface {
pub fn sem_id(&self) -> Option<SemId> {
if let Self::Data(id) = self {
Some(*id)
} else {
None
}
}
}

pub type ArgMap = TinyOrdMap<FieldName, Occurrences>;

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display, Default)]
Expand Down Expand Up @@ -434,11 +409,7 @@ impl Iface {
.values()
.copied()
.chain(self.global_state.values().filter_map(|i| i.sem_id))
.chain(
self.assignments
.values()
.filter_map(|i| i.owned_state.sem_id()),
)
.chain(self.assignments.values().filter_map(|i| i.state_ty))
}

pub fn find_abstractable_impl<'a>(
Expand Down
16 changes: 2 additions & 14 deletions src/interface/inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rgb::{
use strict_encoding::{FieldName, TypeName};

use crate::interface::{
ExtensionIface, GenesisIface, Iface, IfaceImpl, Modifier, OpName, OwnedIface, TransitionIface,
ExtensionIface, GenesisIface, Iface, IfaceImpl, Modifier, OpName, TransitionIface,
};

#[derive(Clone, PartialEq, Eq, Debug, Display, From)]
Expand Down Expand Up @@ -273,18 +273,6 @@ pub enum ExtensionError {
InheritanceOverflow,
}

impl OwnedIface {
pub fn is_superset(self, other: OwnedIface) -> bool {
if self == Self::Any {
return true;
}
if self == Self::AnyData && matches!(other, Self::Data(_)) {
return true;
}
self == other
}
}

impl Modifier {
pub fn is_final(self) -> bool { self == Self::Final }
pub fn can_be_overridden_by(self, other: Modifier) -> bool {
Expand Down Expand Up @@ -401,7 +389,7 @@ impl Iface {
}
}
Some(orig) => {
if !orig.owned_state.is_superset(e.owned_state) {
if orig.state_ty.is_some() && orig.state_ty != e.state_ty {
errors.push(ExtensionError::AssignmentType(name));
} else if orig.required & !e.required {
errors.push(ExtensionError::AssignmentOcc(name));
Expand Down
2 changes: 1 addition & 1 deletion src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use contractum::IfaceDisplay;
pub use filter::{AssignmentsFilter, FilterExclude, FilterIncludeAll};
pub use iface::{
ArgMap, AssignIface, ExtensionIface, GenesisIface, GlobalIface, Iface, IfaceClass, IfaceId,
IfaceInconsistency, IfaceRef, IfaceWrapper, Modifier, OpName, OwnedIface, Req, TransitionIface,
IfaceInconsistency, IfaceRef, IfaceWrapper, Modifier, OpName, Req, TransitionIface,
ValencyIface,
};
pub use iimpl::{IfaceImpl, ImplId, NamedField, NamedType, NamedVariant, SchemaTypeIndex};
Expand Down
4 changes: 2 additions & 2 deletions src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ pub const LIB_NAME_RGB_STORAGE: &str = "RGBStorage";
/// Strict types id for the library providing standard data types which may be
/// used in RGB smart contracts.
pub const LIB_ID_RGB_STORAGE: &str =
"stl:RMDj!yyo-ca0Rmdl-pBBc50W-ciu1!P3-U8gHIqL-0Y83X50#memo-ballet-fresh";
"stl:lnl6QOG0-EYfOLKP-MHdEyA3-$cyUNuc-F3XmU!W-0glc1M0#alaska-phone-bagel";

/// Strict types id for the library representing of RGB StdLib data types.
pub const LIB_ID_RGB_STD: &str =
"stl:vdvotNKl-wGrtjuT-Q4qXt4U-UVQlDMB-ONCuwLd-ORBWRTw#zebra-twist-tango";
"stl:yMGmidPl-LcWFyh!-W6sQ3K5-JQ8evpO-BGuI!lA-0htx!kg#chemist-enjoy-sound";

#[allow(dead_code)]
#[derive(Debug, From)]
Expand Down
Loading

0 comments on commit 46694a5

Please sign in to comment.