I am working on creating a custom map which takes T::AccountId
as a perimeter:
#[pallet::storage]
#[pallet::getter(fn declaration_map)]
pub(super) type Declarations<T: Config> = StorageMap
<
_,
Blake2_128Concat,
T::AccountId,
Amendment<T::AccountId>,
OptionQuery
>;
I pass it as an OptionQuery
since AccountId
does not have a default value implemented and therefore could be None
value. However in my calls: (Example)
#[pallet::weight(100_000)]
pub fn add_amendment(origin: OriginFor<T>, statement: Vec<u8>, owners: Vec<T::AccountId>) -> DispatchResult {
use crate::pallet::Event::AmendmentAdded;
ensure_root(origin)?;
let amendment = Amendment {
statement: statement.clone(),
owners: owners
};
let next_id = Self::next_amendment();
Declarations::<T>::insert(next_id, amendment);
Self::deposit_event(AmendmentAdded(next_id.unwrap(), statement));
NextAmendmentID::<T>::put(&next_id.unwrap() + 1);
Ok(())
}
When I get a value from the map there is a potential that the value will be None
and can not be used as a key. The simplest way to fix this in my mind is to implement a default value to AccountId
. My question is how do I implement that? There is an this article:
Why is there no `Default` implementation for `T::AccountId`?
The OP however doesn't go into detail about how they implemented a default value. If anyone has any insight on this it would be very helpful.