|
6 | 6 | //! Constraint Checkers can be used to codify the laws of a monetary system, a chemistry or physics simulation,
|
7 | 7 | //! NFT kitties, public elections and much more.
|
8 | 8 | //!
|
9 |
| -//! By far the most common and most important way to write a constraint checker is with the `SimpleConstraintChecker` |
10 |
| -//! trait. It provides a single method called `check` which determines whether the relationship between the inputs |
| 9 | +//! The primary way for developers to write a constraint checker is with the `SimpleConstraintChecker` |
| 10 | +//! trait. It provides a method called `check` which determines whether the relationship between the inputs |
11 | 11 | //! and outputs (and peeks) is valid. For example making sure no extra money was created, or making sure the chemical
|
12 | 12 | //! reaction balances.
|
13 | 13 | //!
|
14 | 14 | //! ## Inherents
|
15 | 15 | //!
|
16 | 16 | //! If you need to tap in to [Substrate's inherent system](https://docs.substrate.io/learn/transaction-types/#inherent-transactions)
|
17 |
| -//! you may choose to implement the `ConstraintCheckerWithInherent` trait instead of the simple one. This trait is more complex |
18 |
| -//! but if you really need an inherent, it is required. Make sure you know what you are doing before |
19 |
| -//! you start writing an inherent. |
| 17 | +//! you may choose to also implement the `InherentHooks` trait for the same type that implements `SimpleConstraintChecker`. |
| 18 | +//! When installing a constraint checker in your runtime, make sure to wrap it with the `InherentAdapter` type. |
| 19 | +//! See the `inherents` module for more details. |
20 | 20 | //!
|
21 | 21 | //! ## Constraint Checker Internals
|
22 | 22 | //!
|
23 | 23 | //! One of Tuxedo's killer features is its ability to aggregating pieces recursively.
|
24 | 24 | //! To achieve this we have to consider that many intermediate layers in the aggregation tree
|
25 | 25 | //! will have multiple inherent types. For this reason, we provide a much more flexible interface
|
26 |
| -//! that the aggregation macro can use. |
27 |
| -//! |
28 |
| -//! The current design is based on a chain of blanket implementations. Each trait has a blanket |
29 |
| -//! impl for the next more complex one. |
30 |
| -//! |
31 |
| -//! `SimpleConstraintChecker` -> `ConstraintCheckerWithInherent` -> ConstraintChecker |
32 |
| -//! https://github.com/rust-lang/rust/issues/42721 |
| 26 | +//! that the aggregation macro can use called `ConstraintChecker`. Do not implement `ConstraintChecker` |
| 27 | +//! directly. |
33 | 28 |
|
34 | 29 | use sp_core::H256;
|
35 | 30 | use sp_inherents::{CheckInherentsResult, InherentData};
|
@@ -58,15 +53,16 @@ pub trait SimpleConstraintChecker: Debug + Encode + Decode + Clone {
|
58 | 53 | ) -> Result<TransactionPriority, Self::Error>;
|
59 | 54 | }
|
60 | 55 |
|
61 |
| -/// A single constraint checker that a transaction can choose to call. Checks whether the input |
62 |
| -/// and output data from a transaction meets the codified constraints. |
| 56 | +/// The raw and fully powerful `ConstraintChecker` interface used by the |
| 57 | +/// Tuxedo Executive. |
63 | 58 | ///
|
64 |
| -/// You should never manually write a body to this function. |
| 59 | +/// You should never manually manually implement this trait. |
65 | 60 | /// If you are:
|
66 |
| -/// * Working on an inherent constraint checker -> Rely on the default body. |
67 | 61 | /// * Working on a simple non-inherent constraint checker -> Use the `SimpleConstraintChecker` trait instead
|
68 | 62 | /// and rely on its blanket implementation.
|
69 |
| -/// * Considering an aggregate constraint checker which is part inherent, part not -> let the macro handle it for you. |
| 63 | +/// * Working on an inherent constraint checker -> Implement `SimpleConstraintChecker` and `InherentHooks` and use the |
| 64 | +/// `InherentAdapter` wrapper type. |
| 65 | +/// * Considering an aggregate constraint checker that is part inherent, part not -> let the macro handle it for you. |
70 | 66 | ///
|
71 | 67 | /// If you are trying to implement some complex inherent logic that requires the interaction of
|
72 | 68 | /// multiple inherents, or features a variable number of inherents in each block, you might be
|
|
0 commit comments