3.4 谓词 (Predicates)

From the perspective of Sway, predicates are programs that return a Boolean value and which represent ownership of some resource upon execution to true. They have no access to contract storage. Here is a trivial predicate, which always evaluates to true:

从Sway的角度来看,谓词是返回一个布尔值的程序,它在执行时表示对某些资源的所有权为真。它们不能访问合约存储。下面是一个简单的谓词,它总是被评估为真:

predicate;

// All predicates require a main function which returns a Boolean value.
fn main() -> bool {
    true
}

调试谓词 (Debugging Predicates)

Because they don't have any side effects (they are pure), predicates cannot create receipts. Therefore, they cannot have logging or create a stack backtrace. This means that there is no native way to debug them aside from using a single-stepping debugger (which is a work-in-progress).

因为它们没有任何副作用(它们是 的),谓词不能创建收据。因此,它们不能有日志记录或创建堆栈来回溯。这意味着除了使用单步调试器(这是一个正在进行的工作)外,没有原生的方法来调试它们。

As a workaround, the predicate can be written, tested, and debugged first as a script, and then changed back into a predicate.

作为一种变通方法,谓词可以先作为 脚本 script编写、测试和调试,然后再改回为 谓词 predicate

Last updated