Skip to content

Commit

Permalink
Weight function
Browse files Browse the repository at this point in the history
  • Loading branch information
gavofyork committed Nov 23, 2023
1 parent 4e9fd7e commit 6e17a83
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use sp_core::{self, RuntimeDebug};
#[doc(hidden)]
pub use sp_std::marker::PhantomData;
use sp_std::{self, fmt::Debug, prelude::*};
use sp_weights::Weight;
use tuplex::{PopFront, PushBack};

use super::{DispatchInfoOf, Dispatchable, OriginOf, PostDispatchInfoOf};
Expand Down Expand Up @@ -79,6 +80,11 @@ pub trait TransactionExtensionBase: TransactionExtensionInterior {
Ok(Self::Implicit::decode(&mut &[][..]).map_err(|_| IndeterminateImplicit)?)
}

/// The weight consumed by executing this extension instance fully during transaction dispatch.
fn weight(&self) -> Weight {
Weight::zero()
}

/// Returns the metadata for this extension.
///
/// As a [`TransactionExtension`] can be a tuple of [`TransactionExtension`]s we need to return
Expand Down Expand Up @@ -373,6 +379,11 @@ impl TransactionExtensionBase for Tuple {
fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
Ok(for_tuples!( ( #( Tuple.implicit()? ),* ) ))
}
fn weight(&self) -> Weight {
let mut weight = Weight::zero();
for_tuples!( #( weight += Tuple.weight(); )* );
weight
}
fn metadata() -> Vec<TransactionExtensionMetadata> {
let mut ids = Vec::new();
for_tuples!( #( ids.extend(Tuple::metadata()); )* );
Expand Down Expand Up @@ -461,6 +472,9 @@ impl TransactionExtensionBase for () {
fn implicit(&self) -> sp_std::result::Result<Self::Implicit, TransactionValidityError> {
Ok(())
}
fn weight(&self) -> Weight {
Weight::zero()
}
}

impl<Call: Dispatchable, Context> TransactionExtension<Call, Context> for () {
Expand Down

0 comments on commit 6e17a83

Please sign in to comment.