Skip to content

Commit 79e9307

Browse files
committed
add fast-forward version codes. Closes #140
1 parent 9cd15ff commit 79e9307

File tree

3 files changed

+36
-53
lines changed

3 files changed

+36
-53
lines changed

src/contract/operations.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use super::{GlobalState, TypedState};
3636
use crate::schema::{
3737
self, ExtensionType, OpFullType, OpType, OwnedStateType, SchemaId, TransitionType,
3838
};
39-
use crate::LIB_NAME_RGB;
39+
use crate::{Ffv, LIB_NAME_RGB};
4040

4141
/// RGB contract node output pointer, defined by the node ID and output number.
4242
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
@@ -218,6 +218,7 @@ pub trait Operation: AsAny {
218218
#[strict_type(lib = LIB_NAME_RGB)]
219219
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
220220
pub struct Genesis {
221+
pub ffv: Ffv,
221222
pub schema_id: SchemaId,
222223
pub chain: Chain,
223224
pub metadata: Option<TinyVec<u8>>,
@@ -231,6 +232,7 @@ pub struct Genesis {
231232
#[strict_type(lib = LIB_NAME_RGB)]
232233
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
233234
pub struct Extension {
235+
pub ffv: Ffv,
234236
pub extension_type: ExtensionType,
235237
pub contract_id: ContractId,
236238
pub metadata: Option<TinyVec<u8>>,
@@ -245,6 +247,7 @@ pub struct Extension {
245247
#[strict_type(lib = LIB_NAME_RGB)]
246248
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
247249
pub struct Transition {
250+
pub ffv: Ffv,
248251
pub transition_type: TransitionType,
249252
pub metadata: Option<TinyVec<u8>>,
250253
pub global_state: GlobalState,

src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,32 @@ pub mod prelude {
6666
}
6767

6868
pub use prelude::*;
69+
70+
/// Fast-forward version code
71+
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Default, Debug, Display)]
72+
#[display("v0.10.0+{0}")]
73+
#[derive(StrictType, StrictEncode)]
74+
#[strict_type(lib = LIB_NAME_RGB)]
75+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
76+
pub struct Ffv(u16);
77+
78+
mod _ffv {
79+
use strict_encoding::{DecodeError, ReadTuple, StrictDecode, TypedRead};
80+
81+
use crate::Ffv;
82+
83+
impl StrictDecode for Ffv {
84+
fn strict_decode(reader: &mut impl TypedRead) -> Result<Self, DecodeError> {
85+
let ffv = reader.read_tuple(|r| r.read_field().map(Self))?;
86+
if ffv != Ffv::default() {
87+
Err(DecodeError::DataIntegrityError(format!(
88+
"unsupported fast-forward version code belonging to a future RGB version. \
89+
Please update your software, or, if the problem persists, contact your \
90+
vendor providing the following version information: {ffv}"
91+
)))
92+
} else {
93+
Ok(ffv)
94+
}
95+
}
96+
}
97+
}

src/schema/schema.rs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,20 @@
2121
// limitations under the License.
2222

2323
use std::cmp::Ordering;
24-
use std::io;
2524
use std::str::FromStr;
2625

2726
use amplify::confinement::{MediumVec, TinyOrdMap, TinyOrdSet};
28-
use amplify::flags::FlagVec;
2927
use amplify::{Bytes32, RawArray};
3028
use baid58::{Baid58ParseError, FromBaid58, ToBaid58};
3129
use commit_verify::{CommitStrategy, CommitmentId};
32-
use strict_encoding::{
33-
DecodeError, ReadTuple, StrictDecode, StrictEncode, StrictProduct, StrictTuple, StrictType,
34-
TypeName, TypedRead, TypedWrite, WriteTuple,
35-
};
30+
use strict_encoding::{StrictDecode, StrictEncode, StrictType};
3631
use strict_types::SemId;
3732

3833
use super::{
3934
ExtensionSchema, GenesisSchema, OwnedStateType, Script, StateSchema, TransitionSchema,
4035
ValencyType,
4136
};
42-
use crate::LIB_NAME_RGB;
37+
use crate::{Ffv, LIB_NAME_RGB};
4338

4439
pub type GlobalStateType = u16;
4540
pub type ExtensionType = u16;
@@ -80,18 +75,7 @@ impl FromStr for SchemaId {
8075
#[strict_type(lib = LIB_NAME_RGB)]
8176
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
8277
pub struct Schema {
83-
/// Feature flags control which of the available RGB features are allowed
84-
/// for smart contracts created under this schema.
85-
///
86-
/// NB: This is not the same as RGB protocol versioning: feature flag set
87-
/// is specific to a particular RGB protocol version. The only currently
88-
/// defined RGB version is RGBv1; future versions may change the whole
89-
/// structure of Schema data, use of feature flags, re-define their meaning
90-
/// or do other backward-incompatible changes (RGB protocol versions are
91-
/// not interoperable and backward-incompatible by definitions and the
92-
/// nature of client-side-validation which does not allow upgrades).
93-
#[cfg_attr(feature = "serde", serde(skip))]
94-
pub rgb_features: SchemaFlags,
78+
pub ffv: Ffv,
9579
pub subset_of: Option<SchemaId>,
9680

9781
pub global_types: TinyOrdMap<GlobalStateType, SemId>,
@@ -133,39 +117,6 @@ impl Schema {
133117
pub fn schema_id(&self) -> SchemaId { self.commitment_id() }
134118
}
135119

136-
#[derive(Clone, Eq, PartialEq, Hash, Debug, Display, Default)]
137-
#[display(inner)]
138-
pub struct SchemaFlags(FlagVec);
139-
140-
impl StrictType for SchemaFlags {
141-
const STRICT_LIB_NAME: &'static str = LIB_NAME_RGB;
142-
fn strict_name() -> Option<TypeName> { Some(tn!("SchemaFlags")) }
143-
}
144-
impl StrictProduct for SchemaFlags {}
145-
impl StrictTuple for SchemaFlags {
146-
const FIELD_COUNT: u8 = 1;
147-
}
148-
impl StrictEncode for SchemaFlags {
149-
fn strict_encode<W: TypedWrite>(&self, writer: W) -> io::Result<W> {
150-
writer.write_tuple::<Self>(|w| Ok(w.write_field(&self.0.shrunk().into_inner())?.complete()))
151-
}
152-
}
153-
impl StrictDecode for SchemaFlags {
154-
fn strict_decode(reader: &mut impl TypedRead) -> Result<Self, DecodeError> {
155-
let flags =
156-
reader.read_tuple(|r| r.read_field().map(|vec| Self(FlagVec::from_inner(vec))))?;
157-
if !flags.0.is_empty() {
158-
Err(DecodeError::DataIntegrityError(format!(
159-
"unsupported schema flags potentially belonging to a future RGB version. Please \
160-
update your software, or, if the problem persists, contact your vendor providing \
161-
the following flag information: {flags}"
162-
)))
163-
} else {
164-
Ok(flags)
165-
}
166-
}
167-
}
168-
169120
#[cfg(test)]
170121
mod test {
171122
use strict_encoding::StrictDumb;

0 commit comments

Comments
 (0)