Skip to content

Commit

Permalink
Merge branch 'fix/rgb-252' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 12, 2024
2 parents 670a7b6 + 94b5ebc commit 81ab531
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 286 deletions.
58 changes: 46 additions & 12 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;

use amplify::confinement::SmallVec;
use commit_verify::Conceal;
Expand All @@ -39,18 +40,50 @@ use crate::LIB_NAME_RGB_STD;
/// Trait used by contract state. Unlike [`ExposedState`] it doesn't allow
/// concealment of the state, i.e. may contain incomplete data without blinding
/// factors, asset tags etc.
pub trait KnownState: Debug + StrictDumb + StrictEncode + StrictDecode + Eq + Clone {}

impl KnownState for () {}
impl KnownState for VoidState {}
impl KnownState for DataState {}
impl KnownState for Amount {}
impl KnownState for AttachState {}
impl KnownState for RevealedValue {}
impl KnownState for RevealedData {}
impl KnownState for RevealedAttach {}

#[derive(Copy, Clone, Eq, Debug)]
pub trait KnownState: Debug + StrictDumb + StrictEncode + StrictDecode + Eq + Clone + Hash {
const IS_FUNGIBLE: bool;
}

impl KnownState for () {
const IS_FUNGIBLE: bool = false;
}
impl KnownState for VoidState {
const IS_FUNGIBLE: bool = false;
}
impl KnownState for DataState {
const IS_FUNGIBLE: bool = false;
}
impl KnownState for Amount {
const IS_FUNGIBLE: bool = true;
}
impl KnownState for AttachState {
const IS_FUNGIBLE: bool = false;
}
impl KnownState for RevealedValue {
const IS_FUNGIBLE: bool = true;
}
impl KnownState for RevealedData {
const IS_FUNGIBLE: bool = false;
}
impl KnownState for RevealedAttach {
const IS_FUNGIBLE: bool = false;
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct WitnessInfo {
pub id: XWitnessId,
pub ord: WitnessOrd,
}

#[allow(clippy::derived_hash_with_manual_eq)]
#[derive(Copy, Clone, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
#[cfg_attr(
Expand Down Expand Up @@ -142,6 +175,7 @@ impl<State: KnownState> OutputAssignment<State> {
}
}

/// Transmutes output assignment from one form of state to another
pub fn transmute<S: KnownState + From<State>>(self) -> OutputAssignment<S> {
OutputAssignment {
opout: self.opout,
Expand Down
2 changes: 1 addition & 1 deletion src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod assignments;
mod bundle;
mod merge_reveal;

pub use assignments::{KnownState, OutputAssignment, TypedAssignsExt};
pub use assignments::{KnownState, OutputAssignment, TypedAssignsExt, WitnessInfo};
pub use bundle::{BundleExt, RevealError};
pub use merge_reveal::{MergeReveal, MergeRevealError};
use rgb::vm::OrdOpRef;
Expand Down
Loading

0 comments on commit 81ab531

Please sign in to comment.