Struct Codex

Source
pub struct Codex {
    pub version: ReservedBytes<1>,
    pub name: Confined<String, amplify::::collection::confinement::TinyString::{constant#0}, amplify::::collection::confinement::TinyString::{constant#1}>,
    pub developer: Identity,
    pub timestamp: i64,
    pub features: ReservedBytes<4>,
    pub field_order: u256,
    pub verification_config: CoreConfig,
    pub input_config: CoreConfig,
    pub verifiers: Confined<BTreeMap<u16, LibSite>, amplify::::collection::confinement::TinyOrdMap::{constant#0}, amplify::::collection::confinement::TinyOrdMap::{constant#1}>,
}
Expand description

Codex is a crucial part of a contract; it provides a set of commitments to the contract terms and conditions expressed as a deterministic program able to run in SONIC computer model.

The main (and the only) operation of the codex is verification of contract Operations. It is done in Self::verify method.

Fields§

§version: ReservedBytes<1>

Consensus version of the codex.

§Future use

For now, the only supported version is one; thus, a ReservedBytes is used.

In the future, with more versions coming, this should be replaced with an enum, where the first byte will encode (with standard strict encoding) a version number as an enum variant. For instance,

pub enum Codex {
    V0(CodexV0),
    V1(CodexV1)
}
pub struct CodexV0 { /*...*/ }
pub struct CodexV1 { /*...*/ }
§name: Confined<String, amplify::::collection::confinement::TinyString::{constant#0}, amplify::::collection::confinement::TinyString::{constant#1}>

Human-readable name of the codex used in the UI.

§developer: Identity

Identity of the codex developer.

§timestamp: i64

Timestamp of the codex creation.

This field can be also used to “mine” a vanity codex id. While this feature is noa necessary one, many people will try to do it, and it is better to provide them with a standard way of doing this, rather to force them into abusing and misusing other fields of the codex.

§features: ReservedBytes<4>

A set of feature flags.

RGB-I-0 consensus has no flags, which is enforced with ReservedBytes structure.

§field_order: u256

The order of the field used by VM for all scripts (operation verification and state access condition satisfaction).

§verification_config: CoreConfig

VM core configuration for the operation verification.

§input_config: CoreConfig

The VM uses input config to verify the satisfaction of the lock conditions for operation inputs.

This configuration is given in the codex and not the contract, but contract issuers still decide on it since they can just use a different codex or modify it here.

Please keep in mind that this config may be used to effectively prohibit the use of custom lock scripts in destructible state, via setting the maximal complexity level to zero.

§verifiers: Confined<BTreeMap<u16, LibSite>, amplify::::collection::confinement::TinyOrdMap::{constant#0}, amplify::::collection::confinement::TinyOrdMap::{constant#1}>

List of verifiers for each of the calls supported by the codex.

Implementations§

Source§

impl Codex

Source

pub fn codex_id(&self) -> CodexId

The codex id holds a commitment to all codex data.

The codex is encoded using strict encoding into the hasher, which is provided by the #[derive(CommitEncode)] and #[commit_encode(strategy = strict, id = CodexId)] macros in the structure definition.

It is the same as the result of the CommitId::commit_id procedure.

Source

pub fn verify( &self, contract_id: ContractId, operation: Operation, memory: &impl Memory, repo: &impl LibRepo, ) -> Result<VerifiedOperation, CallError>

The main purpose of the codex is to verify the operation under the contract. This is the implementation of this verification procedure.

§Arguments
  • contract_id: since the contract is external to the codex, this information must be provided to the verifier. While operation also commits to the contract id, this id must come not from the operation itself, but from the external knowledge of the contract id which is being verified; such that operation commitment to the contract is also checked.
  • operation: the operation to verify.
  • memory: an object holding an actual contract state (see Memory trait) and provides a read access to it.
  • repo: a repository holding VM libraries used in the operation verification, calls to which are kept in the codex (see Codex::verifiers) and may be called from by the access conditions of the inputs. See LibRepo for the details.
§Returns

On success, returns an operation wrapped as VerifiedOperation structure, which should be used (1) for updating the contract state by applying the operation, and (2) for the persistence of the contract history.

§Errors

On any verification failure, the method does not proceed with further certification and instantly returns with one of CallError variants.

§Panics

Panics if the repo (library resolver) returns a library which id doesn’t match the requested one.

Trait Implementations§

Source§

impl Clone for Codex

Source§

fn clone(&self) -> Codex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CommitEncode for Codex

Source§

type CommitmentId = CodexId

Type of the resulting commitment.
Source§

fn commit_encode(&self, engine: &mut CommitEngine)

Encodes the data for the commitment by writing them directly into a std::io::Write writer instance
Source§

impl Debug for Codex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Codex

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Codex, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Codex

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Codex

Source§

fn cmp(&self, other: &Codex) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Codex

Source§

fn eq(&self, other: &Codex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Codex

Source§

fn partial_cmp(&self, other: &Codex) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Codex

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StrictDecode for Codex

Source§

impl StrictDumb for Codex

Source§

impl StrictEncode for Codex

Source§

fn strict_encode<W>(&self, writer: W) -> Result<W, Error>
where W: TypedWrite,

Source§

fn strict_write(&self, writer: impl WriteRaw) -> Result<(), Error>

Source§

impl StrictStruct for Codex

Source§

impl StrictType for Codex

Source§

const STRICT_LIB_NAME: &'static str = LIB_NAME_ULTRASONIC

Source§

fn strict_name() -> Option<TypeName>

Source§

impl Eq for Codex

Source§

impl StrictProduct for Codex

Auto Trait Implementations§

§

impl Freeze for Codex

§

impl RefUnwindSafe for Codex

§

impl Send for Codex

§

impl Sync for Codex

§

impl Unpin for Codex

§

impl UnwindSafe for Codex

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CommitId for T
where T: CommitEncode,

Source§

fn commit(&self) -> CommitEngine

Source§

fn commit_id(&self) -> <T as CommitEncode>::CommitmentId

Performs commitment to client-side-validated data
Source§

impl<T> CommitmentLayout for T

Source§

fn commitment_layout() -> CommitLayout

Generate a descriptive commitment layout, which includes a description of each encoded field and the used hashing strategies.
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> VerifyEq for T
where T: Eq,

Source§

fn verify_eq(&self, other: &T) -> bool

Verifies commit-equivalence of two instances of the same type.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,