@@ -34,10 +34,10 @@ use amplify::hex;
3434use strict_encoding:: { StrictDecode , StrictDumb , StrictEncode } ;
3535
3636use crate :: {
37- Assign , AssignmentType , Assignments , AssignmentsRef , ContractId , ExposedSeal , ExposedState ,
38- Extension , Genesis , GlobalStateType , OpId , Operation , RevealedAttach , RevealedData ,
39- RevealedValue , SchemaId , SubSchema , Transition , TypedAssigns , VoidState , WitnessAnchor ,
40- WitnessId , XChain , XOutputSeal , LIB_NAME_RGB ,
37+ Assign , AssignmentType , Assignments , AssignmentsRef , ContractId , DataState , ExposedSeal ,
38+ ExposedState , Extension , Genesis , GlobalStateType , OpId , Operation , RevealedAttach ,
39+ RevealedData , RevealedValue , SchemaId , SubSchema , Transition , TypedAssigns , VoidState ,
40+ WitnessAnchor , WitnessId , XChain , XOutputSeal , LIB_NAME_RGB ,
4141} ;
4242
4343#[ derive( Copy , Clone , Ord , PartialOrd , Eq , PartialEq , Hash , Debug , Display ) ]
@@ -92,22 +92,59 @@ impl FromStr for Opout {
9292 }
9393}
9494
95- #[ derive( Clone , Eq , Debug ) ]
95+ /// Trait used by contract state. Unlike [`ExposedState`] it doesn't allow
96+ /// concealment of the state, i.e. may contain incomplete data without blinding
97+ /// factors, asset tags etc.
98+ pub trait KnownState : Debug + StrictDumb + StrictEncode + StrictDecode + Eq + Clone { }
99+ impl < S : ExposedState > KnownState for S { }
100+
101+ impl KnownState for ( ) { }
102+ impl KnownState for DataState { }
103+
104+ #[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash , Debug , Display , From ) ]
105+ #[ derive( StrictType , StrictDumb , StrictEncode , StrictDecode ) ]
106+ #[ strict_type( lib = LIB_NAME_RGB , tags = custom) ]
107+ #[ cfg_attr(
108+ feature = "serde" ,
109+ derive( Serialize , Deserialize ) ,
110+ serde( crate = "serde_crate" , rename_all = "camelCase" )
111+ ) ]
112+ pub enum AssignmentWitness {
113+ #[ display( "~" ) ]
114+ #[ strict_type( tag = 0 , dumb) ]
115+ Absent ,
116+
117+ #[ from]
118+ #[ display( inner) ]
119+ #[ strict_type( tag = 1 ) ]
120+ Present ( WitnessId ) ,
121+ }
122+
123+ impl From < Option < WitnessId > > for AssignmentWitness {
124+ fn from ( value : Option < WitnessId > ) -> Self {
125+ match value {
126+ None => AssignmentWitness :: Absent ,
127+ Some ( id) => AssignmentWitness :: Present ( id) ,
128+ }
129+ }
130+ }
131+
132+ #[ derive( Copy , Clone , Eq , Debug ) ]
96133#[ derive( StrictType , StrictDumb , StrictEncode , StrictDecode ) ]
97134#[ strict_type( lib = LIB_NAME_RGB ) ]
98135#[ cfg_attr(
99136 feature = "serde" ,
100137 derive( Serialize , Deserialize ) ,
101138 serde( crate = "serde_crate" , rename_all = "camelCase" )
102139) ]
103- pub struct OutputAssignment < State : ExposedState > {
140+ pub struct OutputAssignment < State : KnownState > {
104141 pub opout : Opout ,
105142 pub seal : XOutputSeal ,
106143 pub state : State ,
107- pub witness : Option < WitnessId > ,
144+ pub witness : AssignmentWitness ,
108145}
109146
110- impl < State : ExposedState > PartialEq for OutputAssignment < State > {
147+ impl < State : KnownState > PartialEq for OutputAssignment < State > {
111148 fn eq ( & self , other : & Self ) -> bool {
112149 if self . opout == other. opout &&
113150 ( self . seal != other. seal ||
@@ -127,11 +164,11 @@ impl<State: ExposedState> PartialEq for OutputAssignment<State> {
127164 }
128165}
129166
130- impl < State : ExposedState > PartialOrd for OutputAssignment < State > {
167+ impl < State : KnownState > PartialOrd for OutputAssignment < State > {
131168 fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > { Some ( self . cmp ( other) ) }
132169}
133170
134- impl < State : ExposedState > Ord for OutputAssignment < State > {
171+ impl < State : KnownState > Ord for OutputAssignment < State > {
135172 fn cmp ( & self , other : & Self ) -> Ordering {
136173 if self == other {
137174 return Ordering :: Equal ;
@@ -140,7 +177,7 @@ impl<State: ExposedState> Ord for OutputAssignment<State> {
140177 }
141178}
142179
143- impl < State : ExposedState > OutputAssignment < State > {
180+ impl < State : KnownState > OutputAssignment < State > {
144181 /// # Panics
145182 ///
146183 /// If the processing is done on invalid stash data, the seal is
@@ -160,7 +197,7 @@ impl<State: ExposedState> OutputAssignment<State> {
160197 match anchor's chain",
161198 ) ,
162199 state,
163- witness : Some ( witness_id) ,
200+ witness : witness_id. into ( ) ,
164201 }
165202 }
166203
@@ -182,7 +219,17 @@ impl<State: ExposedState> OutputAssignment<State> {
182219 information since it comes from genesis or extension",
183220 ) ,
184221 state,
185- witness : None ,
222+ witness : AssignmentWitness :: Absent ,
223+ }
224+ }
225+
226+ pub fn transmute < S : KnownState > ( self ) -> OutputAssignment < S >
227+ where S : From < State > {
228+ OutputAssignment {
229+ opout : self . opout ,
230+ seal : self . seal ,
231+ state : self . state . into ( ) ,
232+ witness : self . witness ,
186233 }
187234 }
188235}
@@ -234,11 +281,6 @@ impl GlobalOrd {
234281 }
235282}
236283
237- pub type RightsOutput = OutputAssignment < VoidState > ;
238- pub type FungibleOutput = OutputAssignment < RevealedValue > ;
239- pub type DataOutput = OutputAssignment < RevealedData > ;
240- pub type AttachOutput = OutputAssignment < RevealedAttach > ;
241-
242284/// Contract history accumulates raw data from the contract history, extracted
243285/// from a series of consignments over the time. It does consensus ordering of
244286/// the state data, but it doesn't interpret or validates the state against the
@@ -262,10 +304,10 @@ pub struct ContractHistory {
262304 contract_id : ContractId ,
263305 #[ getter( skip) ]
264306 global : TinyOrdMap < GlobalStateType , LargeOrdMap < GlobalOrd , RevealedData > > ,
265- rights : LargeOrdSet < RightsOutput > ,
266- fungibles : LargeOrdSet < FungibleOutput > ,
267- data : LargeOrdSet < DataOutput > ,
268- attach : LargeOrdSet < AttachOutput > ,
307+ rights : LargeOrdSet < OutputAssignment < VoidState > > ,
308+ fungibles : LargeOrdSet < OutputAssignment < RevealedValue > > ,
309+ data : LargeOrdSet < OutputAssignment < RevealedData > > ,
310+ attach : LargeOrdSet < OutputAssignment < RevealedAttach > > ,
269311}
270312
271313impl ContractHistory {
0 commit comments