Skip to content

Commit

Permalink
contract: add timestamp and issuer to genesis
Browse files Browse the repository at this point in the history
Implements RGB-WG/RFC#1
and RGB-WG/RFC#2
  • Loading branch information
dr-orlovsky committed Mar 4, 2024
1 parent 916ff4f commit 1342202
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 202 deletions.
4 changes: 4 additions & 0 deletions src/contract/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ impl TransitionBundle {
#[strict_type(lib = LIB_NAME_RGB)]
pub struct BaseCommitment {
pub schema_id: SchemaId,
pub timestamp: i64,
pub testnet: bool,
pub alt_layers1: StrictHash,
pub issuer: StrictHash,
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -279,8 +281,10 @@ impl Genesis {
pub fn commit(&self) -> OpCommitment {
let base = BaseCommitment {
schema_id: self.schema_id,
timestamp: self.timestamp,

Check warning on line 284 in src/contract/commit.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/commit.rs#L284

Added line #L284 was not covered by tests
testnet: self.testnet,
alt_layers1: self.alt_layers1.commit_id(),
issuer: self.issuer.commit_id(),

Check warning on line 287 in src/contract/commit.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/commit.rs#L287

Added line #L287 was not covered by tests
};
OpCommitment {
ffv: self.ffv,
Expand Down
3 changes: 2 additions & 1 deletion src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub use fungible::{
};
pub use global::{GlobalState, GlobalValues};
pub use operations::{
Extension, Genesis, Input, Inputs, Metadata, OpRef, Operation, Redeemed, Transition, Valencies,
Extension, Genesis, Input, Inputs, Issuer, Metadata, OpRef, Operation, Redeemed, Transition,
Valencies,
};
pub use seal::{
ExposedSeal, GenesisSeal, GraphSeal, OutputSeal, SecretSeal, TxoSeal, WitnessId, WitnessOrd,
Expand Down
22 changes: 22 additions & 0 deletions src/contract/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ pub trait Operation {
fn disclose_hash(&self) -> DiscloseHash { self.disclose().commit_id() }
}

/// Issuer is a binary string which must be encoded into the issuer identity in
/// the application.
///
/// We deliberately do not define the internal structure of the identity such
/// that it can be updated without changes to the consensus level.
///
/// Contract validity doesn't assume any checks on the issuer identity; these
/// checks must be performed at the application level.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]

Check warning on line 260 in src/contract/operations.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/operations.rs#L260

Added line #L260 was not covered by tests
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
#[derive(CommitEncode)]

Check warning on line 263 in src/contract/operations.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/operations.rs#L263

Added line #L263 was not covered by tests
#[commit_encode(strategy = strict, id = StrictHash)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),

Check warning on line 267 in src/contract/operations.rs

View check run for this annotation

Codecov / codecov/patch

src/contract/operations.rs#L267

Added line #L267 was not covered by tests
serde(crate = "serde_crate", transparent)
)]
pub struct Issuer(SmallBlob);

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB)]
Expand All @@ -260,12 +280,14 @@ pub trait Operation {
pub struct Genesis {
pub ffv: Ffv,
pub schema_id: SchemaId,
pub timestamp: i64,
pub testnet: bool,
pub alt_layers1: AltLayer1Set,
pub metadata: Metadata,
pub globals: GlobalState,
pub assignments: Assignments<GenesisSeal>,
pub valencies: Valencies,
pub issuer: Issuer,
}

impl StrictSerialize for Genesis {}
Expand Down
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::{

/// Strict types id for the library providing data types for RGB consensus.
pub const LIB_ID_RGB: &str =
"urn:ubideco:stl:HqdNNAehK3yaQ1AC5pQmEuNNS1zgyo2Jw31fdUNKb9MU#annual-virus-garlic";
"urn:ubideco:stl:5corTa7ZCSDLdH2yXxpSm3Jyjw2vSjcqeUFbuGFNJrJr#except-basket-archer";

fn _rgb_core_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_RGB), tiny_bset! {
Expand Down
397 changes: 200 additions & 197 deletions stl/RGB@0.1.0.sta

Large diffs are not rendered by default.

Binary file modified stl/RGB@0.1.0.stl
Binary file not shown.
13 changes: 10 additions & 3 deletions stl/RGB@0.1.0.sty
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-
Id: urn:ubideco:stl:HqdNNAehK3yaQ1AC5pQmEuNNS1zgyo2Jw31fdUNKb9MU#annual-virus-garlic
Id: urn:ubideco:stl:5corTa7ZCSDLdH2yXxpSm3Jyjw2vSjcqeUFbuGFNJrJr#except-basket-archer
Name: RGB
Version: 0.1.0
Description: Consensus layer for RGB smart contracts
Expand Down Expand Up @@ -152,10 +152,12 @@ data AssignmentsBlindSealTxid : {AssignmentType -> ^ ..0xff TypedAssignsBlindSea
@mnemonic(delta-member-agenda)
data AttachId : [Byte ^ 32]

@mnemonic(goblin-accent-number)
@mnemonic(context-alpha-cover)
data BaseCommitment : schemaId SchemaId
, timestamp I64
, testnet Std.Bool#laser-madam-maxwell
, altLayers1 CommitVerify.StrictHash#cheese-final-locate
, issuer CommitVerify.StrictHash#cheese-final-locate

@mnemonic(agenda-ivory-blast)
data BlindingFactor : [Byte ^ 32]
Expand Down Expand Up @@ -218,15 +220,17 @@ data FungibleState : bits64#8 U64
data FungibleType : unsigned64Bit#8


@mnemonic(darwin-between-pilot)
@mnemonic(elastic-toyota-baron)
data Genesis : ffv Ffv
, schemaId SchemaId
, timestamp I64
, testnet Std.Bool#laser-madam-maxwell
, altLayers1 AltLayer1Set
, metadata Metadata
, globals GlobalState
, assignments AssignmentsBlindSealTxid
, valencies Valencies
, issuer Issuer

@mnemonic(andrea-amigo-grid)
data GenesisSchema : metadata StrictTypes.SemId#cargo-plasma-catalog
Expand Down Expand Up @@ -258,6 +262,9 @@ data InputMap : {Bitcoin.Vout -> ^ 1.. OpId}
@mnemonic(liquid-meaning-convert)
data Inputs : {Input}

@mnemonic(veteran-tango-content)
data Issuer : [Byte]

@mnemonic(light-nelson-brain)
data MediaType : any#255

Expand Down
2 changes: 2 additions & 0 deletions stl/Transition.vesper
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ OpCommitment rec
opType union -- TypeCommitment
genesis rec wrapped tag=0 -- BaseCommitment
schemaId bytes len=32 aka=SchemaId
timestamp is I64
testnet enum false=0 true=1 -- Bool
altLayers1 bytes len=32 aka=StrictHash
issuer bytes len=32 aka=StrictHash
transition tuple tag=1
_ bytes len=32 aka=ContractId
_ is U16 aka=TransitionType
Expand Down

0 comments on commit 1342202

Please sign in to comment.