// This is free and unencumbered software released into the public domain. // // Anyone is free to copy, modify, publish, use, compile, sell, or // distribute this software, either in source code form or as a compiled // binary, for any purpose, commercial or non-commercial, and by any // means. // // In jurisdictions that recognize copyright laws, the author or authors // of this software dedicate any and all copyright interest in the // software to the public domain. We make this dedication for the benefit // of the public at large and to the detriment of our heirs and // successors. We intend this dedication to be an overt act of // relinquishment in perpetuity of all present and future rights to this // software under copyright law. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // // For more information, please refer to // External crates imports use alloc::vec::Vec; use pezframe_support::{ genesis_builder_helper::{build_state, get_preset}, weights::Weight, }; use pezpallet_grandpa::AuthorityId as GrandpaId; use pezsp_api::impl_runtime_apis; use pezsp_consensus_aura::sr25519::AuthorityId as AuraId; use pezsp_core::{crypto::KeyTypeId, OpaqueMetadata}; use pezsp_runtime::{ traits::{Block as BlockT, NumberFor}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; use pezsp_version::RuntimeVersion; // Local module imports use super::{ AccountId, Aura, Balance, Block, Executive, Grandpa, InherentDataExt, Nonce, Runtime, RuntimeCall, RuntimeGenesisConfig, SessionKeys, System, TransactionPayment, VERSION, }; impl_runtime_apis! { impl pezsp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION } fn execute_block(block: ::LazyBlock) { Executive::execute_block(block); } fn initialize_block(header: &::Header) -> pezsp_runtime::ExtrinsicInclusionMode { Executive::initialize_block(header) } } impl pezsp_api::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 pezframe_support::view_functions::runtime_api::RuntimeViewFunction for Runtime { fn execute_view_function(id: pezframe_support::view_functions::ViewFunctionId, input: Vec) -> Result, pezframe_support::view_functions::ViewFunctionDispatchError> { Runtime::execute_view_function(id, input) } } impl pezsp_block_builder::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { Executive::apply_extrinsic(extrinsic) } fn finalize_block() -> ::Header { Executive::finalize_block() } fn inherent_extrinsics(data: pezsp_inherents::InherentData) -> Vec<::Extrinsic> { data.create_extrinsics() } fn check_inherents( block: ::LazyBlock, data: pezsp_inherents::InherentData, ) -> pezsp_inherents::CheckInherentsResult { data.check_extrinsics(&block) } } impl pezsp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { fn validate_transaction( source: TransactionSource, tx: ::Extrinsic, block_hash: ::Hash, ) -> TransactionValidity { Executive::validate_transaction(source, tx, block_hash) } } impl pezsp_offchain::OffchainWorkerApi for Runtime { fn offchain_worker(header: &::Header) { Executive::offchain_worker(header) } } impl pezsp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> pezsp_consensus_aura::SlotDuration { pezsp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) } fn authorities() -> Vec { pezpallet_aura::Authorities::::get().into_inner() } } impl pezsp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { SessionKeys::generate(seed) } fn decode_session_keys( encoded: Vec, ) -> Option, KeyTypeId)>> { SessionKeys::decode_into_raw_public_keys(&encoded) } } impl pezsp_consensus_grandpa::GrandpaApi for Runtime { fn grandpa_authorities() -> pezsp_consensus_grandpa::AuthorityList { Grandpa::grandpa_authorities() } fn current_set_id() -> pezsp_consensus_grandpa::SetId { Grandpa::current_set_id() } fn submit_report_equivocation_unsigned_extrinsic( _equivocation_proof: pezsp_consensus_grandpa::EquivocationProof< ::Hash, NumberFor, >, _key_owner_proof: pezsp_consensus_grandpa::OpaqueKeyOwnershipProof, ) -> Option<()> { None } fn generate_key_ownership_proof( _set_id: pezsp_consensus_grandpa::SetId, _authority_id: GrandpaId, ) -> Option { // NOTE: this is the only implementation possible since we've // defined our key owner proof type as a bottom type (i.e. a type // with no values). None } } impl pezframe_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Nonce { System::account_nonce(account) } } impl pezpallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { fn query_info( uxt: ::Extrinsic, len: u32, ) -> pezpallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { TransactionPayment::query_info(uxt, len) } fn query_fee_details( uxt: ::Extrinsic, len: u32, ) -> pezpallet_transaction_payment::FeeDetails { TransactionPayment::query_fee_details(uxt, len) } fn query_weight_to_fee(weight: Weight) -> Balance { TransactionPayment::weight_to_fee(weight) } fn query_length_to_fee(length: u32) -> Balance { TransactionPayment::length_to_fee(length) } } impl pezpallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi for Runtime { fn query_call_info( call: RuntimeCall, len: u32, ) -> pezpallet_transaction_payment::RuntimeDispatchInfo { TransactionPayment::query_call_info(call, len) } fn query_call_fee_details( call: RuntimeCall, len: u32, ) -> pezpallet_transaction_payment::FeeDetails { TransactionPayment::query_call_fee_details(call, len) } fn query_weight_to_fee(weight: Weight) -> Balance { TransactionPayment::weight_to_fee(weight) } fn query_length_to_fee(length: u32) -> Balance { TransactionPayment::length_to_fee(length) } } #[cfg(feature = "runtime-benchmarks")] impl pezframe_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( Vec, Vec, ) { use pezframe_benchmarking::{baseline, BenchmarkList}; use pezframe_support::traits::StorageInfoTrait; use pezframe_system_benchmarking::Pezpallet as SystemBench; use pezframe_system_benchmarking::extensions::Pezpallet as SystemExtensionsBench; use baseline::Pezpallet as BaselineBench; use super::*; let mut list = Vec::::new(); list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); (list, storage_info) } #[allow(non_local_definitions)] fn dispatch_benchmark( config: pezframe_benchmarking::BenchmarkConfig ) -> Result, alloc::string::String> { use pezframe_benchmarking::{baseline, BenchmarkBatch}; use pezsp_storage::TrackedStorageKey; use pezframe_system_benchmarking::Pezpallet as SystemBench; use pezframe_system_benchmarking::extensions::Pezpallet as SystemExtensionsBench; use baseline::Pezpallet as BaselineBench; use super::*; impl pezframe_system_benchmarking::Config for Runtime {} impl baseline::Config for Runtime {} use pezframe_support::traits::WhitelistedStorageKeys; let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); add_benchmarks!(params, batches); Ok(batches) } } #[cfg(feature = "try-runtime")] impl pezframe_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: pezframe_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. If any of the pre/post migration checks fail, we shall stop // right here and right now. let weight = Executive::try_runtime_upgrade(checks).unwrap(); (weight, super::configs::RuntimeBlockWeights::get().max_block) } fn execute_block( block: ::LazyBlock, state_root_check: bool, signature_check: bool, select: pezframe_try_runtime::TryStateSelect ) -> Weight { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed") } } impl pezsp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> pezsp_genesis_builder::Result { build_state::(config) } fn get_preset(id: &Option) -> Option> { get_preset::(id, crate::genesis_config_presets::get_preset) } fn preset_names() -> Vec { crate::genesis_config_presets::preset_names() } } }