ink icon indicating copy to clipboard operation
ink copied to clipboard

The macro #[ink::storage_item] doesn't derive all necessary traits when the struct is used inner the Mapping

Open GuiGou12358 opened this issue 2 years ago • 1 comments

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

GuiGou12358 avatar Mar 02 '23 12:03 GuiGou12358

here is a new error link, in case the link expired (1 month from now). https://pastebin.com/JtLP2aAi

corlys avatar Mar 13 '23 13:03 corlys