// This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #![cfg_attr(not(feature = "std"), no_std)] // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use frame::{ deps::frame_support::weights::{FixedFee, NoFee}, prelude::*, runtime::{ apis::{ self, impl_runtime_apis, ApplyExtrinsicResult, CheckInherentsResult, OpaqueMetadata, }, prelude::*, }, }; use frame_support::genesis_builder_helper::{build_config, create_default_config}; #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("minimal-runtime"), impl_name: create_runtime_str!("minimal-runtime"), authoring_version: 1, spec_version: 0, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, }; /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } type SignedExtra = ( frame_system::CheckNonZeroSender, frame_system::CheckSpecVersion, frame_system::CheckTxVersion, frame_system::CheckGenesis, frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, ); construct_runtime!( pub struct Runtime { System: frame_system, Timestamp: pallet_timestamp, Balances: pallet_balances, Sudo: pallet_sudo, TransactionPayment: pallet_transaction_payment, } ); parameter_types! { pub const Version: RuntimeVersion = VERSION; } #[derive_impl(frame_system::config_preludes::SolochainDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { type Block = Block; type Version = Version; type BlockHashCount = ConstU32<1024>; type AccountData = pallet_balances::AccountData<::Balance>; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Runtime { type AccountStore = System; } #[derive_impl(pallet_sudo::config_preludes::TestDefaultConfig as pallet_sudo::DefaultConfig)] impl pallet_sudo::Config for Runtime {} #[derive_impl(pallet_timestamp::config_preludes::TestDefaultConfig as pallet_timestamp::DefaultConfig)] impl pallet_timestamp::Config for Runtime {} #[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig as pallet_transaction_payment::DefaultConfig)] impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter; type WeightToFee = NoFee<::Balance>; type LengthToFee = FixedFee<1, ::Balance>; } type Block = frame::runtime::types_common::BlockOf; type Header = HeaderFor; type RuntimeExecutive = Executive, Runtime, AllPalletsWithSystem>; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; impl_runtime_apis! { impl apis::Core for Runtime { fn version() -> RuntimeVersion { VERSION } fn execute_block(block: Block) { RuntimeExecutive::execute_block(block) } fn initialize_block(header: &Header) { RuntimeExecutive::initialize_block(header) } } impl apis::Metadata for Runtime { fn metadata() -> OpaqueMetadata { OpaqueMetadata::new(Runtime::metadata().into()) } fn metadata_at_version(version: u32) -> Option { Runtime::metadata_at_version(version) } fn metadata_versions() -> Vec { Runtime::metadata_versions() } } impl apis::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ExtrinsicFor) -> ApplyExtrinsicResult { RuntimeExecutive::apply_extrinsic(extrinsic) } fn finalize_block() -> HeaderFor { RuntimeExecutive::finalize_block() } fn inherent_extrinsics(data: InherentData) -> Vec> { data.create_extrinsics() } fn check_inherents( block: Block, data: InherentData, ) -> CheckInherentsResult { data.check_extrinsics(&block) } } impl apis::TaggedTransactionQueue for Runtime { fn validate_transaction( source: TransactionSource, tx: ExtrinsicFor, block_hash: ::Hash, ) -> TransactionValidity { RuntimeExecutive::validate_transaction(source, tx, block_hash) } } impl apis::OffchainWorkerApi for Runtime { fn offchain_worker(header: &HeaderFor) { RuntimeExecutive::offchain_worker(header) } } impl apis::SessionKeys for Runtime { fn generate_session_keys(_seed: Option>) -> Vec { Default::default() } fn decode_session_keys( _encoded: Vec, ) -> Option, apis::KeyTypeId)>> { Default::default() } } impl apis::AccountNonceApi for Runtime { fn account_nonce(account: interface::AccountId) -> interface::Nonce { System::account_nonce(account) } } impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< Block, interface::Balance, > for Runtime { fn query_info(uxt: ExtrinsicFor, len: u32) -> RuntimeDispatchInfo { TransactionPayment::query_info(uxt, len) } fn query_fee_details(uxt: ExtrinsicFor, len: u32) -> FeeDetails { TransactionPayment::query_fee_details(uxt, len) } fn query_weight_to_fee(weight: Weight) -> interface::Balance { TransactionPayment::weight_to_fee(weight) } fn query_length_to_fee(length: u32) -> interface::Balance { TransactionPayment::length_to_fee(length) } } impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { create_default_config::() } fn build_config(config: Vec) -> sp_genesis_builder::Result { build_config::(config) } } } /// Some re-exports that the node side code needs to know. Some are useful in this context as well. /// /// Other types should preferably be private. // TODO: this should be standardized in some way, see: // https://github.com/paritytech/substrate/issues/10579#issuecomment-1600537558 pub mod interface { use super::Runtime; use frame::deps::frame_system; pub type Block = super::Block; pub use frame::runtime::types_common::OpaqueBlock; pub type AccountId = ::AccountId; pub type Nonce = ::Nonce; pub type Hash = ::Hash; pub type Balance = ::Balance; pub type MinimumBalance = ::ExistentialDeposit; }