Processing

The object imaging process involves executing the kind contracts of objects, which are compiled into WebAssembly (Wasm) bytecode from kind contract source code. These contracts are loaded and executed by the Object Virtual Machine (OVM) on the Previous chain. The code, along with other necessary runtime data, is provided by blockchain storage.

Retrieve Kind Contract

The first step in the processing involves retrieving the kind contract, which is necessary to compute the new version of the object's assets. The code hash of the kind contract is resolved from the object’s metadata, and the content of the contract is then loaded from the blockchain storage.

Here’s a pseudocode example to illustrate the loading process:

#![allow(unused)]
fn main() {
let kind_oid: Oid = oid.kind_oid(); // Get the kind OID associated with the object
let meta: Meta = storage.get_meta(oid, rev); // Get the metadata of the object
let kind_elems: Vec<Bytes32> = storage.get_object_data(kind_oid, meta.kind_rev); // Retrieve kind data
let kind_code: Bytes32 = kind_elems[1]; // Extract the code identifier from the kind data
let code_material: Material = storage.get_material(kind_code); // Load the material for the code
let code: Bytes = code_material.content; // Extract the actual bytecode
}

In this process:

  • The oid.kind_oid() function retrieves the identifier for the object’s kind.
  • Metadata about the object, including its revision, is fetched from storage.
  • The relevant kind data, including the contract bytecode, is retrieved and used to load the executable code into the OVM.

Initialize Memory

Once the kind contract is loaded, the elements of the object are retrieved from blockchain storage and used to initialize the memory of the Wasm instance. These elements represent the object’s state and attributes, which are necessary for executing the kind contract.

Here’s the pseudocode for retrieving the object’s elements:

#![allow(unused)]
fn main() {
let elems: Vec<Bytes32> = storage.get_object_data(oid, rev); // Get the object data based on OID and revision
}

The elements are loaded into a specific memory location of the Wasm instance, allowing the contract to access and process them during execution.

Runtime Data

During the execution of the kind contract, several data components are accessed and processed. These include:

  • Meta: Metadata for the object, including the object's version and related properties.
  • Elements: The individual components that make up the object, such as its attributes and state.
  • Connections: Links between objects that define their relationships and interactions.
  • Object Set: The grouping of objects to which the current object belongs.
  • Object Kind: The type of object, which determines its behavior and rules defined by the kind contract.

These runtime data points are provided by the Previous chain's storage and used by the Wasm instance to execute the contract and generate new versions of the object’s assets.

Host Functions

During execution, the Wasm instance can invoke host functions, which are provided by the OVM and allow the contract to interact with the blockchain state. These functions enable access to blockchain storage, retrieval of materials, and other operations necessary for contract execution. These host functions are critical for ensuring that kind contracts can read and write to the blockchain, enabling updates to object state.

World State Updating

After the kind contract executes, the object’s new state, including any changes to its underlying assets, is updated in the world state on the Previous chain. The results of the contract execution are deterministic and verifiable, ensuring that object evolution remains transparent and secure.

The updated data includes:

  • New revisions of the object’s elements and assets.
  • Changes to connections and relationships between objects.
  • Updates to the object’s metadata and kind information.

This ensures that the object’s state remains consistent and can be used in subsequent interactions and imaging processes.