fp_self_contained/
lib.rs

1// This file is part of Frontier.
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
18#![cfg_attr(not(feature = "std"), no_std)]
19#![warn(unused_crate_dependencies)]
20
21mod checked_extrinsic;
22mod unchecked_extrinsic;
23
24pub use crate::{
25	checked_extrinsic::{CheckedExtrinsic, CheckedSignature},
26	unchecked_extrinsic::UncheckedExtrinsic,
27};
28
29use sp_runtime::{
30	traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf},
31	transaction_validity::{TransactionValidity, TransactionValidityError},
32};
33
34/// A call that has self-contained functions. A self-contained
35/// function is something that has its signature embedded in its call.
36pub trait SelfContainedCall: Dispatchable {
37	/// Validated signature info.
38	type SignedInfo;
39
40	/// Returns whether the current call is a self-contained function.
41	fn is_self_contained(&self) -> bool;
42	/// Check signatures of a self-contained function. Returns `None`
43	/// if the function is not a self-contained.
44	fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>>;
45	/// Validate a self-contained function. Returns `None` if the
46	/// function is not a self-contained.
47	fn validate_self_contained(
48		&self,
49		info: &Self::SignedInfo,
50		dispatch_info: &DispatchInfoOf<Self>,
51		len: usize,
52	) -> Option<TransactionValidity>;
53	/// Do any pre-flight stuff for a self-contained call.
54	///
55	/// Note this function by default delegates to `validate_self_contained`, so that
56	/// all checks performed for the transaction queue are also performed during
57	/// the dispatch phase (applying the extrinsic).
58	///
59	/// If you ever override this function, you need to make sure to always
60	/// perform the same validation as in `validate_self_contained`.
61	///
62	/// Returns `None` if the function is not a self-contained.
63	fn pre_dispatch_self_contained(
64		&self,
65		info: &Self::SignedInfo,
66		dispatch_info: &DispatchInfoOf<Self>,
67		len: usize,
68	) -> Option<Result<(), TransactionValidityError>> {
69		self.validate_self_contained(info, dispatch_info, len)
70			.map(|res| res.map(|_| ()))
71	}
72	/// Apply a self-contained function. Returns `None` if the
73	/// function is not a self-contained.
74	fn apply_self_contained(
75		self,
76		info: Self::SignedInfo,
77	) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>>;
78}