git.delta.rocks / unique-network / refs/commits / d1896d4a495f

difftreelog

source

runtime/common/mod.rs5.2 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617pub mod config;18pub mod construct_runtime;19pub mod dispatch;20pub mod ethereum;21pub mod instance;22pub mod maintenance;23pub mod runtime_apis;24pub mod xcm;2526#[cfg(feature = "scheduler")]27pub mod scheduler;2829pub mod sponsoring;30pub mod weights;3132#[cfg(test)]33pub mod tests;3435use sp_core::H160;36use frame_support::traits::{Currency, OnUnbalanced, Imbalance};37use sp_runtime::{38	generic,39	traits::{BlakeTwo256, BlockNumberProvider},40	impl_opaque_keys,41};42use sp_std::vec::Vec;4344#[cfg(feature = "std")]45use sp_version::NativeVersion;4647use crate::{48	Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,49	InherentDataExt,50};51use up_common::types::{AccountId, BlockNumber};5253#[macro_export]54macro_rules! unsupported {55	() => {56		pallet_common::unsupported!($crate::Runtime)57	};58}5960/// The address format for describing accounts.61pub type Address = sp_runtime::MultiAddress<AccountId, ()>;62/// Block header type as expected by this runtime.63pub type Header = generic::Header<BlockNumber, BlakeTwo256>;64/// Block type as expected by this runtime.65pub type Block = generic::Block<Header, UncheckedExtrinsic>;66/// A Block signed with a Justification67pub type SignedBlock = generic::SignedBlock<Block>;68/// BlockId type as expected by this runtime.69pub type BlockId = generic::BlockId<Block>;7071impl_opaque_keys! {72	pub struct SessionKeys {73		pub aura: Aura,74	}75}7677/// The version information used to identify this runtime when compiled natively.78#[cfg(feature = "std")]79pub fn native_version() -> NativeVersion {80	NativeVersion {81		runtime_version: crate::VERSION,82		can_author_with: Default::default(),83	}84}8586pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;8788pub type SignedExtra = (89	frame_system::CheckSpecVersion<Runtime>,90	frame_system::CheckTxVersion<Runtime>,91	frame_system::CheckGenesis<Runtime>,92	frame_system::CheckEra<Runtime>,93	frame_system::CheckNonce<Runtime>,94	frame_system::CheckWeight<Runtime>,95	maintenance::CheckMaintenance,96	ChargeTransactionPayment,97	//pallet_contract_helpers::ContractHelpersExtension<Runtime>,98	pallet_ethereum::FakeTransactionFinalizer<Runtime>,99);100101/// Unchecked extrinsic type as expected by this runtime.102pub type UncheckedExtrinsic =103	fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;104105/// Extrinsic type that has already been checked.106pub type CheckedExtrinsic =107	fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;108109/// Executive: handles dispatch to the various modules.110pub type Executive = frame_executive::Executive<111	Runtime,112	Block,113	frame_system::ChainContext<Runtime>,114	Runtime,115	AllPalletsWithSystem,116>;117118type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;119120pub struct DealWithFees;121impl OnUnbalanced<NegativeImbalance> for DealWithFees {122	fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {123		if let Some(fees) = fees_then_tips.next() {124			// for fees, 100% to treasury125			let mut split = fees.ration(100, 0);126			if let Some(tips) = fees_then_tips.next() {127				// for tips, if any, 100% to treasury128				tips.ration_merge_into(100, 0, &mut split);129			}130			Treasury::on_unbalanced(split.0);131			// Author::on_unbalanced(split.1);132		}133	}134}135136pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);137138impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider139	for RelayChainBlockNumberProvider<T>140{141	type BlockNumber = BlockNumber;142143	fn current_block_number() -> Self::BlockNumber {144		cumulus_pallet_parachain_system::Pallet::<T>::validation_data()145			.map(|d| d.relay_parent_number)146			.unwrap_or_default()147	}148}149150pub(crate) struct CheckInherents;151152impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {153	fn check_inherents(154		block: &Block,155		relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,156	) -> sp_inherents::CheckInherentsResult {157		let relay_chain_slot = relay_state_proof158			.read_slot()159			.expect("Could not read the relay chain slot from the proof");160161		let inherent_data =162			cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(163				relay_chain_slot,164				sp_std::time::Duration::from_secs(6),165			)166			.create_inherent_data()167			.expect("Could not create the timestamp inherent data");168169		inherent_data.check_extrinsics(block)170	}171}172173#[derive(codec::Encode, codec::Decode)]174pub enum XCMPMessage<XAccountId, XBalance> {175	/// Transfer tokens to the given account from the Parachain account.176	TransferToken(XAccountId, XBalance),177}