0

I have looked through other posts on the compile errors for "Use macros in a custom pallet". None of them seemed to get me through the following error. I made sure to have a clean install of substrate-node-template. I also traced it to /Users/****/substrate/substrate-node-template/runtime/src/lib.rs:273:2. I couldn't find any references to "weights". It appears to be referenceing something which doesn't exist; however, I'm not sure where to go from there as I'm very new at this. Information below:

Error

MacBook-Pro src %  cargo check -p node-template-runtime --release
    Checking pallet-session v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#bca8a29d)
    Checking pallet-template v4.0.0-dev (/Users/****/substrate/substrate-node-template/pallets/template)
    Checking pallet-transaction-payment-rpc-runtime-api v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#bca8a29d)
    Checking pallet-aura v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#bca8a29d)
   Compiling node-template-runtime v4.0.0-dev (/Users/****/substrate/substrate-node-template/runtime)
warning: use of deprecated struct `pallet::_::Store`: 
                 Use of `#[pallet::generate_store(pub(super) trait Store)]` will be removed soon.
                 Check https://github.com/paritytech/substrate/pull/13535 for more details.
  --> pallets/template/src/lib.rs:12:4
   |
12 |   #[pallet::generate_store(pub(super) trait Store)]
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: 
                 It is deprecated to use hard-coded constant as call weight.
                 Please instead benchmark all calls or put the pallet into `dev` mode.
         
                 For more info see:
                     <https://github.com/paritytech/substrate/pull/13798>
  --> pallets/template/src/lib.rs:51:22
   |
51 |     #[pallet::weight(0)]
   |                      ^

warning: use of deprecated constant `pallet::warnings::ConstantWeight_1::_w`: 
                 It is deprecated to use hard-coded constant as call weight.
                 Please instead benchmark all calls or put the pallet into `dev` mode.
         
                 For more info see:
                     <https://github.com/paritytech/substrate/pull/13798>
  --> pallets/template/src/lib.rs:73:22
   |
73 |     #[pallet::weight(0)]
   |                      ^

warning: `pallet-template` (lib) generated 3 warnings
    Checking pallet-grandpa v4.0.0-dev (https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#bca8a29d)
error: failed to run custom build command for `node-template-runtime v4.0.0-dev (/Users/****/substrate/substrate-node-template/runtime)`

Caused by:
  process didn't exit successfully: `/Users/****/substrate/substrate-node-template/target/release/build/node-template-runtime-0abb0d4d70014bf7/build-script-build` (exit status: 1)
  --- stdout
  Information that should be included in a bug report.
  Executing build command: RUSTFLAGS="-C target-cpu=mvp -C target-feature=-sign-ext -C link-arg=--export-table -Clink-arg=--export=__heap_base -C link-arg=--import-memory  " SKIP_WASM_BUILD="" "/Users/****/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/Users/****/substrate/substrate-node-template/target/release/wbuild/node-template-runtime/Cargo.toml" "--color=always" "--profile" "release"
  Using rustc version: rustc 1.70.0 (90c541806 2023-05-31)


  --- stderr
     Compiling pallet-template v4.0.0-dev (/Users/****/substrate/substrate-node-template/pallets/template)
  warning: use of deprecated struct `pallet::_::Store`: 
                   Use of `#[pallet::generate_store(pub(super) trait Store)]` will be removed soon.
                   Check https://github.com/paritytech/substrate/pull/13535 for more details.
    --> /Users/****/substrate/substrate-node-template/pallets/template/src/lib.rs:12:4
     |
  12 |   #[pallet::generate_store(pub(super) trait Store)]
     |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(deprecated)]` on by default

  warning: use of deprecated constant `pallet::warnings::ConstantWeight_0::_w`: 
                   It is deprecated to use hard-coded constant as call weight.
                   Please instead benchmark all calls or put the pallet into `dev` mode.
           
                   For more info see:
                       <https://github.com/paritytech/substrate/pull/13798>
    --> /Users/****/substrate/substrate-node-template/pallets/template/src/lib.rs:51:22
     |
  51 |     #[pallet::weight(0)]
     |                      ^

  warning: use of deprecated constant `pallet::warnings::ConstantWeight_1::_w`: 
                   It is deprecated to use hard-coded constant as call weight.
                   Please instead benchmark all calls or put the pallet into `dev` mode.
           
                   For more info see:
                       <https://github.com/paritytech/substrate/pull/13798>
    --> /Users/****/substrate/substrate-node-template/pallets/template/src/lib.rs:73:22
     |
  73 |     #[pallet::weight(0)]
     |                      ^

     Compiling node-template-runtime v4.0.0-dev (/Users/****/substrate/substrate-node-template/runtime)
  warning: `pallet-template` (lib) generated 3 warnings
  error[E0437]: type `WeightInfo` is not a member of trait `pallet_template::Config`
     --> /Users/****/substrate/substrate-node-template/runtime/src/lib.rs:273:2
      |
  273 |     type WeightInfo = pallet_template::weights::SubstrateWeight<Runtime>;
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `pallet_template::Config`

  error[E0433]: failed to resolve: could not find `weights` in `pallet_template`
     --> /Users/****/substrate/substrate-node-template/runtime/src/lib.rs:273:37
      |
  273 |     type WeightInfo = pallet_template::weights::SubstrateWeight<Runtime>;
      |                                        ^^^^^^^ could not find `weights` in `pallet_template`

  Some errors have detailed explanations: E0433, E0437.
  For more information about an error, try `rustc --explain E0433`.
  error: could not compile `node-template-runtime` (lib) due to 2 previous errors

/substrate-node-template/pallets/template/src/lib.rs

#![cfg_attr(not(feature = "std"), no_std)]

// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
  use frame_support::pallet_prelude::*;
  use frame_system::pallet_prelude::*;

  #[pallet::pallet]
  #[pallet::generate_store(pub(super) trait Store)]
  pub struct Pallet<T>(_);

  /// Configure the pallet by specifying the parameters and types on which it depends.
  #[pallet::config]
  pub trait Config: frame_system::Config {
    /// Because this pallet emits events, it depends on the runtime's definition of an event.
    type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
  }

  // Pallets use events to inform users when important changes are made.
  // Event documentation should end with an array that provides descriptive names for parameters.
  #[pallet::event]
  #[pallet::generate_deposit(pub(super) fn deposit_event)]
  pub enum Event<T: Config> {
    /// Event emitted when a claim has been created.
    ClaimCreated { who: T::AccountId, claim: T::Hash },
    /// Event emitted when a claim is revoked by the owner.
    ClaimRevoked { who: T::AccountId, claim: T::Hash },
  }

  #[pallet::error]
  pub enum Error<T> {
    /// The claim already exists.
    AlreadyClaimed,
    /// The claim does not exist, so it cannot be revoked.
    NoSuchClaim,
    /// The claim is owned by another account, so caller can't revoke it.
    NotClaimOwner,
  }

  #[pallet::storage]
  pub(super) type Claims<T: Config> = StorageMap<_, Blake2_128Concat, T::Hash, (T::AccountId, T::BlockNumber)>;

  // Dispatchable functions allow users to interact with the pallet and invoke state changes.
  // These functions materialize as "extrinsics", which are often compared to transactions.
  // Dispatchable functions must be annotated with a weight and must return a DispatchResult.
  #[pallet::call]
  impl<T: Config> Pallet<T> {
    #[pallet::weight(0)]
    #[pallet::call_index(1)]
    pub fn create_claim(origin: OriginFor<T>, claim: T::Hash) -> DispatchResult {
      // Check that the extrinsic was signed and get the signer.
      // This function will return an error if the extrinsic is not signed.
      let sender = ensure_signed(origin)?;

      // Verify that the specified claim has not already been stored.
      ensure!(!Claims::<T>::contains_key(&claim), Error::<T>::AlreadyClaimed);

      // Get the block number from the FRAME System pallet.
      let current_block = <frame_system::Pallet<T>>::block_number();

      // Store the claim with the sender and block number.
      Claims::<T>::insert(&claim, (&sender, current_block));

      // Emit an event that the claim was created.
      Self::deposit_event(Event::ClaimCreated { who: sender, claim });

      Ok(())
    }

    #[pallet::weight(0)]
    #[pallet::call_index(2)]
    pub fn revoke_claim(origin: OriginFor<T>, claim: T::Hash) -> DispatchResult {
      // Check that the extrinsic was signed and get the signer.
      // This function will return an error if the extrinsic is not signed.
      let sender = ensure_signed(origin)?;

      // Get owner of the claim, if none return an error.
      let (owner, _) = Claims::<T>::get(&claim).ok_or(Error::<T>::NoSuchClaim)?;

      // Verify that sender of the current call is the claim owner.
      ensure!(sender == owner, Error::<T>::NotClaimOwner);

      // Remove claim from storage.
      Claims::<T>::remove(&claim);

      // Emit an event that the claim was erased.
      Self::deposit_event(Event::ClaimRevoked { who: sender, claim });
      Ok(())
    }
}

}

Cargo.toml

[package]
name = "pallet-template"
version = "4.0.0-dev"
description = "FRAME pallet template for defining custom runtime logic."
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
homepage = "https://substrate.io"
edition = "2021"
license = "MIT-0"
publish = false
repository = "https://github.com/substrate-developer-hub/substrate-node-template/"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
    "derive",
] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

[dev-dependencies]
sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

[features]
default = ["std"]
std = [
    "codec/std",
    "frame-benchmarking?/std",
    "frame-support/std",
    "frame-system/std",
    "scale-info/std",
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]

1 Answer 1

0

The code is outdated.

Check https://github.com/paritytech/substrate/blob/master/bin/node-template/pallets/template/src/lib.rs.


And I think you have ran the cargo update locally. Otherwise, the old code should also work.

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.