diff --git a/examples/upgradeable-contract/upgradeable-flipper/Cargo.toml b/examples/upgradeable-contract/upgradeable-flipper/Cargo.toml index b2589cbfd3b..dc936644d89 100644 --- a/examples/upgradeable-contract/upgradeable-flipper/Cargo.toml +++ b/examples/upgradeable-contract/upgradeable-flipper/Cargo.toml @@ -23,13 +23,11 @@ crate-type = ["cdylib"] default = ["std"] std = [ "ink_primitives/std", - "ink_metadata", "ink_metadata/std", "ink_env/std", "ink_storage/std", "ink_lang/std", "scale/std", - "scale-info", "scale-info/std", ] ink-as-dependency = [] diff --git a/examples/upgradeable-contract/upgradeable-flipper/lib.rs b/examples/upgradeable-contract/upgradeable-flipper/lib.rs index bc827c83b7e..dfd86020b11 100644 --- a/examples/upgradeable-contract/upgradeable-flipper/lib.rs +++ b/examples/upgradeable-contract/upgradeable-flipper/lib.rs @@ -15,7 +15,7 @@ pub mod flipper { pub struct Flipper { /// The field is `Upgradeable`, which means if the field is not initialized, it will be. /// - /// By default ink! throw an error that field is not initialized. + /// By default ink! would throw an error that the field is not initialized. /// With that wrapper, you can initialize the field later during the method execution, /// not in the constructor. value: Upgradeable, diff --git a/examples/upgradeable-contract/upgradeable-flipper/upgradeable.rs b/examples/upgradeable-contract/upgradeable-flipper/upgradeable.rs index c00553986cd..c589811925b 100644 --- a/examples/upgradeable-contract/upgradeable-flipper/upgradeable.rs +++ b/examples/upgradeable-contract/upgradeable-flipper/upgradeable.rs @@ -14,11 +14,20 @@ use scale::{ Encode, }; +/// It is a status struct for `Upgradeable`, to specify that the inner type is initialized. #[derive(Debug)] pub struct Initialized; +/// It is a status struct for `Upgradeable`, to specify that the inner type may be not initialized and +/// `pull_spread` should initialize it. #[derive(Debug)] pub struct NotInitialized; +/// The `Upgradeable` means if the field is not initialized, it will be. +/// +/// By default ink! would throw an error that the field is not initialized. +/// With that wrapper, you can initialize the field later during the method execution, +/// not in the constructor. It can be done because `SpreadLayout` for `Upgradeable` +/// creates the object, if storage key is empty. #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub struct Upgradeable { @@ -35,6 +44,7 @@ impl Upgradeable { } } +/// It is default implementation of `SpreadLayout` for case when we don't need to init. impl SpreadLayout for Upgradeable { const FOOTPRINT: u64 = T::FOOTPRINT; const REQUIRES_DEEP_CLEAN_UP: bool = T::REQUIRES_DEEP_CLEAN_UP; @@ -52,6 +62,7 @@ impl SpreadLayout for Upgradeable { } } +/// It is implementation of `SpreadLayout` that initialize the inner type if it is not initialized. impl SpreadLayout for Upgradeable { const FOOTPRINT: u64 = ::FOOTPRINT; const REQUIRES_DEEP_CLEAN_UP: bool = ::REQUIRES_DEEP_CLEAN_UP; @@ -76,6 +87,8 @@ impl SpreadLayout for Upgradeable PackedLayout for Upgradeable { fn pull_packed(&mut self, at: &Key) { ::pull_packed(&mut self.inner, at)