referrerpolicy=no-referrer-when-downgrade

polkadot_omni_node_lib/common/
aura.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Aura-related primitives for cumulus parachain collators.
18
19use codec::Codec;
20use cumulus_primitives_aura::AuraUnincludedSegmentApi;
21use sp_consensus_aura::AuraApi;
22use sp_runtime::{
23	app_crypto::{AppCrypto, AppPair, AppSignature, Pair},
24	traits::Block as BlockT,
25};
26
27/// Convenience trait for defining the basic bounds of an `AuraId`.
28pub trait AuraIdT: AppCrypto<Pair = Self::BoundedPair> + Codec + Send {
29	/// Extra bounds for the `Pair`.
30	type BoundedPair: AppPair + AppCrypto<Signature = Self::BoundedSignature>;
31
32	/// Extra bounds for the `Signature`.
33	type BoundedSignature: AppSignature
34		+ TryFrom<Vec<u8>>
35		+ std::hash::Hash
36		+ sp_runtime::traits::Member
37		+ Codec;
38}
39
40impl<T> AuraIdT for T
41where
42	T: AppCrypto + Codec + Send + Sync,
43	<<T as AppCrypto>::Pair as AppCrypto>::Signature:
44		TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
45{
46	type BoundedPair = <T as AppCrypto>::Pair;
47	type BoundedSignature = <<T as AppCrypto>::Pair as AppCrypto>::Signature;
48}
49
50/// Convenience trait for defining the basic bounds of a parachain runtime that supports
51/// the Aura consensus.
52pub trait AuraRuntimeApi<Block: BlockT, AuraId: AuraIdT>:
53	sp_api::ApiExt<Block>
54	+ AuraApi<Block, <AuraId::BoundedPair as Pair>::Public>
55	+ AuraUnincludedSegmentApi<Block>
56	+ Sized
57{
58	/// Check if the runtime has the Aura API.
59	fn has_aura_api(&self, at: Block::Hash) -> bool {
60		self.has_api::<dyn AuraApi<Block, <AuraId::BoundedPair as Pair>::Public>>(at)
61			.unwrap_or(false)
62	}
63}
64
65impl<T, Block: BlockT, AuraId: AuraIdT> AuraRuntimeApi<Block, AuraId> for T where
66	T: sp_api::ApiExt<Block>
67		+ AuraApi<Block, <AuraId::BoundedPair as Pair>::Public>
68		+ AuraUnincludedSegmentApi<Block>
69{
70}