sui icon indicating copy to clipboard operation
sui copied to clipboard

[Question] what's wintness-pattern?

Open icodezjb opened this issue 2 years ago • 1 comments

what's wintness-pattern?

  1. 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).

  2. 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)

  3. if both 1 and 2 are correct, the transferable-witness example is not witness-pattern.

Is my understanding correct?

icodezjb avatar Nov 04 '22 06:11 icodezjb

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.

sblackshear avatar Nov 04 '22 15:11 sblackshear

This way the classification will not be confused: witness is one pattern and one-time-witness is another pattern.

icodezjb avatar Nov 11 '22 03:11 icodezjb