6

Starting with version 9.17 and greater I started getting these errors for the custom pallets I've made. Could I please get a pointer in resolving this issue? Example output from compiler:

#[derive(Debug, Clone, PartialEq, Default, Encode, Decode, scale_info::TypeInfo)]
   |                                       ^^^^^^^
   = note: required because of the requirements on the impl of `frame_support::traits::Get<SolanaAccount<<T as frame_system::Config>::AccountId>>` for `GetDefault`
   = note: required because of the requirements on the impl of `QueryKindTrait<SolanaAccount<<T as frame_system::Config>::AccountId>, GetDefault>` for `frame_support::pallet_prelude::ValueQuery`
   = note: required because of the requirements on the impl of `frame_support::storage::generator::StorageMap<<T as frame_system::Config>::AccountId, SolanaAccount<<T as frame_system::Config>::AccountId>>` for `frame_support::pallet_prelude::StorageMap<_GeneratedPrefixForStorageSolMnemonic<T>, frame_support::Twox64Concat, <T as frame_system::Config>::AccountId, SolanaAccount<<T as frame_system::Config>::AccountId>, frame_support::pallet_prelude::ValueQuery>`
   = note: required because of the requirements on the impl of `frame_support::StorageMap<<T as frame_system::Config>::AccountId, SolanaAccount<<T as frame_system::Config>::AccountId>>` for `frame_support::pallet_prelude::StorageMap<_GeneratedPrefixForStorageSolMnemonic<T>, frame_support::Twox64Concat, <T as frame_system::Config>::AccountId, SolanaAccount<<T as frame_system::Config>::AccountId>, frame_support::pallet_prelude::ValueQuery>`
   = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting the associated type
   |
97 |     #[pallet::storage, <T as frame_system::Config>::AccountId: std::default::Default]
3
  • It's a little bit too little context to provide a useful answer. Consider augmenting the question with a little bit more detail.
    – pepyakin
    Commented Apr 11, 2022 at 18:58
  • 2
    You may find this PR useful github.com/paritytech/substrate/pull/10403
    – pepyakin
    Commented Apr 11, 2022 at 18:58
  • I have a struct of many different chain addresses to attach to a user. I used T::AccountId for the dot address reference, I suppose I can change it to Vec<u8>. Its convenient to use the macro on those structs as it saves many lines of code.
    – Aaron Ely
    Commented Apr 11, 2022 at 19:27

1 Answer 1

11

Short answer: AccountId is not designed to be bound to Default. A "default" AccountId doesn't make any sense to have and it helped mask a previous issue and so it was removed in a recent release.

This means that AccountId values cannot be used as storage item values which assume a default value.

In your case, you'll probably need to replace the ValueQuery with an OptionQuery and handle the possibility that the map item doesn't exist (i.e. that it returns None). An alternative would be to manually implement Default for SolanaAccount<AccountId> when AccountId doesn't itself implement Default.

3
  • I just manually impl Default for it. Thanks!
    – Aaron Ely
    Commented Apr 11, 2022 at 23:26
  • @AaronEly please consider marking this answer as the solution, thanks.
    – pepyakin
    Commented Apr 12, 2022 at 12:07
  • @AaronEly can you provide the code snippet to implement Default for AccountId.
    – Asmita
    Commented May 17, 2022 at 16:29

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.