Closed todofixthis closed 3 months ago
It should be used here too for safety. However, in this case gen
can never be greater than the number of kitties in the system. And both gen
and total_kitties_count
use the same u64
to store the value.
If we introduced kitty deletion, then we may have a problem... either way, doing saturated_add
is probably what we want here. Basically it will get to a max value, and not increase anymore.
In https://substrate.dev/substrate-collectables-workshop/#/3/breeding-a-kitty the solution uses the following code to set the new kitty's
gen
value:Should this logic be using
checked_add()
instead (concept introduced in chapter 2)? E.g.:I'm new to Rust and Substrate, so I don't know if this is a special case where
checked_add()
is not necessary — then this would be an opportunity to reinforce the principle (or explain the special case).