Syscalls and Sources

Scripts can access any information about the transaction that is being validated. All transaction information is retrieved by the script during execution by using CKB-VM syscalls.

Scripts written in Rust will use the CKB-STD library that provides both high-level functions and syscalls. Scripts written in C will directly use the syscalls referenced in the RFC. Developers are recommended to use Rust whenever possible.

In the table below, you will see the relationship between the available syscall functions. Rust developers will want to use the high-level functions most of the time, but on occasion using a syscall may be necessary.

You don't need to memorize all the functions below, but it's a good idea to read through them so you have a general idea about what kind of information is available. We will introduce the most commonly used functions in the lessons to follow.

Using QueryIter with Syscalls

QueryIter allows for convenient iteration over the Rust high-level functions. Most of the CKB-STD high-level functions for loading a cell, header, input, or witness, can be used with QueryIter.

Using QueryIter is the preferred method of calling these functions because it is very concise, and it also abstracts away some of the most common boilerplate code needed to use these loading functions.

We will demonstrate how to use QueryIter in the next lesson. The reason we are mentioning it now is that it is used heavily with the Rust high-level functions shown above.

Sources

Most of the syscall functions also require a source to be provided as an argument. Here are the available sources:

pub enum Source {
    Input,
    Output,
    CellDep,
    HeaderDep,
    GroupInput,
    GroupOutput,
}

You should already be familiar with Input, Output, and CellDep. These are used to load cells from the inputs, outputs, and cell deps structures from the transaction.

The HeaderDep source is used to load additional headers from previous blocks. This is typically used to provide a time reference in a transaction. We will cover headers in a later lesson.

The GroupInput and GroupOutput sources provide a filtered view of the inputs and outputs. When a lock script or type script is executing, a very common process is to locate the cells that also have the same lock script or type script. In our next lesson, we will show how this common process occurs.

Last updated