sui
sui copied to clipboard
[Question] what's wintness-pattern?
what's wintness-pattern?
-
one-time-witness type (1) it can be verified by "sui::types::is_one_time_witness". (2) it has the same name as the module (compared to lowercase strings), that means at most one one-time-witness type per module. (3) it has only one "drop" ability. (4) it has no generic parameters. (5) it is only a struct which has no fields or a single field of type bool. (6) it can only be instantiated in "init" (default initialization function).
-
witness-pattern (1) "sui::types::is_one_time_witness" is used in the function. (2) use case: the function can only be called when other modules are deployed (try call init function)
-
if both 1 and 2 are correct, the transferable-witness example is not witness-pattern.
Is my understanding correct?
The descriptions of each pattern in: https://examples.sui.io/basics/one-time-witness.html
https://examples.sui.io/patterns/witness.html
https://examples.sui.io/patterns/transferable-witness.html
. but copying @damirka for a detailed explanation.
This way the classification will not be confused:
witness
is one pattern and one-time-witness
is another pattern.