From 6ab76d3641c7cf7bb82ff7589fc742c0aaed92e5 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 02 Oct 2023 22:07:32 +0000 Subject: [PATCH] style: retab runtime apis --- --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -26,713 +26,676 @@ #[macro_export] macro_rules! impl_common_runtime_apis { - ( - $( - #![custom_apis] + ( + $( + #![custom_apis] - $($custom_apis:tt)+ - )? - ) => { - use sp_std::prelude::*; - use sp_api::impl_runtime_apis; - use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160}; - use sp_runtime::{ - Permill, - traits::{Block as BlockT}, - transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, DispatchError, - }; - use frame_support::{ - pallet_prelude::Weight, - traits::OnFinalize, - }; - use fp_rpc::TransactionStatus; - use pallet_transaction_payment::{ - FeeDetails, RuntimeDispatchInfo, - }; - use pallet_evm::{ - Runner, account::CrossAccountId as _, - Account as EVMAccount, FeeCalculator, - }; - use runtime_common::{ - sponsoring::{SponsorshipPredict, UniqueSponsorshipPredict}, - dispatch::CollectionDispatch, - config::ethereum::CrossAccountId, - }; - use up_data_structs::*; + $($custom_apis:tt)+ + )? + ) => { + use sp_std::prelude::*; + use sp_api::impl_runtime_apis; + use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160}; + use sp_runtime::{ + Permill, + traits::{Block as BlockT}, + transaction_validity::{TransactionSource, TransactionValidity}, + ApplyExtrinsicResult, DispatchError, + }; + use frame_support::{ + pallet_prelude::Weight, + traits::OnFinalize, + }; + use fp_rpc::TransactionStatus; + use pallet_transaction_payment::{ + FeeDetails, RuntimeDispatchInfo, + }; + use pallet_evm::{ + Runner, account::CrossAccountId as _, + Account as EVMAccount, FeeCalculator, + }; + use runtime_common::{ + sponsoring::{SponsorshipPredict, UniqueSponsorshipPredict}, + dispatch::CollectionDispatch, + config::ethereum::CrossAccountId, + }; + use up_data_structs::*; + use crate::Block; + impl_runtime_apis! { + $($($custom_apis)+)? - impl_runtime_apis! { - $($($custom_apis)+)? + impl up_rpc::UniqueApi for Runtime { + fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result, DispatchError> { + dispatch_unique_runtime!(collection.account_tokens(account)) + } + fn collection_tokens(collection: CollectionId) -> Result, DispatchError> { + dispatch_unique_runtime!(collection.collection_tokens()) + } + fn token_exists(collection: CollectionId, token: TokenId) -> Result { + dispatch_unique_runtime!(collection.token_exists(token)) + } - impl up_rpc::UniqueApi for Runtime { - fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result, DispatchError> { - dispatch_unique_runtime!(collection.account_tokens(account)) - } - fn collection_tokens(collection: CollectionId) -> Result, DispatchError> { - dispatch_unique_runtime!(collection.collection_tokens()) - } - fn token_exists(collection: CollectionId, token: TokenId) -> Result { - dispatch_unique_runtime!(collection.token_exists(token)) - } + fn token_owner(collection: CollectionId, token: TokenId) -> Result, DispatchError> { + dispatch_unique_runtime!(collection.token_owner(token).ok()) + } - fn token_owner(collection: CollectionId, token: TokenId) -> Result, DispatchError> { - dispatch_unique_runtime!(collection.token_owner(token).ok()) - } + fn token_owners(collection: CollectionId, token: TokenId) -> Result, DispatchError> { + dispatch_unique_runtime!(collection.token_owners(token)) + } - fn token_owners(collection: CollectionId, token: TokenId) -> Result, DispatchError> { - dispatch_unique_runtime!(collection.token_owners(token)) - } + fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result, DispatchError> { + let budget = up_data_structs::budget::Value::new(10); - fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result, DispatchError> { - let budget = up_data_structs::budget::Value::new(10); + >::find_topmost_owner(collection, token, &budget) + } + fn token_children(collection: CollectionId, token: TokenId) -> Result, DispatchError> { + Ok(>::token_children_ids(collection, token)) + } + fn collection_properties( + collection: CollectionId, + keys: Option>> + ) -> Result, DispatchError> { + let keys = keys.map( + |keys| Common::bytes_keys_to_property_keys(keys) + ).transpose()?; - >::find_topmost_owner(collection, token, &budget) - } - fn token_children(collection: CollectionId, token: TokenId) -> Result, DispatchError> { - Ok(>::token_children_ids(collection, token)) - } - fn collection_properties( - collection: CollectionId, - keys: Option>> - ) -> Result, DispatchError> { - let keys = keys.map( - |keys| Common::bytes_keys_to_property_keys(keys) - ).transpose()?; + Common::filter_collection_properties(collection, keys) + } - Common::filter_collection_properties(collection, keys) - } + fn token_properties( + collection: CollectionId, + token_id: TokenId, + keys: Option>> + ) -> Result, DispatchError> { + let keys = keys.map( + |keys| Common::bytes_keys_to_property_keys(keys) + ).transpose()?; - fn token_properties( - collection: CollectionId, - token_id: TokenId, - keys: Option>> - ) -> Result, DispatchError> { - let keys = keys.map( - |keys| Common::bytes_keys_to_property_keys(keys) - ).transpose()?; + dispatch_unique_runtime!(collection.token_properties(token_id, keys)) + } - dispatch_unique_runtime!(collection.token_properties(token_id, keys)) - } + fn property_permissions( + collection: CollectionId, + keys: Option>> + ) -> Result, DispatchError> { + let keys = keys.map( + |keys| Common::bytes_keys_to_property_keys(keys) + ).transpose()?; - fn property_permissions( - collection: CollectionId, - keys: Option>> - ) -> Result, DispatchError> { - let keys = keys.map( - |keys| Common::bytes_keys_to_property_keys(keys) - ).transpose()?; + Common::filter_property_permissions(collection, keys) + } - Common::filter_property_permissions(collection, keys) - } + fn token_data( + collection: CollectionId, + token_id: TokenId, + keys: Option>> + ) -> Result, DispatchError> { + let token_data = TokenData { + properties: Self::token_properties(collection, token_id, keys)?, + owner: Self::token_owner(collection, token_id)?, + pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0), + }; - fn token_data( - collection: CollectionId, - token_id: TokenId, - keys: Option>> - ) -> Result, DispatchError> { - let token_data = TokenData { - properties: Self::token_properties(collection, token_id, keys)?, - owner: Self::token_owner(collection, token_id)?, - pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0), - }; + Ok(token_data) + } - Ok(token_data) - } + fn total_supply(collection: CollectionId) -> Result { + dispatch_unique_runtime!(collection.total_supply()) + } + fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result { + dispatch_unique_runtime!(collection.account_balance(account)) + } + fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result { + dispatch_unique_runtime!(collection.balance(account, token)) + } + fn allowance( + collection: CollectionId, + sender: CrossAccountId, + spender: CrossAccountId, + token: TokenId, + ) -> Result { + dispatch_unique_runtime!(collection.allowance(sender, spender, token)) + } - fn total_supply(collection: CollectionId) -> Result { - dispatch_unique_runtime!(collection.total_supply()) - } - fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result { - dispatch_unique_runtime!(collection.account_balance(account)) - } - fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result { - dispatch_unique_runtime!(collection.balance(account, token)) - } - fn allowance( - collection: CollectionId, - sender: CrossAccountId, - spender: CrossAccountId, - token: TokenId, - ) -> Result { - dispatch_unique_runtime!(collection.allowance(sender, spender, token)) - } + fn adminlist(collection: CollectionId) -> Result, DispatchError> { + Ok(>::adminlist(collection)) + } + fn allowlist(collection: CollectionId) -> Result, DispatchError> { + Ok(>::allowlist(collection)) + } + fn allowed(collection: CollectionId, user: CrossAccountId) -> Result { + Ok(>::allowed(collection, user)) + } + fn last_token_id(collection: CollectionId) -> Result { + dispatch_unique_runtime!(collection.last_token_id()) + } + fn collection_by_id(collection: CollectionId) -> Result>, DispatchError> { + Ok(>::rpc_collection(collection)) + } + fn collection_stats() -> Result { + Ok(>::collection_stats()) + } + fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result, DispatchError> { + Ok( as SponsorshipPredict>::predict( + collection, + account, + token + )) + } - fn adminlist(collection: CollectionId) -> Result, DispatchError> { - Ok(>::adminlist(collection)) - } - fn allowlist(collection: CollectionId) -> Result, DispatchError> { - Ok(>::allowlist(collection)) - } - fn allowed(collection: CollectionId, user: CrossAccountId) -> Result { - Ok(>::allowed(collection, user)) - } - fn last_token_id(collection: CollectionId) -> Result { - dispatch_unique_runtime!(collection.last_token_id()) - } - fn collection_by_id(collection: CollectionId) -> Result>, DispatchError> { - Ok(>::rpc_collection(collection)) - } - fn collection_stats() -> Result { - Ok(>::collection_stats()) - } - fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result, DispatchError> { - Ok( as SponsorshipPredict>::predict( - collection, - account, - token - )) - } + fn effective_collection_limits(collection: CollectionId) -> Result, DispatchError> { + Ok(>::effective_collection_limits(collection)) + } - fn effective_collection_limits(collection: CollectionId) -> Result, DispatchError> { - Ok(>::effective_collection_limits(collection)) - } + fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result, DispatchError> { + dispatch_unique_runtime!(collection.total_pieces(token_id)) + } - fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result, DispatchError> { - dispatch_unique_runtime!(collection.total_pieces(token_id)) - } + fn allowance_for_all(collection: CollectionId, owner: CrossAccountId, operator: CrossAccountId) -> Result { + dispatch_unique_runtime!(collection.allowance_for_all(owner, operator)) + } + } - fn allowance_for_all(collection: CollectionId, owner: CrossAccountId, operator: CrossAccountId) -> Result { - dispatch_unique_runtime!(collection.allowance_for_all(owner, operator)) - } - } + impl app_promotion_rpc::AppPromotionApi for Runtime { + #[allow(unused_variables)] + fn total_staked(staker: Option) -> Result { + #[cfg(not(feature = "app-promotion"))] + return unsupported!(); - impl app_promotion_rpc::AppPromotionApi for Runtime { - #[allow(unused_variables)] - fn total_staked(staker: Option) -> Result { - #[cfg(not(feature = "app-promotion"))] - return unsupported!(); + #[cfg(feature = "app-promotion")] + return Ok(>::cross_id_total_staked(staker).unwrap_or_default()); + } - #[cfg(feature = "app-promotion")] - return Ok(>::cross_id_total_staked(staker).unwrap_or_default()); - } + #[allow(unused_variables)] + fn total_staked_per_block(staker: CrossAccountId) -> Result, DispatchError> { + #[cfg(not(feature = "app-promotion"))] + return unsupported!(); - #[allow(unused_variables)] - fn total_staked_per_block(staker: CrossAccountId) -> Result, DispatchError> { - #[cfg(not(feature = "app-promotion"))] - return unsupported!(); + #[cfg(feature = "app-promotion")] + return Ok(>::cross_id_total_staked_per_block(staker)); + } - #[cfg(feature = "app-promotion")] - return Ok(>::cross_id_total_staked_per_block(staker)); - } + #[allow(unused_variables)] + fn pending_unstake(staker: Option) -> Result { + #[cfg(not(feature = "app-promotion"))] + return unsupported!(); - #[allow(unused_variables)] - fn pending_unstake(staker: Option) -> Result { - #[cfg(not(feature = "app-promotion"))] - return unsupported!(); + #[cfg(feature = "app-promotion")] + return Ok(>::cross_id_pending_unstake(staker)); + } - #[cfg(feature = "app-promotion")] - return Ok(>::cross_id_pending_unstake(staker)); - } + #[allow(unused_variables)] + fn pending_unstake_per_block(staker: CrossAccountId) -> Result, DispatchError> { + #[cfg(not(feature = "app-promotion"))] + return unsupported!(); - #[allow(unused_variables)] - fn pending_unstake_per_block(staker: CrossAccountId) -> Result, DispatchError> { - #[cfg(not(feature = "app-promotion"))] - return unsupported!(); + #[cfg(feature = "app-promotion")] + return Ok(>::cross_id_pending_unstake_per_block(staker)) + } + } - #[cfg(feature = "app-promotion")] - return Ok(>::cross_id_pending_unstake_per_block(staker)) - } - } - - impl sp_api::Core for Runtime { - fn version() -> RuntimeVersion { - VERSION - } - - fn execute_block(block: Block) { - Executive::execute_block(block) - } + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + VERSION + } - fn initialize_block(header: &::Header) { - Executive::initialize_block(header) - } - } - - impl sp_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 execute_block(block: Block) { + Executive::execute_block(block) + } - fn metadata_versions() -> sp_std::vec::Vec { - Runtime::metadata_versions() - } - } - - impl sp_block_builder::BlockBuilder for Runtime { - fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { - Executive::apply_extrinsic(extrinsic) - } + fn initialize_block(header: &::Header) { + Executive::initialize_block(header) + } + } - fn finalize_block() -> ::Header { - Executive::finalize_block() - } + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + OpaqueMetadata::new(Runtime::metadata().into()) + } - fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { - data.create_extrinsics() - } + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } - fn check_inherents( - block: Block, - data: sp_inherents::InherentData, - ) -> sp_inherents::CheckInherentsResult { - data.check_extrinsics(&block) - } + fn metadata_versions() -> sp_std::vec::Vec { + Runtime::metadata_versions() + } + } - // fn random_seed() -> ::Hash { - // RandomnessCollectiveFlip::random_seed().0 - // } - } + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { + Executive::apply_extrinsic(extrinsic) + } - impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { - fn validate_transaction( - source: TransactionSource, - tx: ::Extrinsic, - hash: ::Hash, - ) -> TransactionValidity { - Executive::validate_transaction(source, tx, hash) - } - } + fn finalize_block() -> ::Header { + Executive::finalize_block() + } - impl sp_offchain::OffchainWorkerApi for Runtime { - fn offchain_worker(header: &::Header) { - Executive::offchain_worker(header) - } - } + fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<::Extrinsic> { + data.create_extrinsics() + } - impl fp_rpc::EthereumRuntimeRPCApi for Runtime { - fn chain_id() -> u64 { - ::ChainId::get() - } + fn check_inherents( + block: Block, + data: sp_inherents::InherentData, + ) -> sp_inherents::CheckInherentsResult { + data.check_extrinsics(&block) + } - fn account_basic(address: H160) -> EVMAccount { - let (account, _) = EVM::account_basic(&address); - account - } + // fn random_seed() -> ::Hash { + // RandomnessCollectiveFlip::random_seed().0 + // } + } - fn gas_price() -> U256 { - let (price, _) = ::FeeCalculator::min_gas_price(); - price - } + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + tx: ::Extrinsic, + hash: ::Hash, + ) -> TransactionValidity { + Executive::validate_transaction(source, tx, hash) + } + } - fn account_code_at(address: H160) -> Vec { - use pallet_evm::OnMethodCall; - ::OnMethodCall::get_code(&address) - .unwrap_or_else(|| pallet_evm::AccountCodes::::get(address)) - } + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(header: &::Header) { + Executive::offchain_worker(header) + } + } - fn author() -> H160 { - >::find_author() - } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { + fn chain_id() -> u64 { + ::ChainId::get() + } - fn storage_at(address: H160, index: U256) -> H256 { - let mut tmp = [0u8; 32]; - index.to_big_endian(&mut tmp); - pallet_evm::AccountStorages::::get(address, H256::from_slice(&tmp[..])) - } + fn account_basic(address: H160) -> EVMAccount { + let (account, _) = EVM::account_basic(&address); + account + } - #[allow(clippy::redundant_closure)] - fn call( - from: H160, - to: H160, - data: Vec, - value: U256, - gas_limit: U256, - max_fee_per_gas: Option, - max_priority_fee_per_gas: Option, - nonce: Option, - estimate: bool, - access_list: Option)>>, - ) -> Result { - let config = if estimate { - let mut config = ::config().clone(); - config.estimate = true; - Some(config) - } else { - None - }; + fn gas_price() -> U256 { + let (price, _) = ::FeeCalculator::min_gas_price(); + price + } - let is_transactional = false; - let validate = false; - ::Runner::call( - CrossAccountId::from_eth(from), - to, - data, - value, - gas_limit.low_u64(), - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - access_list.unwrap_or_default(), - is_transactional, - validate, - // TODO we probably want to support external cost recording in non-transactional calls - None, - None, + fn account_code_at(address: H160) -> Vec { + use pallet_evm::OnMethodCall; + ::OnMethodCall::get_code(&address) + .unwrap_or_else(|| pallet_evm::AccountCodes::::get(address)) + } - config.as_ref().unwrap_or_else(|| ::config()), - ).map_err(|err| err.error.into()) - } + fn author() -> H160 { + >::find_author() + } - #[allow(clippy::redundant_closure)] - fn create( - from: H160, - data: Vec, - value: U256, - gas_limit: U256, - max_fee_per_gas: Option, - max_priority_fee_per_gas: Option, - nonce: Option, - estimate: bool, - access_list: Option)>>, - ) -> Result { - let config = if estimate { - let mut config = ::config().clone(); - config.estimate = true; - Some(config) - } else { - None - }; + fn storage_at(address: H160, index: U256) -> H256 { + let mut tmp = [0u8; 32]; + index.to_big_endian(&mut tmp); + pallet_evm::AccountStorages::::get(address, H256::from_slice(&tmp[..])) + } - let is_transactional = false; - let validate = false; - ::Runner::create( - CrossAccountId::from_eth(from), - data, - value, - gas_limit.low_u64(), - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - access_list.unwrap_or_default(), - is_transactional, - validate, - // TODO we probably want to support external cost recording in non-transactional calls - None, - None, + #[allow(clippy::redundant_closure)] + fn call( + from: H160, + to: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + estimate: bool, + access_list: Option)>>, + ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + Some(config) + } else { + None + }; - config.as_ref().unwrap_or_else(|| ::config()), - ).map_err(|err| err.error.into()) - } + let is_transactional = false; + let validate = false; + ::Runner::call( + CrossAccountId::from_eth(from), + to, + data, + value, + gas_limit.low_u64(), + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + is_transactional, + validate, + // TODO we probably want to support external cost recording in non-transactional calls + None, + None, - fn current_transaction_statuses() -> Option> { - pallet_ethereum::CurrentTransactionStatuses::::get() - } + config.as_ref().unwrap_or_else(|| ::config()), + ).map_err(|err| err.error.into()) + } - fn current_block() -> Option { - pallet_ethereum::CurrentBlock::::get() - } + #[allow(clippy::redundant_closure)] + fn create( + from: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + estimate: bool, + access_list: Option)>>, + ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + Some(config) + } else { + None + }; - fn current_receipts() -> Option> { - pallet_ethereum::CurrentReceipts::::get() - } + let is_transactional = false; + let validate = false; + ::Runner::create( + CrossAccountId::from_eth(from), + data, + value, + gas_limit.low_u64(), + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + is_transactional, + validate, + // TODO we probably want to support external cost recording in non-transactional calls + None, + None, - fn current_all() -> ( - Option, - Option>, - Option> - ) { - ( - pallet_ethereum::CurrentBlock::::get(), - pallet_ethereum::CurrentReceipts::::get(), - pallet_ethereum::CurrentTransactionStatuses::::get() - ) - } + config.as_ref().unwrap_or_else(|| ::config()), + ).map_err(|err| err.error.into()) + } - fn extrinsic_filter(xts: Vec<::Extrinsic>) -> Vec { - xts.into_iter().filter_map(|xt| match xt.0.function { - RuntimeCall::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction), - _ => None - }).collect() - } + fn current_transaction_statuses() -> Option> { + pallet_ethereum::CurrentTransactionStatuses::::get() + } - fn elasticity() -> Option { - None - } + fn current_block() -> Option { + pallet_ethereum::CurrentBlock::::get() + } - fn gas_limit_multiplier_support() {} + fn current_receipts() -> Option> { + pallet_ethereum::CurrentReceipts::::get() + } - fn pending_block( - xts: Vec<::Extrinsic>, - ) -> (Option, Option>) { - for ext in xts.into_iter() { - let _ = Executive::apply_extrinsic(ext); - } + fn current_all() -> ( + Option, + Option>, + Option> + ) { + ( + pallet_ethereum::CurrentBlock::::get(), + pallet_ethereum::CurrentReceipts::::get(), + pallet_ethereum::CurrentTransactionStatuses::::get() + ) + } - Ethereum::on_finalize(System::block_number() + 1); + fn extrinsic_filter(xts: Vec<::Extrinsic>) -> Vec { + xts.into_iter().filter_map(|xt| match xt.0.function { + RuntimeCall::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction), + _ => None + }).collect() + } - ( - pallet_ethereum::CurrentBlock::::get(), - pallet_ethereum::CurrentTransactionStatuses::::get() - ) - } - } + fn elasticity() -> Option { + None + } - impl fp_rpc::ConvertTransactionRuntimeApi for Runtime { - fn convert_transaction(transaction: pallet_ethereum::Transaction) -> ::Extrinsic { - UncheckedExtrinsic::new_unsigned( - pallet_ethereum::Call::::transact { transaction }.into(), - ) - } - } + fn gas_limit_multiplier_support() {} - impl sp_session::SessionKeys for Runtime { - fn decode_session_keys( - encoded: Vec, - ) -> Option, KeyTypeId)>> { - SessionKeys::decode_into_raw_public_keys(&encoded) - } + fn pending_block( + xts: Vec<::Extrinsic>, + ) -> (Option, Option>) { + for ext in xts.into_iter() { + let _ = Executive::apply_extrinsic(ext); + } - fn generate_session_keys(seed: Option>) -> Vec { - SessionKeys::generate(seed) - } - } + Ethereum::on_finalize(System::block_number() + 1); - impl sp_consensus_aura::AuraApi for Runtime { - fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) - } + ( + pallet_ethereum::CurrentBlock::::get(), + pallet_ethereum::CurrentTransactionStatuses::::get() + ) + } + } - fn authorities() -> Vec { - Aura::authorities().to_vec() - } - } + impl sp_session::SessionKeys for Runtime { + fn decode_session_keys( + encoded: Vec, + ) -> Option, KeyTypeId)>> { + SessionKeys::decode_into_raw_public_keys(&encoded) + } - impl cumulus_primitives_core::CollectCollationInfo for Runtime { - fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { - ParachainSystem::collect_collation_info(header) - } - } + fn generate_session_keys(seed: Option>) -> Vec { + SessionKeys::generate(seed) + } + } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { - fn account_nonce(account: AccountId) -> Index { - System::account_nonce(account) - } - } + impl sp_consensus_aura::AuraApi for Runtime { + fn slot_duration() -> sp_consensus_aura::SlotDuration { + sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + } - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { - fn query_info(uxt: ::Extrinsic, len: u32) -> RuntimeDispatchInfo { - TransactionPayment::query_info(uxt, len) - } - fn query_fee_details(uxt: ::Extrinsic, len: u32) -> 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) - } - } + fn authorities() -> Vec { + Aura::authorities().to_vec() + } + } - /* - impl pallet_contracts_rpc_runtime_api::ContractsApi - for Runtime - { - fn call( - origin: AccountId, - dest: AccountId, - value: Balance, - gas_limit: u64, - input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { - Contracts::bare_call(origin, dest, value, gas_limit, input_data, false) - } + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } - fn instantiate( - origin: AccountId, - endowment: Balance, - gas_limit: u64, - code: pallet_contracts_primitives::Code, - data: Vec, - salt: Vec, - ) -> pallet_contracts_primitives::ContractInstantiateResult - { - Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false) - } + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { + System::account_nonce(account) + } + } - fn get_storage( - address: AccountId, - key: [u8; 32], - ) -> pallet_contracts_primitives::GetStorageResult { - Contracts::get_storage(address, key) - } + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { + fn query_info(uxt: ::Extrinsic, len: u32) -> RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + fn query_fee_details(uxt: ::Extrinsic, len: u32) -> 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) + } + } - fn rent_projection( - address: AccountId, - ) -> pallet_contracts_primitives::RentProjectionResult { - Contracts::rent_projection(address) - } - } - */ + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; - #[cfg(feature = "runtime-benchmarks")] - impl frame_benchmarking::Benchmark for Runtime { - fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; + let mut list = Vec::::new(); + list_benchmark!(list, extra, pallet_xcm, PolkadotXcm); - let mut list = Vec::::new(); - list_benchmark!(list, extra, pallet_xcm, PolkadotXcm); + list_benchmark!(list, extra, pallet_evm_migration, EvmMigration); + list_benchmark!(list, extra, pallet_common, Common); + list_benchmark!(list, extra, pallet_unique, Unique); + list_benchmark!(list, extra, pallet_structure, Structure); + list_benchmark!(list, extra, pallet_inflation, Inflation); + list_benchmark!(list, extra, pallet_configuration, Configuration); - list_benchmark!(list, extra, pallet_evm_migration, EvmMigration); - list_benchmark!(list, extra, pallet_common, Common); - list_benchmark!(list, extra, pallet_unique, Unique); - list_benchmark!(list, extra, pallet_structure, Structure); - list_benchmark!(list, extra, pallet_inflation, Inflation); - list_benchmark!(list, extra, pallet_configuration, Configuration); + #[cfg(feature = "app-promotion")] + list_benchmark!(list, extra, pallet_app_promotion, AppPromotion); - #[cfg(feature = "app-promotion")] - list_benchmark!(list, extra, pallet_app_promotion, AppPromotion); + list_benchmark!(list, extra, pallet_fungible, Fungible); + list_benchmark!(list, extra, pallet_nonfungible, Nonfungible); - list_benchmark!(list, extra, pallet_fungible, Fungible); - list_benchmark!(list, extra, pallet_nonfungible, Nonfungible); + #[cfg(feature = "refungible")] + list_benchmark!(list, extra, pallet_refungible, Refungible); - #[cfg(feature = "refungible")] - list_benchmark!(list, extra, pallet_refungible, Refungible); + #[cfg(feature = "unique-scheduler")] + list_benchmark!(list, extra, pallet_unique_scheduler_v2, Scheduler); - #[cfg(feature = "unique-scheduler")] - list_benchmark!(list, extra, pallet_unique_scheduler_v2, Scheduler); + #[cfg(feature = "collator-selection")] + list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection); - #[cfg(feature = "collator-selection")] - list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection); + #[cfg(feature = "collator-selection")] + list_benchmark!(list, extra, pallet_identity, Identity); - #[cfg(feature = "collator-selection")] - list_benchmark!(list, extra, pallet_identity, Identity); + #[cfg(feature = "foreign-assets")] + list_benchmark!(list, extra, pallet_foreign_assets, ForeignAssets); - #[cfg(feature = "foreign-assets")] - list_benchmark!(list, extra, pallet_foreign_assets, ForeignAssets); + list_benchmark!(list, extra, pallet_maintenance, Maintenance); - list_benchmark!(list, extra, pallet_maintenance, Maintenance); + // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate); - // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate); + let storage_info = AllPalletsWithSystem::storage_info(); - let storage_info = AllPalletsWithSystem::storage_info(); + return (list, storage_info) + } - return (list, storage_info) - } + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig + ) -> Result, sp_runtime::RuntimeString> { + use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; - fn dispatch_benchmark( - config: frame_benchmarking::BenchmarkConfig - ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; + let allowlist: Vec = vec![ + // Total Issuance + hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - let allowlist: Vec = vec![ - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), + // Block Number + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), + // Execution Phase + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), + // Event Count + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), + // System Events + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + // Evm CurrentLogs + hex_literal::hex!("1da53b775b270400e7e61ed5cbc5a146547f210cec367e9af919603343b9cb56").to_vec().into(), - // Evm CurrentLogs - hex_literal::hex!("1da53b775b270400e7e61ed5cbc5a146547f210cec367e9af919603343b9cb56").to_vec().into(), + // Transactional depth + hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(), + ]; - // Transactional depth - hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(), - ]; + let mut batches = Vec::::new(); + let params = (&config, &allowlist); + add_benchmark!(params, batches, pallet_xcm, PolkadotXcm); - let mut batches = Vec::::new(); - let params = (&config, &allowlist); - add_benchmark!(params, batches, pallet_xcm, PolkadotXcm); + add_benchmark!(params, batches, pallet_evm_migration, EvmMigration); + add_benchmark!(params, batches, pallet_common, Common); + add_benchmark!(params, batches, pallet_unique, Unique); + add_benchmark!(params, batches, pallet_structure, Structure); + add_benchmark!(params, batches, pallet_inflation, Inflation); + add_benchmark!(params, batches, pallet_configuration, Configuration); - add_benchmark!(params, batches, pallet_evm_migration, EvmMigration); - add_benchmark!(params, batches, pallet_common, Common); - add_benchmark!(params, batches, pallet_unique, Unique); - add_benchmark!(params, batches, pallet_structure, Structure); - add_benchmark!(params, batches, pallet_inflation, Inflation); - add_benchmark!(params, batches, pallet_configuration, Configuration); + #[cfg(feature = "app-promotion")] + add_benchmark!(params, batches, pallet_app_promotion, AppPromotion); - #[cfg(feature = "app-promotion")] - add_benchmark!(params, batches, pallet_app_promotion, AppPromotion); + add_benchmark!(params, batches, pallet_fungible, Fungible); + add_benchmark!(params, batches, pallet_nonfungible, Nonfungible); - add_benchmark!(params, batches, pallet_fungible, Fungible); - add_benchmark!(params, batches, pallet_nonfungible, Nonfungible); + #[cfg(feature = "refungible")] + add_benchmark!(params, batches, pallet_refungible, Refungible); - #[cfg(feature = "refungible")] - add_benchmark!(params, batches, pallet_refungible, Refungible); + #[cfg(feature = "unique-scheduler")] + add_benchmark!(params, batches, pallet_unique_scheduler_v2, Scheduler); - #[cfg(feature = "unique-scheduler")] - add_benchmark!(params, batches, pallet_unique_scheduler_v2, Scheduler); + #[cfg(feature = "collator-selection")] + add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection); - #[cfg(feature = "collator-selection")] - add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection); + #[cfg(feature = "collator-selection")] + add_benchmark!(params, batches, pallet_identity, Identity); - #[cfg(feature = "collator-selection")] - add_benchmark!(params, batches, pallet_identity, Identity); + #[cfg(feature = "foreign-assets")] + add_benchmark!(params, batches, pallet_foreign_assets, ForeignAssets); - #[cfg(feature = "foreign-assets")] - add_benchmark!(params, batches, pallet_foreign_assets, ForeignAssets); + add_benchmark!(params, batches, pallet_maintenance, Maintenance); - add_benchmark!(params, batches, pallet_maintenance, Maintenance); + // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate); - // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate); + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } - Ok(batches) - } - } + impl up_pov_estimate_rpc::PovEstimateApi for Runtime { + #[allow(unused_variables)] + fn pov_estimate(uxt: Vec) -> ApplyExtrinsicResult { + #[cfg(feature = "pov-estimate")] + { + use parity_scale_codec::Decode; - impl up_pov_estimate_rpc::PovEstimateApi for Runtime { - #[allow(unused_variables)] - fn pov_estimate(uxt: Vec) -> ApplyExtrinsicResult { - #[cfg(feature = "pov-estimate")] - { - use codec::Decode; + let uxt_decode = <::Extrinsic as Decode>::decode(&mut &*uxt) + .map_err(|_| DispatchError::Other("failed to decode the extrinsic")); - let uxt_decode = <::Extrinsic as Decode>::decode(&mut &*uxt) - .map_err(|_| DispatchError::Other("failed to decode the extrinsic")); + let uxt = match uxt_decode { + Ok(uxt) => uxt, + Err(err) => return Ok(err.into()), + }; - let uxt = match uxt_decode { - Ok(uxt) => uxt, - Err(err) => return Ok(err.into()), - }; + Executive::apply_extrinsic(uxt) + } - Executive::apply_extrinsic(uxt) - } + #[cfg(not(feature = "pov-estimate"))] + return Ok(unsupported!()); + } + } - #[cfg(not(feature = "pov-estimate"))] - return Ok(unsupported!()); - } - } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade unique-chain."); + let weight = Executive::try_runtime_upgrade(checks).unwrap(); + (weight, $crate::config::substrate::RuntimeBlockWeights::get().max_block) + } - #[cfg(feature = "try-runtime")] - impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { - log::info!("try-runtime::on_runtime_upgrade unique-chain."); - let weight = Executive::try_runtime_upgrade(checks).unwrap(); - (weight, $crate::config::substrate::RuntimeBlockWeights::get().max_block) - } + fn execute_block( + block: Block, + state_root_check: bool, + signature_check: bool, + select: frame_try_runtime::TryStateSelect + ) -> Weight { + log::info!( + target: "node-runtime", + "try-runtime: executing block {:?} / root checks: {:?} / try-state-select: {:?}", + block.header.hash(), + state_root_check, + select, + ); - fn execute_block( - block: Block, - state_root_check: bool, - signature_check: bool, - select: frame_try_runtime::TryStateSelect - ) -> Weight { - log::info!( - target: "node-runtime", - "try-runtime: executing block {:?} / root checks: {:?} / try-state-select: {:?}", - block.header.hash(), - state_root_check, - select, - ); + Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() + } + } - Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() - } - } - } - } + /// Should never be used, yet still required because of https://github.com/paritytech/polkadot-sdk/issues/27 + /// Not allowed to panic, because rpc may be called using native runtime, thus causing thread panic. + impl fp_rpc::ConvertTransactionRuntimeApi for Runtime { + fn convert_transaction( + transaction: pallet_ethereum::Transaction + ) -> ::Extrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } + } + } + } } -- gitstuff