Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add the calculated weights in the extrinsics
  • Loading branch information
AlexD10S committed Apr 4, 2023
commit 1802ffe7b43fbce68b7d10c56b81fa02abe14ee3
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/node-template/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../../../../frame/benchmarking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../../../frame/support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../../../frame/system" }
sp-std = { version = "5.0.0", default-features = false, path = "../../../../primitives/std" }
Copy link
Member

@ggwpez ggwpez Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just found yourself another issue (if you want obviously 😛).

Getting rid of this and using PhantomData from core::marker instead.


[dev-dependencies]
sp-core = { version = "7.0.0", path = "../../../../primitives/core" }
Expand Down
9 changes: 7 additions & 2 deletions bin/node-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use weights::*;

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

Expand All @@ -27,6 +30,8 @@ pub mod pallet {
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>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
}

// The pallet's runtime storage items.
Expand Down Expand Up @@ -64,7 +69,7 @@ pub mod pallet {
/// An example dispatchable that takes a singles value as a parameter, writes the value to
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
#[pallet::call_index(0)]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
#[pallet::weight(T::WeightInfo::do_something(*something))]
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
// Check that the extrinsic was signed and get the signer.
// This function will return an error if the extrinsic is not signed.
Expand All @@ -82,7 +87,7 @@ pub mod pallet {

/// An example dispatchable that may throw a custom error.
#[pallet::call_index(1)]
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
#[pallet::weight(T::WeightInfo::cause_error())]
pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
let _who = ensure_signed(origin)?;

Expand Down
1 change: 1 addition & 0 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ impl pallet_sudo::Config for Runtime {
/// Configure the pallet-template in pallets/template.
impl pallet_template::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_template::weights::SubstrateWeight<Runtime>;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down