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

difftreelog

source

runtime/common/runtime_apis.rs34.5 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/>.1617#[macro_export]18macro_rules! dispatch_unique_runtime {19	($collection:ident.$method:ident($($name:ident),*)) => {{20		let collection = <Runtime as pallet_common::Config>::CollectionDispatch::dispatch(<pallet_common::CollectionHandle<Runtime>>::try_get($collection)?);21		let dispatch = collection.as_dyn();2223		Ok::<_, DispatchError>(dispatch.$method($($name),*))24	}};25}2627#[macro_export]28macro_rules! impl_common_runtime_apis {29    (30        $(31            #![custom_apis]3233            $($custom_apis:tt)+34        )?35    ) => {36        use sp_std::prelude::*;37        use sp_api::impl_runtime_apis;38        use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};39        use sp_runtime::{40            Permill,41            traits::Block as BlockT,42            transaction_validity::{TransactionSource, TransactionValidity},43            ApplyExtrinsicResult, DispatchError,44        };45        use fp_rpc::TransactionStatus;46        use pallet_transaction_payment::{47            FeeDetails, RuntimeDispatchInfo,48        };49        use pallet_evm::{50            Runner, account::CrossAccountId as _,51            Account as EVMAccount, FeeCalculator,52        };53        use runtime_common::{54            sponsoring::{SponsorshipPredict, UniqueSponsorshipPredict},55            dispatch::CollectionDispatch,56            config::ethereum::CrossAccountId,57        };58        use up_data_structs::*;596061        impl_runtime_apis! {62            $($($custom_apis)+)?6364            impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {65                fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {66                    dispatch_unique_runtime!(collection.account_tokens(account))67                }68                fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {69                    dispatch_unique_runtime!(collection.collection_tokens())70                }71                fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {72                    dispatch_unique_runtime!(collection.token_exists(token))73                }7475                fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {76                    dispatch_unique_runtime!(collection.token_owner(token))77                }7879                fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>, DispatchError>  {80                   dispatch_unique_runtime!(collection.token_owners(token))81                }8283                fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {84                    let budget = up_data_structs::budget::Value::new(10);8586                    Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))87                }88                fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>, DispatchError> {89                    Ok(<pallet_nonfungible::Pallet<Runtime>>::token_children_ids(collection, token))90                }91                fn collection_properties(92                    collection: CollectionId,93                    keys: Option<Vec<Vec<u8>>>94                ) -> Result<Vec<Property>, DispatchError> {95                    let keys = keys.map(96                        |keys| Common::bytes_keys_to_property_keys(keys)97                    ).transpose()?;9899                    Common::filter_collection_properties(collection, keys)100                }101102                fn token_properties(103                    collection: CollectionId,104                    token_id: TokenId,105                    keys: Option<Vec<Vec<u8>>>106                ) -> Result<Vec<Property>, DispatchError> {107                    let keys = keys.map(108                        |keys| Common::bytes_keys_to_property_keys(keys)109                    ).transpose()?;110111                    dispatch_unique_runtime!(collection.token_properties(token_id, keys))112                }113114                fn property_permissions(115                    collection: CollectionId,116                    keys: Option<Vec<Vec<u8>>>117                ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {118                    let keys = keys.map(119                        |keys| Common::bytes_keys_to_property_keys(keys)120                    ).transpose()?;121122                    Common::filter_property_permissions(collection, keys)123                }124125                fn token_data(126                    collection: CollectionId,127                    token_id: TokenId,128                    keys: Option<Vec<Vec<u8>>>129                ) -> Result<TokenData<CrossAccountId>, DispatchError> {130                    let token_data = TokenData {131                        properties: Self::token_properties(collection, token_id, keys)?,132                        owner: Self::token_owner(collection, token_id)?,133                        pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0),134                    };135136                    Ok(token_data)137                }138139                fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {140                    dispatch_unique_runtime!(collection.total_supply())141                }142                fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {143                    dispatch_unique_runtime!(collection.account_balance(account))144                }145                fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {146                    dispatch_unique_runtime!(collection.balance(account, token))147                }148                fn allowance(149                    collection: CollectionId,150                    sender: CrossAccountId,151                    spender: CrossAccountId,152                    token: TokenId,153                ) -> Result<u128, DispatchError> {154                    dispatch_unique_runtime!(collection.allowance(sender, spender, token))155                }156157                fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {158                    Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))159                }160                fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {161                    Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))162                }163                fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {164                    Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))165                }166                fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {167                    dispatch_unique_runtime!(collection.last_token_id())168                }169                fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>, DispatchError> {170                    Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(collection))171                }172                fn collection_stats() -> Result<CollectionStats, DispatchError> {173                    Ok(<pallet_common::Pallet<Runtime>>::collection_stats())174                }175                fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {176                    Ok(<UniqueSponsorshipPredict<Runtime> as SponsorshipPredict<Runtime>>::predict(177                        collection,178                        account,179                        token180                    ))181                }182183                fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {184                    Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))185                }186187                fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<Option<u128>, DispatchError> {188                    dispatch_unique_runtime!(collection.total_pieces(token_id))189                }190            }191192            impl app_promotion_rpc::AppPromotionApi<Block, BlockNumber, CrossAccountId, AccountId> for Runtime {193                fn total_staked(staker: Option<CrossAccountId>) -> Result<u128, DispatchError> {194                    #[cfg(not(feature = "app-promotion"))]195                    return unsupported!();196197                    #[cfg(feature = "app-promotion")]198                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_total_staked(staker).unwrap_or_default());199                }200201                fn total_staked_per_block(staker: CrossAccountId) -> Result<Vec<(BlockNumber, u128)>, DispatchError> {202                    #[cfg(not(feature = "app-promotion"))]203                    return unsupported!();204205                    #[cfg(feature = "app-promotion")]206                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_total_staked_per_block(staker));207                }208209                fn pending_unstake(staker: Option<CrossAccountId>) -> Result<u128, DispatchError> {210                    #[cfg(not(feature = "app-promotion"))]211                    return unsupported!();212213                    #[cfg(feature = "app-promotion")]214                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_pending_unstake(staker));215                }216217                fn pending_unstake_per_block(staker: CrossAccountId) -> Result<Vec<(BlockNumber, u128)>, DispatchError> {218                    #[cfg(not(feature = "app-promotion"))]219                    return unsupported!();220221                    #[cfg(feature = "app-promotion")]222                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_pending_unstake_per_block(staker))223                }224            }225226            impl rmrk_rpc::RmrkApi<227                Block,228                AccountId,229                RmrkCollectionInfo<AccountId>,230                RmrkInstanceInfo<AccountId>,231                RmrkResourceInfo,232                RmrkPropertyInfo,233                RmrkBaseInfo<AccountId>,234                RmrkPartType,235                RmrkTheme236            > for Runtime {237                fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {238                    #[cfg(feature = "rmrk")]239                    return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();240241                    #[cfg(not(feature = "rmrk"))]242                    return unsupported!();243                }244245                #[allow(unused_variables)]246                fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {247                    #[cfg(feature = "rmrk")]248                    return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);249250                    #[cfg(not(feature = "rmrk"))]251                    return unsupported!();252                }253254                #[allow(unused_variables)]255                fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {256                    #[cfg(feature = "rmrk")]257                    return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);258259                    #[cfg(not(feature = "rmrk"))]260                    return unsupported!();261                }262263                #[allow(unused_variables)]264                fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {265                    #[cfg(feature = "rmrk")]266                    return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);267268                    #[cfg(not(feature = "rmrk"))]269                    return unsupported!();270                }271272                #[allow(unused_variables)]273                fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {274                    #[cfg(feature = "rmrk")]275                    return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);276277                    #[cfg(not(feature = "rmrk"))]278                    return unsupported!();279                }280281                #[allow(unused_variables)]282                fn collection_properties(283                    collection_id: RmrkCollectionId,284                    filter_keys: Option<Vec<RmrkPropertyKey>>285                ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {286                    #[cfg(feature = "rmrk")]287                    return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);288289                    #[cfg(not(feature = "rmrk"))]290                    return unsupported!();291                }292293                #[allow(unused_variables)]294                fn nft_properties(295                    collection_id: RmrkCollectionId,296                    nft_id: RmrkNftId,297                    filter_keys: Option<Vec<RmrkPropertyKey>>298                ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {299                    #[cfg(feature = "rmrk")]300                    return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);301302                    #[cfg(not(feature = "rmrk"))]303                    return unsupported!();304                }305306                #[allow(unused_variables)]307                fn nft_resources(collection_id: RmrkCollectionId,nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {308                    #[cfg(feature = "rmrk")]309                    return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);310311                    #[cfg(not(feature = "rmrk"))]312                    return unsupported!();313                }314315                #[allow(unused_variables)]316                fn nft_resource_priority(317                    collection_id: RmrkCollectionId,318                    nft_id: RmrkNftId,319                    resource_id: RmrkResourceId320                ) -> Result<Option<u32>, DispatchError> {321                    #[cfg(feature = "rmrk")]322                    return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);323324                    #[cfg(not(feature = "rmrk"))]325                    return unsupported!();326                }327328                #[allow(unused_variables)]329                fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {330                    #[cfg(feature = "rmrk")]331                    return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);332333                    #[cfg(not(feature = "rmrk"))]334                    return unsupported!();335                }336337                #[allow(unused_variables)]338                fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {339                    #[cfg(feature = "rmrk")]340                    return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);341342                    #[cfg(not(feature = "rmrk"))]343                    return unsupported!();344                }345346                #[allow(unused_variables)]347                fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {348                    #[cfg(feature = "rmrk")]349                    return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);350351                    #[cfg(not(feature = "rmrk"))]352                    return unsupported!();353                }354355                #[allow(unused_variables)]356                fn theme(357                    base_id: RmrkBaseId,358                    theme_name: RmrkThemeName,359                    filter_keys: Option<Vec<RmrkPropertyKey>>360                ) -> Result<Option<RmrkTheme>, DispatchError> {361                    #[cfg(feature = "rmrk")]362                    return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);363364                    #[cfg(not(feature = "rmrk"))]365                    return unsupported!();366                }367            }368369            impl sp_api::Core<Block> for Runtime {370                fn version() -> RuntimeVersion {371                    VERSION372                }373374                fn execute_block(block: Block) {375                    Executive::execute_block(block)376                }377378                fn initialize_block(header: &<Block as BlockT>::Header) {379                    Executive::initialize_block(header)380                }381            }382383            impl sp_api::Metadata<Block> for Runtime {384                fn metadata() -> OpaqueMetadata {385                    OpaqueMetadata::new(Runtime::metadata().into())386                }387            }388389            impl sp_block_builder::BlockBuilder<Block> for Runtime {390                fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {391                    Executive::apply_extrinsic(extrinsic)392                }393394                fn finalize_block() -> <Block as BlockT>::Header {395                    Executive::finalize_block()396                }397398                fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {399                    data.create_extrinsics()400                }401402                fn check_inherents(403                    block: Block,404                    data: sp_inherents::InherentData,405                ) -> sp_inherents::CheckInherentsResult {406                    data.check_extrinsics(&block)407                }408409                // fn random_seed() -> <Block as BlockT>::Hash {410                //     RandomnessCollectiveFlip::random_seed().0411                // }412            }413414            impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {415                fn validate_transaction(416                    source: TransactionSource,417                    tx: <Block as BlockT>::Extrinsic,418                    hash: <Block as BlockT>::Hash,419                ) -> TransactionValidity {420                    Executive::validate_transaction(source, tx, hash)421                }422            }423424            impl sp_offchain::OffchainWorkerApi<Block> for Runtime {425                fn offchain_worker(header: &<Block as BlockT>::Header) {426                    Executive::offchain_worker(header)427                }428            }429430            impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {431                fn chain_id() -> u64 {432                    <Runtime as pallet_evm::Config>::ChainId::get()433                }434435                fn account_basic(address: H160) -> EVMAccount {436                    let (account, _) = EVM::account_basic(&address);437                    account438                }439440                fn gas_price() -> U256 {441                    let (price, _) = <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price();442                    price443                }444445                fn account_code_at(address: H160) -> Vec<u8> {446                    EVM::account_codes(address)447                }448449                fn author() -> H160 {450                    <pallet_evm::Pallet<Runtime>>::find_author()451                }452453                fn storage_at(address: H160, index: U256) -> H256 {454                    let mut tmp = [0u8; 32];455                    index.to_big_endian(&mut tmp);456                    EVM::account_storages(address, H256::from_slice(&tmp[..]))457                }458459                #[allow(clippy::redundant_closure)]460                fn call(461                    from: H160,462                    to: H160,463                    data: Vec<u8>,464                    value: U256,465                    gas_limit: U256,466                    max_fee_per_gas: Option<U256>,467                    max_priority_fee_per_gas: Option<U256>,468                    nonce: Option<U256>,469                    estimate: bool,470                    access_list: Option<Vec<(H160, Vec<H256>)>>,471                ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {472                    let config = if estimate {473                        let mut config = <Runtime as pallet_evm::Config>::config().clone();474                        config.estimate = true;475                        Some(config)476                    } else {477                        None478                    };479480                    let is_transactional = false;481                    <Runtime as pallet_evm::Config>::Runner::call(482                        CrossAccountId::from_eth(from),483                        to,484                        data,485                        value,486                        gas_limit.low_u64(),487                        max_fee_per_gas,488                        max_priority_fee_per_gas,489                        nonce,490                        access_list.unwrap_or_default(),491                        is_transactional,492                        config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),493                    ).map_err(|err| err.error.into())494                }495496                #[allow(clippy::redundant_closure)]497                fn create(498                    from: H160,499                    data: Vec<u8>,500                    value: U256,501                    gas_limit: U256,502                    max_fee_per_gas: Option<U256>,503                    max_priority_fee_per_gas: Option<U256>,504                    nonce: Option<U256>,505                    estimate: bool,506                    access_list: Option<Vec<(H160, Vec<H256>)>>,507                ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {508                    let config = if estimate {509                        let mut config = <Runtime as pallet_evm::Config>::config().clone();510                        config.estimate = true;511                        Some(config)512                    } else {513                        None514                    };515516                    let is_transactional = false;517                    <Runtime as pallet_evm::Config>::Runner::create(518                        CrossAccountId::from_eth(from),519                        data,520                        value,521                        gas_limit.low_u64(),522                        max_fee_per_gas,523                        max_priority_fee_per_gas,524                        nonce,525                        access_list.unwrap_or_default(),526                        is_transactional,527                        config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),528                    ).map_err(|err| err.error.into())529                }530531                fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {532                    Ethereum::current_transaction_statuses()533                }534535                fn current_block() -> Option<pallet_ethereum::Block> {536                    Ethereum::current_block()537                }538539                fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {540                    Ethereum::current_receipts()541                }542543                fn current_all() -> (544                    Option<pallet_ethereum::Block>,545                    Option<Vec<pallet_ethereum::Receipt>>,546                    Option<Vec<TransactionStatus>>547                ) {548                    (549                        Ethereum::current_block(),550                        Ethereum::current_receipts(),551                        Ethereum::current_transaction_statuses()552                    )553                }554555                fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {556                    xts.into_iter().filter_map(|xt| match xt.0.function {557                        Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),558                        _ => None559                    }).collect()560                }561562                fn elasticity() -> Option<Permill> {563                    None564                }565            }566567            impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {568                fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic  {569                    UncheckedExtrinsic::new_unsigned(570                        pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),571                    )572                }573            }574575            impl sp_session::SessionKeys<Block> for Runtime {576                fn decode_session_keys(577                    encoded: Vec<u8>,578                ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {579                    SessionKeys::decode_into_raw_public_keys(&encoded)580                }581582                fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {583                    SessionKeys::generate(seed)584                }585            }586587            impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {588                fn slot_duration() -> sp_consensus_aura::SlotDuration {589                    sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())590                }591592                fn authorities() -> Vec<AuraId> {593                    Aura::authorities().to_vec()594                }595            }596597            impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {598                fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {599                    ParachainSystem::collect_collation_info(header)600                }601            }602603            impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {604                fn account_nonce(account: AccountId) -> Index {605                    System::account_nonce(account)606                }607            }608609            impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {610                fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {611                    TransactionPayment::query_info(uxt, len)612                }613                fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {614                    TransactionPayment::query_fee_details(uxt, len)615                }616            }617618            /*619            impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>620                for Runtime621            {622                fn call(623                    origin: AccountId,624                    dest: AccountId,625                    value: Balance,626                    gas_limit: u64,627                    input_data: Vec<u8>,628                ) -> pallet_contracts_primitives::ContractExecResult {629                    Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)630                }631632                fn instantiate(633                    origin: AccountId,634                    endowment: Balance,635                    gas_limit: u64,636                    code: pallet_contracts_primitives::Code<Hash>,637                    data: Vec<u8>,638                    salt: Vec<u8>,639                ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>640                {641                    Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)642                }643644                fn get_storage(645                    address: AccountId,646                    key: [u8; 32],647                ) -> pallet_contracts_primitives::GetStorageResult {648                    Contracts::get_storage(address, key)649                }650651                fn rent_projection(652                    address: AccountId,653                ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {654                    Contracts::rent_projection(address)655                }656            }657            */658659            #[cfg(feature = "runtime-benchmarks")]660            impl frame_benchmarking::Benchmark<Block> for Runtime {661                fn benchmark_metadata(extra: bool) -> (662                    Vec<frame_benchmarking::BenchmarkList>,663                    Vec<frame_support::traits::StorageInfo>,664                ) {665                    use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};666                    use frame_support::traits::StorageInfoTrait;667668                    let mut list = Vec::<BenchmarkList>::new();669670                    list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);671                    list_benchmark!(list, extra, pallet_common, Common);672                    list_benchmark!(list, extra, pallet_unique, Unique);673                    list_benchmark!(list, extra, pallet_structure, Structure);674                    list_benchmark!(list, extra, pallet_inflation, Inflation);675                    list_benchmark!(list, extra, pallet_app_promotion, AppPromotion);676                    list_benchmark!(list, extra, pallet_fungible, Fungible);677                    list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);678679                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]680                    list_benchmark!(list, extra, pallet_refungible, Refungible);681682                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]683                    list_benchmark!(list, extra, pallet_unique_scheduler, Scheduler);684685                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]686                    list_benchmark!(list, extra, pallet_proxy_rmrk_core, RmrkCore);687688                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]689                    list_benchmark!(list, extra, pallet_proxy_rmrk_equip, RmrkEquip);690691                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]692                    list_benchmark!(list, extra, pallet_foreign_assets, ForeignAssets);693694695                    // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);696697                    let storage_info = AllPalletsReversedWithSystemFirst::storage_info();698699                    return (list, storage_info)700                }701702                fn dispatch_benchmark(703                    config: frame_benchmarking::BenchmarkConfig704                ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {705                    use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};706707                    let allowlist: Vec<TrackedStorageKey> = vec![708                        // Total Issuance709                        hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),710711                        // Block Number712                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),713                        // Execution Phase714                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),715                        // Event Count716                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),717                        // System Events718                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),719720                        // Evm CurrentLogs721                        hex_literal::hex!("1da53b775b270400e7e61ed5cbc5a146547f210cec367e9af919603343b9cb56").to_vec().into(),722723                        // Transactional depth724                        hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),725                    ];726727                    let mut batches = Vec::<BenchmarkBatch>::new();728                    let params = (&config, &allowlist);729730                    add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);731                    add_benchmark!(params, batches, pallet_common, Common);732                    add_benchmark!(params, batches, pallet_unique, Unique);733                    add_benchmark!(params, batches, pallet_structure, Structure);734                    add_benchmark!(params, batches, pallet_inflation, Inflation);735                    add_benchmark!(params, batches, pallet_app_promotion, AppPromotion);736                    add_benchmark!(params, batches, pallet_fungible, Fungible);737                    add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);738739                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]740                    add_benchmark!(params, batches, pallet_refungible, Refungible);741742                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]743                    add_benchmark!(params, batches, pallet_unique_scheduler, Scheduler);744745                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]746                    add_benchmark!(params, batches, pallet_proxy_rmrk_core, RmrkCore);747748                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]749                    add_benchmark!(params, batches, pallet_proxy_rmrk_equip, RmrkEquip);750751                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]752                    add_benchmark!(params, batches, pallet_foreign_assets, ForeignAssets);753754                    // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);755756                    if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }757                    Ok(batches)758                }759            }760761            #[cfg(feature = "try-runtime")]762            impl frame_try_runtime::TryRuntime<Block> for Runtime {763                fn on_runtime_upgrade() -> (frame_support::pallet_prelude::Weight, frame_support::pallet_prelude::Weight) {764                    log::info!("try-runtime::on_runtime_upgrade unique-chain.");765                    let weight = Executive::try_runtime_upgrade().unwrap();766                    (weight, crate::config::substrate::RuntimeBlockWeights::get().max_block)767                }768769                fn execute_block_no_check(block: Block) -> frame_support::pallet_prelude::Weight {770                    Executive::execute_block_no_check(block)771                }772            }773        }774    }775}