referrerpolicy=no-referrer-when-downgrade

pallet_meta_tx/
extension.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use super::*;
19use sp_runtime::impl_tx_ext_default;
20
21/// This type serves as a marker extension to differentiate meta-transactions from regular
22/// transactions. It implements the `TransactionExtension` trait and carries constant implicit data
23/// ("_meta_tx").
24#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo, DebugNoBound, DecodeWithMemTracking)]
25#[scale_info(skip_type_params(T))]
26pub struct MetaTxMarker<T> {
27	_phantom: core::marker::PhantomData<T>,
28}
29
30impl<T> MetaTxMarker<T> {
31	/// Creates new `TransactionExtension` with implicit meta tx marked.
32	pub fn new() -> Self {
33		Self { _phantom: Default::default() }
34	}
35}
36
37impl<T: Config + Send + Sync> TransactionExtension<T::RuntimeCall> for MetaTxMarker<T> {
38	const IDENTIFIER: &'static str = "MetaTxMarker";
39	type Implicit = [u8; 8];
40	type Val = ();
41	type Pre = ();
42	fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
43		Ok(*b"_meta_tx")
44	}
45	fn weight(&self, _: &T::RuntimeCall) -> Weight {
46		Weight::zero()
47	}
48	impl_tx_ext_default!(T::RuntimeCall; validate prepare);
49}