The macro #[ink::storage_item] doesn't derive all necessary traits when the struct is used inner the Mapping
Environment: ink! v4 - cargo-contract: v2
Based on the documentation (https://use.ink/datastructures/custom-datastructure) the macro #[ink::storage_item] should derive all necessary traits for you.
It means :
#[derive(scale::Decode, scale::Encode)]
#[cfg_attr(
feature = "std",
derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
could be replaced by the simple macro #[ink::storage_item]
exept when the struct is used inner the Mapping
example:
This code will work:
#[ink::storage_item]
pub struct Inventory {
....
}
#[ink(storage)]
#[derive(Default)]
pub struct Marketplace {
inventory: Inventory,
}
but not this one:
#[ink(storage)]
#[derive(Default)]
pub struct Marketplace {
inventories: Mapping<u128, Inventory>,
}
because the trait bound ink::storage::Mapping<u128, Inventory>: StorableHint<()> is not satisfied
the trait StorableHint<Key> is implemented for ink::storage::Mapping<K, V, InnerKey>
required for ink::storage::Mapping<u128, Inventory> to implement AutoStorableHint<ManualKey<3377945766>>
Here the full error: https://pastebin.com/qN7ZCfCk
here is a new error link, in case the link expired (1 month from now). https://pastebin.com/JtLP2aAi