I have one pallet with a storagemap that I want to use/call with another Pallet.
After doing some research I ran over Centrifuge fudge project(https://github.com/centrifuge/fudge/blob/376e4d6b89324b24d131e7f7c19c7c504871d5d3/core/src/builder/relay_chain.rs#L62-L70) that has a similar approach.
I tried to do this using a StorageInstance:
pub mod llmmod {
use super::*;
use frame_support::{
storage::types::{StorageMap, StorageValue, ValueQuery},
traits::StorageInstance,
Blake2_128Concat, Twox64Concat,
};
// ParaLifecyclesPrefix, based on centrifuge
pub struct LLMPoliticsCopy;
impl StorageInstance for LLMPoliticsCopy {
fn pallet_prefix() -> &'static str {
"llm"
}
const STORAGE_PREFIX: &'static str = "LLMPolitics";
}
pub type LLMPolitics<T> = frame_support::storage::types::StorageMap<
LLMPoliticsCopy,
Blake2_128Concat,
<T as frame_system::Config>::AccountId,
u128,
frame_support::pallet_prelude::ValueQuery,
>;
pub fn check_pooled_llm<T: frame_system::Config>(sender: T::AccountId) -> bool {
LLMPolitics::<T>::contains_key::<T::AccountId>(sender)
}
}
Then I check the storage map with a regular contains, to check if the account is in the storage map:
ensure!(!llmmod::check_pooled_llm::<T>(who.clone()), Error::<T>::NoPolLLM);
The code is compiling, but the storage map is not syncing, when I insert a new entry using the pallet, it does not sync.
Is there a way to Query a storage map in another pallet without adding new_pallet::Config to the config trait ? Is there a way to get around this?
I need the democracy pallet to query a storage map from another pallet but adding + LLM_Pallet::Config
in the trait config for the pallet just introduce a lot of bugs.
Is there a way to query storage maps that other pallets have without the pallet's config? manually adding a trait for it?
from pallet:
#[pallet::storage] // allocated in politics
#[pallet::getter(fn get_politics_balance)]
pub(super) type LLMPolitics<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;
Link to the code repo:
https://github.com/liberland/liberland_substrate/tree/storage
https://github.com/liberland/liberland_substrate/blob/storage/frame/democracy/src/lib.rs
https://github.com/liberland/liberland_substrate/blob/storage/frame/llm/src/lib.rs