I'm trying to have my pallet compile a pallet call based on the feature that is set, for example if I have two function calls feature_one()
and feature_two()
, it works fine with feature_one
but when I add the second method with the #[cfg(feature= "feature2")]
macro it gives me the following error:
error[E0599]: no function or associated item named `feature_two` found for struct `pallet::Pallet` in the current scope
function or associated item not found in `pallet::Pallet<T>`
help: there is an associated function with a similar name: `feature_one`
this is the pallet code:
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(test)]
mod tests;
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use frame_system::pallet_prelude::*;
pub use sp_runtime::traits::Extrinsic;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// An Event has been validated
CustomEvent { event_id: T::Hash },
}
#[pallet::error]
pub enum Error<T> {
AlreadySymbitted,
}
#[pallet::storage]
pub(super) type MyStorage<T: Config> = StorageMap<_, Blake2_128Concat, T::Hash, T::BlockNumber>;
#[pallet::call]
impl<T: Config> Pallet<T> {
#[cfg(feature= "feature1")]
#[pallet::weight(0)]
pub fn feature_one(_origin: OriginFor<T>, event_id: T::Hash) -> DispatchResult {
}
#[cfg(feature= "feature2")]
#[pallet::weight(0)]
pub fn feature_two(_origin: OriginFor<T>, event_id: T::Hash) -> DispatchResult {
}
}
#[cfg(feature= "feature1")]
is supported in theconstruct_runtime!
macro these days.