3

I'm trying to use a custom struct inside a Mapping, but I get many errors when trying to compile my code.

Here is the custom struct I want to use inside a Mapping:

#[ink::storage_item]
pub struct Transaction {

        creator:AccountId,
        approvers: Mapping<AccountId, Balance>,
        number_of_approvals:Balance,
        psp22_token_to_transfer:AccountId,
        recipient:AccountId,
        transaction_number:Balance

}

And this is how I try to use the Mapping inside the contract struct:

#[ink(storage)]
pub struct MultiSig {
        
        deployer: AccountId,
        wallet_participants: Vec<AccountId>,
        number_of_participants: Balance,
        number_of_transactions: Balance,
        wallet_tokens: Mapping<AccountId,Balance>,
        wallet_transactions: Mapping<Balance,(Transaction,Balance)>

}

The errors that I get are related to decode and encode and "StorableHint", here are some of the errors that I'm getting:

the trait `parity_scale_codec::Decode` is not implemented for `(multi_sig::Transaction, u128)`


the trait `Encode` is not implemented for `(multi_sig::Transaction, u128)`

the trait `StorableHint<()>` is not implemented for `ink::storage::Mapping<u128, (multi_sig::Transaction, u128)>`

I'm using the following documentation in order to implement a custom struct:

Thank you in advance :)

1 Answer 1

1

Update your custom struct like this.

#[derive(scale::Decode, scale::Encode)]
#[cfg_attr(feature = "std",derive(scale_info::TypeInfo, 
 ink::storage::traits::StorageLayout))]

 pub struct Transaction {
        creator:AccountId,
        approvers: Mapping<AccountId, Balance>,
        number_of_approvals:Balance,
        psp22_token_to_transfer:AccountId,
        recipient:AccountId,
        transaction_number:Balance
    }
4
  • I now facing different error: #[derive(scale::Encode)] the trait WrapperTypeEncode is not implemented for ink::storage::Mapping<ink::ink_primitives::AccountId, u128> Commented Feb 15, 2023 at 10:42
  • would it be possible to share your code?
    – go11li
    Commented Feb 15, 2023 at 11:41
  • #[derive(scale::Decode, scale::Encode)] #[cfg_attr(feature = “std”,derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout))] pub struct Transaction { creator:AccountId, approvers: Mapping<AccountId, Balance>, number_of_approvals:Balance, psp22_token_to_transfer:AccountId, recipient:AccountId, transaction_number:Balance } I've implemented the derives and macros just like you suggested, or do you see the whole file? Commented Feb 15, 2023 at 11:49
  • I have very similar issue, I think that there is NO working example with Mapping. Commented May 29, 2023 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.