Expand description

A constraint checker is a piece of logic that determines whether a transaction as a whole is valid and should be committed. Most tuxedo pieces will provide one or more constraint checkers. Constraint Checkers do not calculate the correct final state, but rather determine whether the proposed final state (as specified by the output set) meets the necessary constraints.

Constraint Checkers can be used to codify the laws of a monetary system, a chemistry or physics simulation, NFT kitties, public elections and much more.

The primary way for developers to write a constraint checker is with the SimpleConstraintChecker trait. It provides a method called check which determines whether the relationship between the inputs and outputs (and peeks) is valid. For example making sure no extra money was created, or making sure the chemical reaction balances.

§Inherents

If you need to tap in to Substrate’s inherent system you may choose to also implement the InherentHooks trait for the same type that implements SimpleConstraintChecker. When installing a constraint checker in your runtime, make sure to wrap it with the InherentAdapter type. See the inherents module for more details.

§Constraint Checker Internals

One of Tuxedo’s killer features is its ability to aggregating pieces recursively. To achieve this we have to consider that many intermediate layers in the aggregation tree will have multiple inherent types. For this reason, we provide a much more flexible interface that the aggregation macro can use called ConstraintChecker. Do not implement ConstraintChecker directly.

Traits§

  • The raw and fully powerful ConstraintChecker interface used by the Tuxedo Executive.
  • A particular constraint checker that a transaction can choose to be checked by. Checks whether the input and output data from a transaction meets the codified constraints.