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 Operation
s. 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
impl Codex
Sourcepub fn codex_id(&self) -> CodexId
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.
Sourcepub fn verify(
&self,
contract_id: ContractId,
operation: Operation,
memory: &impl Memory,
repo: &impl LibRepo,
) -> Result<VerifiedOperation, CallError>
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 (seeMemory
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 (seeCodex::verifiers
) and may be called from by the access conditions of the inputs. SeeLibRepo
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 CommitEncode for Codex
impl CommitEncode for Codex
Source§type CommitmentId = CodexId
type CommitmentId = CodexId
Source§fn commit_encode(&self, engine: &mut CommitEngine)
fn commit_encode(&self, engine: &mut CommitEngine)
std::io::Write
writer instanceSource§impl<'de> Deserialize<'de> for Codex
impl<'de> Deserialize<'de> for Codex
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Codex, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Codex, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Codex
impl Ord for Codex
Source§impl PartialOrd for Codex
impl PartialOrd for Codex
Source§impl Serialize for Codex
impl Serialize for Codex
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl StrictDecode for Codex
impl StrictDecode for Codex
fn strict_decode(reader: &mut impl TypedRead) -> Result<Codex, DecodeError>
fn strict_read(reader: impl ReadRaw) -> Result<Self, DecodeError>
Source§impl StrictDumb for Codex
impl StrictDumb for Codex
fn strict_dumb() -> Codex
Source§impl StrictEncode for Codex
impl StrictEncode for Codex
fn strict_encode<W>(&self, writer: W) -> Result<W, Error>where
W: TypedWrite,
fn strict_write(&self, writer: impl WriteRaw) -> Result<(), Error>
Source§impl StrictStruct for Codex
impl StrictStruct for Codex
const ALL_FIELDS: &'static [&'static str]
fn strict_check_fields()
fn strict_type_info() -> TypeInfo<Self>
Source§impl StrictType for Codex
impl StrictType for Codex
const STRICT_LIB_NAME: &'static str = LIB_NAME_ULTRASONIC
fn strict_name() -> Option<TypeName>
impl Eq for Codex
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CommitId for Twhere
T: CommitEncode,
impl<T> CommitId for Twhere
T: CommitEncode,
fn commit(&self) -> CommitEngine
Source§fn commit_id(&self) -> <T as CommitEncode>::CommitmentId
fn commit_id(&self) -> <T as CommitEncode>::CommitmentId
Source§impl<T> CommitmentLayout for Twhere
T: CommitEncode + StrictDumb,
impl<T> CommitmentLayout for Twhere
T: CommitEncode + StrictDumb,
Source§fn commitment_layout() -> CommitLayout
fn commitment_layout() -> CommitLayout
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.