Skip to content

Commit

Permalink
Merge branch 'rm-subschema' into v0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Mar 31, 2024
2 parents addeff9 + fbc979d commit a1d852b
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 499 deletions.
4 changes: 2 additions & 2 deletions src/bin/rgbcore-stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use bp::stl::bp_core_stl;
use commit_verify::stl::commit_verify_stl;
use commit_verify::CommitmentLayout;
use rgb::stl::bp_tx_stl;
use rgb::{SubSchema, Transition, TransitionBundle};
use rgb::{Schema, Transition, TransitionBundle};
use strict_types::stl::{std_stl, strict_types_stl};
use strict_types::typelib::parse_args;
use strict_types::SystemBuilder;
Expand Down Expand Up @@ -93,7 +93,7 @@ Schema vesper lexicon=types+commitments
"
)
.unwrap();
let layout = SubSchema::commitment_layout();
let layout = Schema::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("RGB.Schema").unwrap();
writeln!(file, "{tt}").unwrap();
Expand Down
14 changes: 3 additions & 11 deletions src/contract/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use strict_encoding::{StrictDecode, StrictDumb, StrictEncode};
use crate::{
Assign, AssignmentType, Assignments, AssignmentsRef, ContractId, DataState, ExposedSeal,
ExposedState, Extension, Genesis, GlobalStateType, OpId, Operation, RevealedAttach,
RevealedData, RevealedValue, SchemaId, SubSchema, Transition, TypedAssigns, VoidState,
RevealedData, RevealedValue, Schema, SchemaId, Transition, TypedAssigns, VoidState,
WitnessAnchor, XChain, XOutputSeal, XWitnessId, LIB_NAME_RGB,
};

Expand Down Expand Up @@ -299,8 +299,6 @@ pub struct ContractHistory {
#[getter(as_copy)]
schema_id: SchemaId,
#[getter(as_copy)]
root_schema_id: Option<SchemaId>,
#[getter(as_copy)]
contract_id: ContractId,
#[getter(skip)]
global: TinyOrdMap<GlobalStateType, LargeOrdMap<GlobalOrd, RevealedData>>,
Expand All @@ -315,15 +313,9 @@ impl ContractHistory {
///
/// If genesis violates RGB consensus rules and wasn't checked against the
/// schema before adding to the history.
pub fn with(
schema_id: SchemaId,
root_schema_id: Option<SchemaId>,
contract_id: ContractId,
genesis: &Genesis,
) -> Self {
pub fn with(schema_id: SchemaId, contract_id: ContractId, genesis: &Genesis) -> Self {
let mut state = ContractHistory {
schema_id,
root_schema_id,
contract_id,
global: empty!(),
rights: empty!(),
Expand Down Expand Up @@ -487,7 +479,7 @@ impl ContractHistory {
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct ContractState {
pub schema: SubSchema,
pub schema: Schema,
pub history: ContractHistory,
}

Expand Down
5 changes: 1 addition & 4 deletions src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ pub use operations::{
AssignmentType, AssignmentsSchema, ExtensionSchema, GenesisSchema, GlobalSchema, OpFullType,
OpSchema, OpType, TransitionSchema, ValencySchema, ValencyType,
};
pub use schema::{
ExtensionType, GlobalStateType, RootSchema, Schema, SchemaId, SchemaRoot, SubSchema,
TransitionType,
};
pub use schema::{ExtensionType, GlobalStateType, Schema, SchemaId, TransitionType};
pub use script::{Script, Types, VmType};
pub use state::{FungibleType, GlobalStateSchema, MediaType, StateSchema};
32 changes: 9 additions & 23 deletions src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,6 @@ impl SchemaId {
pub fn to_mnemonic(&self) -> String { self.to_baid58().mnemonic() }
}

pub trait SchemaRoot: Clone + Eq + StrictType + StrictEncode + StrictDecode + Default {
fn schema_id(&self) -> SchemaId;
}
impl SchemaRoot for () {
fn schema_id(&self) -> SchemaId { SchemaId::from_byte_array([0u8; 32]) }
}
impl SchemaRoot for RootSchema {
fn schema_id(&self) -> SchemaId { self.schema_id() }
}
pub type RootSchema = Schema<()>;
pub type SubSchema = Schema<RootSchema>;

#[derive(Clone, Eq, Default, Debug)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
Expand All @@ -163,10 +151,9 @@ pub type SubSchema = Schema<RootSchema>;
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct Schema<Root: SchemaRoot> {
pub struct Schema {
pub ffv: Ffv,
pub flags: ReservedBytes<1, 0>,
pub subset_of: Option<Root>,

pub global_types: TinyOrdMap<GlobalStateType, GlobalStateSchema>,
pub owned_types: TinyOrdMap<AssignmentType, StateSchema>,
Expand All @@ -181,13 +168,12 @@ pub struct Schema<Root: SchemaRoot> {
pub script: Script,
}

impl<Root: SchemaRoot> CommitEncode for Schema<Root> {
impl CommitEncode for Schema {
type CommitmentId = SchemaId;

fn commit_encode(&self, e: &mut CommitEngine) {
e.commit_to_serialized(&self.ffv);
e.commit_to_serialized(&self.flags);
e.commit_to_option(&self.subset_of.as_ref().map(Root::schema_id));

e.commit_to_map(&self.global_types);
e.commit_to_map(&self.owned_types);
Expand All @@ -201,22 +187,22 @@ impl<Root: SchemaRoot> CommitEncode for Schema<Root> {
}
}

impl<Root: SchemaRoot> PartialEq for Schema<Root> {
impl PartialEq for Schema {
fn eq(&self, other: &Self) -> bool { self.schema_id() == other.schema_id() }
}

impl<Root: SchemaRoot> Ord for Schema<Root> {
impl Ord for Schema {
fn cmp(&self, other: &Self) -> Ordering { self.schema_id().cmp(&other.schema_id()) }
}

impl<Root: SchemaRoot> PartialOrd for Schema<Root> {
impl PartialOrd for Schema {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}

impl<Root: SchemaRoot> StrictSerialize for Schema<Root> {}
impl<Root: SchemaRoot> StrictDeserialize for Schema<Root> {}
impl StrictSerialize for Schema {}
impl StrictDeserialize for Schema {}

impl<Root: SchemaRoot> Schema<Root> {
impl Schema {
#[inline]
pub fn schema_id(&self) -> SchemaId { self.commit_id() }

Expand All @@ -230,7 +216,7 @@ impl<Root: SchemaRoot> Schema<Root> {
}
}

impl<Root: SchemaRoot> StrictArmor for Schema<Root> {
impl StrictArmor for Schema {
type Id = SchemaId;
const PLATE_TITLE: &'static str = "RGB SCHEMA";

Expand Down
7 changes: 3 additions & 4 deletions src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ use strict_types::typelib::LibBuilder;
use strict_types::{CompileError, TypeLib};

use crate::{
ContractState, Extension, Genesis, OpCommitment, SubSchema, TransitionBundle, XGrip,
LIB_NAME_RGB,
ContractState, Extension, Genesis, OpCommitment, Schema, TransitionBundle, XGrip, LIB_NAME_RGB,
};

/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB: &str =
"urn:ubideco:stl:5mAFkM5R9wkRErCxG8nC97hqubayp5MaLpuNrupugTYC#bikini-oscar-logic";
"urn:ubideco:stl:BdxvFi2JckXJ3uE4PkJy81BnM7RnbhwA8Mif6c9maP7n#garden-diesel-cable";

fn _rgb_core_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB), tiny_bset! {
Expand All @@ -46,7 +45,7 @@ fn _rgb_core_stl() -> Result<TypeLib, CompileError> {
bp_core_stl().to_dependency(),
aluvm_stl().to_dependency()
})
.transpile::<SubSchema>()
.transpile::<Schema>()
.transpile::<Genesis>()
.transpile::<XGrip>()
.transpile::<TransitionBundle>()
Expand Down
6 changes: 3 additions & 3 deletions src/validation/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::collections::{BTreeMap, BTreeSet};
use std::rc::Rc;

use crate::{
AssetTag, AssignmentType, BundleId, Genesis, OpId, OpRef, Operation, SecretSeal, SubSchema,
AssetTag, AssignmentType, BundleId, Genesis, OpId, OpRef, Operation, Schema, SecretSeal,
TransitionBundle, XChain, XGrip, XWitnessId,
};

Expand All @@ -41,7 +41,7 @@ impl<'consignment, C: ConsignmentApi> CheckedConsignment<'consignment, C> {
impl<'consignment, C: ConsignmentApi> ConsignmentApi for CheckedConsignment<'consignment, C> {
type Iter<'placeholder> = C::Iter<'placeholder>;

fn schema(&self) -> &SubSchema { self.0.schema() }
fn schema(&self) -> &Schema { self.0.schema() }

fn asset_tags(&self) -> &BTreeMap<AssignmentType, AssetTag> { self.0.asset_tags() }

Expand Down Expand Up @@ -78,7 +78,7 @@ pub trait ConsignmentApi {
type Iter<'a>: Iterator<Item = BundleId>;

/// Returns reference to the schema object used by the consignment.
fn schema(&self) -> &SubSchema;
fn schema(&self) -> &Schema;

/// Asset tags uses in the confidential asset validation.
fn asset_tags(&self) -> &BTreeMap<AssignmentType, AssetTag>;
Expand Down
8 changes: 2 additions & 6 deletions src/validation/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ use crate::validation::{CheckedConsignment, ConsignmentApi, VirtualMachine};
use crate::{
validation, AssetTag, AssignmentType, Assignments, AssignmentsRef, ContractId, ExposedSeal,
GlobalState, GlobalStateSchema, GlobalValues, GraphSeal, Inputs, OpFullType, OpId, OpRef,
Operation, Opout, Schema, SchemaRoot, TransitionType, TypedAssigns, Valencies,
Operation, Opout, Schema, TransitionType, TypedAssigns, Valencies,
};

impl<Root: SchemaRoot> Schema<Root> {
impl Schema {
pub fn validate_state<'validator, 'consignment, C: ConsignmentApi>(
&'validator self,
consignment: &'validator CheckedConsignment<'consignment, C>,
Expand Down Expand Up @@ -167,7 +167,6 @@ impl<Root: SchemaRoot> Schema<Root> {
let op_info = OpInfo::with(
consignment.genesis().contract_id(),
id,
self.subset_of.is_some(),
&op,
&prev_state,
&redeemed,
Expand Down Expand Up @@ -427,7 +426,6 @@ impl<Root: SchemaRoot> Schema<Root> {
}

pub struct OpInfo<'op> {
pub subschema: bool,
pub contract_id: ContractId,
pub id: OpId,
pub ty: OpFullType,
Expand All @@ -444,15 +442,13 @@ impl<'op> OpInfo<'op> {
pub fn with(
contract_id: ContractId,
id: OpId,
subschema: bool,
op: &'op OpRef<'op>,
prev_state: &'op Assignments<GraphSeal>,
redeemed: &'op Valencies,
asset_tags: &'op BTreeMap<AssignmentType, AssetTag>,
) -> Self {
OpInfo {
id,
subschema,
contract_id,
ty: op.full_type(),
asset_tags,
Expand Down
Loading

0 comments on commit a1d852b

Please sign in to comment.