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

difftreelog

source

runtime/common/runtime_apis.rs34.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/>.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,52            FeeCalculator53        };54        use runtime_common::{55            sponsoring::{SponsorshipPredict, UniqueSponsorshipPredict},56            dispatch::CollectionDispatch,57            config::ethereum::CrossAccountId,58        };59        use up_data_structs::*;606162        impl_runtime_apis! {63            $($($custom_apis)+)?6465            impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {66                fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {67                    dispatch_unique_runtime!(collection.account_tokens(account))68                }69                fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {70                    dispatch_unique_runtime!(collection.collection_tokens())71                }72                fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {73                    dispatch_unique_runtime!(collection.token_exists(token))74                }7576                fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {77                    dispatch_unique_runtime!(collection.token_owner(token))78                }7980                fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>, DispatchError>  {81                   dispatch_unique_runtime!(collection.token_owners(token))82                }8384                fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {85                    let budget = up_data_structs::budget::Value::new(10);8687                    Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))88                }89                fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>, DispatchError> {90                    Ok(<pallet_nonfungible::Pallet<Runtime>>::token_children_ids(collection, token))91                }92                fn collection_properties(93                    collection: CollectionId,94                    keys: Option<Vec<Vec<u8>>>95                ) -> Result<Vec<Property>, DispatchError> {96                    let keys = keys.map(97                        |keys| Common::bytes_keys_to_property_keys(keys)98                    ).transpose()?;99100                    Common::filter_collection_properties(collection, keys)101                }102103                fn token_properties(104                    collection: CollectionId,105                    token_id: TokenId,106                    keys: Option<Vec<Vec<u8>>>107                ) -> Result<Vec<Property>, DispatchError> {108                    let keys = keys.map(109                        |keys| Common::bytes_keys_to_property_keys(keys)110                    ).transpose()?;111112                    dispatch_unique_runtime!(collection.token_properties(token_id, keys))113                }114115                fn property_permissions(116                    collection: CollectionId,117                    keys: Option<Vec<Vec<u8>>>118                ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {119                    let keys = keys.map(120                        |keys| Common::bytes_keys_to_property_keys(keys)121                    ).transpose()?;122123                    Common::filter_property_permissions(collection, keys)124                }125126                fn token_data(127                    collection: CollectionId,128                    token_id: TokenId,129                    keys: Option<Vec<Vec<u8>>>130                ) -> Result<TokenData<CrossAccountId>, DispatchError> {131                    let token_data = TokenData {132                        properties: Self::token_properties(collection, token_id, keys)?,133                        owner: Self::token_owner(collection, token_id)?,134                        pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0),135                    };136137                    Ok(token_data)138                }139140                fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {141                    dispatch_unique_runtime!(collection.total_supply())142                }143                fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {144                    dispatch_unique_runtime!(collection.account_balance(account))145                }146                fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {147                    dispatch_unique_runtime!(collection.balance(account, token))148                }149                fn allowance(150                    collection: CollectionId,151                    sender: CrossAccountId,152                    spender: CrossAccountId,153                    token: TokenId,154                ) -> Result<u128, DispatchError> {155                    dispatch_unique_runtime!(collection.allowance(sender, spender, token))156                }157158                fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {159                    Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))160                }161                fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {162                    Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))163                }164                fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {165                    Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))166                }167                fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {168                    dispatch_unique_runtime!(collection.last_token_id())169                }170                fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>, DispatchError> {171                    Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(collection))172                }173                fn collection_stats() -> Result<CollectionStats, DispatchError> {174                    Ok(<pallet_common::Pallet<Runtime>>::collection_stats())175                }176                fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {177                    Ok(<UniqueSponsorshipPredict<Runtime> as SponsorshipPredict<Runtime>>::predict(178                        collection,179                        account,180                        token181                    ))182                }183184                fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {185                    Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))186                }187188                fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<Option<u128>, DispatchError> {189                    dispatch_unique_runtime!(collection.total_pieces(token_id))190                }191            }192193            impl app_promotion_rpc::AppPromotionApi<Block, BlockNumber, CrossAccountId, AccountId> for Runtime {194                fn total_staked(staker: Option<CrossAccountId>) -> Result<u128, DispatchError> {195                    #[cfg(not(feature = "app-promotion"))]196                    return unsupported!();197198                    #[cfg(feature = "app-promotion")]199                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_total_staked(staker).unwrap_or_default());200                }201202                fn total_staked_per_block(staker: CrossAccountId) -> Result<Vec<(BlockNumber, u128)>, DispatchError> {203                    #[cfg(not(feature = "app-promotion"))]204                    return unsupported!();205206                    #[cfg(feature = "app-promotion")]207                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_total_staked_per_block(staker));208                }209210                fn pending_unstake(staker: Option<CrossAccountId>) -> Result<u128, DispatchError> {211                    #[cfg(not(feature = "app-promotion"))]212                    return unsupported!();213214                    #[cfg(feature = "app-promotion")]215                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_pending_unstake(staker));216                }217218                fn pending_unstake_per_block(staker: CrossAccountId) -> Result<Vec<(BlockNumber, u128)>, DispatchError> {219                    #[cfg(not(feature = "app-promotion"))]220                    return unsupported!();221222                    #[cfg(feature = "app-promotion")]223                    return Ok(<pallet_app_promotion::Pallet<Runtime>>::cross_id_pending_unstake_per_block(staker))224                }225            }226227            impl rmrk_rpc::RmrkApi<228                Block,229                AccountId,230                RmrkCollectionInfo<AccountId>,231                RmrkInstanceInfo<AccountId>,232                RmrkResourceInfo,233                RmrkPropertyInfo,234                RmrkBaseInfo<AccountId>,235                RmrkPartType,236                RmrkTheme237            > for Runtime {238                fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {239                    #[cfg(feature = "rmrk")]240                    return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();241242                    #[cfg(not(feature = "rmrk"))]243                    return unsupported!();244                }245246                #[allow(unused_variables)]247                fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {248                    #[cfg(feature = "rmrk")]249                    return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);250251                    #[cfg(not(feature = "rmrk"))]252                    return unsupported!();253                }254255                #[allow(unused_variables)]256                fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {257                    #[cfg(feature = "rmrk")]258                    return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);259260                    #[cfg(not(feature = "rmrk"))]261                    return unsupported!();262                }263264                #[allow(unused_variables)]265                fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {266                    #[cfg(feature = "rmrk")]267                    return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);268269                    #[cfg(not(feature = "rmrk"))]270                    return unsupported!();271                }272273                #[allow(unused_variables)]274                fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {275                    #[cfg(feature = "rmrk")]276                    return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);277278                    #[cfg(not(feature = "rmrk"))]279                    return unsupported!();280                }281282                #[allow(unused_variables)]283                fn collection_properties(284                    collection_id: RmrkCollectionId,285                    filter_keys: Option<Vec<RmrkPropertyKey>>286                ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {287                    #[cfg(feature = "rmrk")]288                    return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);289290                    #[cfg(not(feature = "rmrk"))]291                    return unsupported!();292                }293294                #[allow(unused_variables)]295                fn nft_properties(296                    collection_id: RmrkCollectionId,297                    nft_id: RmrkNftId,298                    filter_keys: Option<Vec<RmrkPropertyKey>>299                ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {300                    #[cfg(feature = "rmrk")]301                    return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);302303                    #[cfg(not(feature = "rmrk"))]304                    return unsupported!();305                }306307                #[allow(unused_variables)]308                fn nft_resources(collection_id: RmrkCollectionId,nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {309                    #[cfg(feature = "rmrk")]310                    return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);311312                    #[cfg(not(feature = "rmrk"))]313                    return unsupported!();314                }315316                #[allow(unused_variables)]317                fn nft_resource_priority(318                    collection_id: RmrkCollectionId,319                    nft_id: RmrkNftId,320                    resource_id: RmrkResourceId321                ) -> Result<Option<u32>, DispatchError> {322                    #[cfg(feature = "rmrk")]323                    return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);324325                    #[cfg(not(feature = "rmrk"))]326                    return unsupported!();327                }328329                #[allow(unused_variables)]330                fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {331                    #[cfg(feature = "rmrk")]332                    return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);333334                    #[cfg(not(feature = "rmrk"))]335                    return unsupported!();336                }337338                #[allow(unused_variables)]339                fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {340                    #[cfg(feature = "rmrk")]341                    return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);342343                    #[cfg(not(feature = "rmrk"))]344                    return unsupported!();345                }346347                #[allow(unused_variables)]348                fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {349                    #[cfg(feature = "rmrk")]350                    return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);351352                    #[cfg(not(feature = "rmrk"))]353                    return unsupported!();354                }355356                #[allow(unused_variables)]357                fn theme(358                    base_id: RmrkBaseId,359                    theme_name: RmrkThemeName,360                    filter_keys: Option<Vec<RmrkPropertyKey>>361                ) -> Result<Option<RmrkTheme>, DispatchError> {362                    #[cfg(feature = "rmrk")]363                    return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);364365                    #[cfg(not(feature = "rmrk"))]366                    return unsupported!();367                }368            }369370            impl sp_api::Core<Block> for Runtime {371                fn version() -> RuntimeVersion {372                    VERSION373                }374375                fn execute_block(block: Block) {376                    Executive::execute_block(block)377                }378379                fn initialize_block(header: &<Block as BlockT>::Header) {380                    Executive::initialize_block(header)381                }382            }383384            impl sp_api::Metadata<Block> for Runtime {385                fn metadata() -> OpaqueMetadata {386                    OpaqueMetadata::new(Runtime::metadata().into())387                }388            }389390            impl sp_block_builder::BlockBuilder<Block> for Runtime {391                fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {392                    Executive::apply_extrinsic(extrinsic)393                }394395                fn finalize_block() -> <Block as BlockT>::Header {396                    Executive::finalize_block()397                }398399                fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {400                    data.create_extrinsics()401                }402403                fn check_inherents(404                    block: Block,405                    data: sp_inherents::InherentData,406                ) -> sp_inherents::CheckInherentsResult {407                    data.check_extrinsics(&block)408                }409410                // fn random_seed() -> <Block as BlockT>::Hash {411                //     RandomnessCollectiveFlip::random_seed().0412                // }413            }414415            impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {416                fn validate_transaction(417                    source: TransactionSource,418                    tx: <Block as BlockT>::Extrinsic,419                    hash: <Block as BlockT>::Hash,420                ) -> TransactionValidity {421                    Executive::validate_transaction(source, tx, hash)422                }423            }424425            impl sp_offchain::OffchainWorkerApi<Block> for Runtime {426                fn offchain_worker(header: &<Block as BlockT>::Header) {427                    Executive::offchain_worker(header)428                }429            }430431            impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {432                fn chain_id() -> u64 {433                    <Runtime as pallet_evm::Config>::ChainId::get()434                }435436                fn account_basic(address: H160) -> EVMAccount {437                    let (account, _) = EVM::account_basic(&address);438                    account439                }440441                fn gas_price() -> U256 {442                    let (price, _) = <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price();443                    price444                }445446                fn account_code_at(address: H160) -> Vec<u8> {447                    EVM::account_codes(address)448                }449450                fn author() -> H160 {451                    <pallet_evm::Pallet<Runtime>>::find_author()452                }453454                fn storage_at(address: H160, index: U256) -> H256 {455                    let mut tmp = [0u8; 32];456                    index.to_big_endian(&mut tmp);457                    EVM::account_storages(address, H256::from_slice(&tmp[..]))458                }459460                #[allow(clippy::redundant_closure)]461                fn call(462                    from: H160,463                    to: H160,464                    data: Vec<u8>,465                    value: U256,466                    gas_limit: U256,467                    max_fee_per_gas: Option<U256>,468                    max_priority_fee_per_gas: Option<U256>,469                    nonce: Option<U256>,470                    estimate: bool,471                    access_list: Option<Vec<(H160, Vec<H256>)>>,472                ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {473                    let config = if estimate {474                        let mut config = <Runtime as pallet_evm::Config>::config().clone();475                        config.estimate = true;476                        Some(config)477                    } else {478                        None479                    };480481                    let is_transactional = false;482                    <Runtime as pallet_evm::Config>::Runner::call(483                        CrossAccountId::from_eth(from),484                        to,485                        data,486                        value,487                        gas_limit.low_u64(),488                        max_fee_per_gas,489                        max_priority_fee_per_gas,490                        nonce,491                        access_list.unwrap_or_default(),492                        is_transactional,493                        config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),494                    ).map_err(|err| err.error.into())495                }496497                #[allow(clippy::redundant_closure)]498                fn create(499                    from: H160,500                    data: Vec<u8>,501                    value: U256,502                    gas_limit: U256,503                    max_fee_per_gas: Option<U256>,504                    max_priority_fee_per_gas: Option<U256>,505                    nonce: Option<U256>,506                    estimate: bool,507                    access_list: Option<Vec<(H160, Vec<H256>)>>,508                ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {509                    let config = if estimate {510                        let mut config = <Runtime as pallet_evm::Config>::config().clone();511                        config.estimate = true;512                        Some(config)513                    } else {514                        None515                    };516517                    let is_transactional = false;518                    <Runtime as pallet_evm::Config>::Runner::create(519                        CrossAccountId::from_eth(from),520                        data,521                        value,522                        gas_limit.low_u64(),523                        max_fee_per_gas,524                        max_priority_fee_per_gas,525                        nonce,526                        access_list.unwrap_or_default(),527                        is_transactional,528                        config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),529                    ).map_err(|err| err.error.into())530                }531532                fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {533                    Ethereum::current_transaction_statuses()534                }535536                fn current_block() -> Option<pallet_ethereum::Block> {537                    Ethereum::current_block()538                }539540                fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {541                    Ethereum::current_receipts()542                }543544                fn current_all() -> (545                    Option<pallet_ethereum::Block>,546                    Option<Vec<pallet_ethereum::Receipt>>,547                    Option<Vec<TransactionStatus>>548                ) {549                    (550                        Ethereum::current_block(),551                        Ethereum::current_receipts(),552                        Ethereum::current_transaction_statuses()553                    )554                }555556                fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {557                    xts.into_iter().filter_map(|xt| match xt.0.function {558                        Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),559                        _ => None560                    }).collect()561                }562563                fn elasticity() -> Option<Permill> {564                    None565                }566            }567568            impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {569                fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic  {570                    UncheckedExtrinsic::new_unsigned(571                        pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),572                    )573                }574            }575576            impl sp_session::SessionKeys<Block> for Runtime {577                fn decode_session_keys(578                    encoded: Vec<u8>,579                ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {580                    SessionKeys::decode_into_raw_public_keys(&encoded)581                }582583                fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {584                    SessionKeys::generate(seed)585                }586            }587588            impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {589                fn slot_duration() -> sp_consensus_aura::SlotDuration {590                    sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())591                }592593                fn authorities() -> Vec<AuraId> {594                    Aura::authorities().to_vec()595                }596            }597598            impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {599                fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {600                    ParachainSystem::collect_collation_info(header)601                }602            }603604            impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {605                fn account_nonce(account: AccountId) -> Index {606                    System::account_nonce(account)607                }608            }609610            impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {611                fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {612                    TransactionPayment::query_info(uxt, len)613                }614                fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {615                    TransactionPayment::query_fee_details(uxt, len)616                }617            }618619            /*620            impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>621                for Runtime622            {623                fn call(624                    origin: AccountId,625                    dest: AccountId,626                    value: Balance,627                    gas_limit: u64,628                    input_data: Vec<u8>,629                ) -> pallet_contracts_primitives::ContractExecResult {630                    Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)631                }632633                fn instantiate(634                    origin: AccountId,635                    endowment: Balance,636                    gas_limit: u64,637                    code: pallet_contracts_primitives::Code<Hash>,638                    data: Vec<u8>,639                    salt: Vec<u8>,640                ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>641                {642                    Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)643                }644645                fn get_storage(646                    address: AccountId,647                    key: [u8; 32],648                ) -> pallet_contracts_primitives::GetStorageResult {649                    Contracts::get_storage(address, key)650                }651652                fn rent_projection(653                    address: AccountId,654                ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {655                    Contracts::rent_projection(address)656                }657            }658            */659660            #[cfg(feature = "runtime-benchmarks")]661            impl frame_benchmarking::Benchmark<Block> for Runtime {662                fn benchmark_metadata(extra: bool) -> (663                    Vec<frame_benchmarking::BenchmarkList>,664                    Vec<frame_support::traits::StorageInfo>,665                ) {666                    use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};667                    use frame_support::traits::StorageInfoTrait;668669                    let mut list = Vec::<BenchmarkList>::new();670671                    list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);672                    list_benchmark!(list, extra, pallet_common, Common);673                    list_benchmark!(list, extra, pallet_unique, Unique);674                    list_benchmark!(list, extra, pallet_structure, Structure);675                    list_benchmark!(list, extra, pallet_inflation, Inflation);676                    list_benchmark!(list, extra, pallet_app_promotion, AppPromotion);677                    list_benchmark!(list, extra, pallet_fungible, Fungible);678                    list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);679680                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]681                    list_benchmark!(list, extra, pallet_refungible, Refungible);682683                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]684                    list_benchmark!(list, extra, pallet_unique_scheduler, Scheduler);685686                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]687                    list_benchmark!(list, extra, pallet_proxy_rmrk_core, RmrkCore);688689                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]690                    list_benchmark!(list, extra, pallet_proxy_rmrk_equip, RmrkEquip);691692                    // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);693694                    let storage_info = AllPalletsReversedWithSystemFirst::storage_info();695696                    return (list, storage_info)697                }698699                fn dispatch_benchmark(700                    config: frame_benchmarking::BenchmarkConfig701                ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {702                    use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};703704                    let allowlist: Vec<TrackedStorageKey> = vec![705                        // Total Issuance706                        hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),707708                        // Block Number709                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),710                        // Execution Phase711                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),712                        // Event Count713                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),714                        // System Events715                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),716717                        // Evm CurrentLogs718                        hex_literal::hex!("1da53b775b270400e7e61ed5cbc5a146547f210cec367e9af919603343b9cb56").to_vec().into(),719720                        // Transactional depth721                        hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),722                    ];723724                    let mut batches = Vec::<BenchmarkBatch>::new();725                    let params = (&config, &allowlist);726727                    add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);728                    add_benchmark!(params, batches, pallet_common, Common);729                    add_benchmark!(params, batches, pallet_unique, Unique);730                    add_benchmark!(params, batches, pallet_structure, Structure);731                    add_benchmark!(params, batches, pallet_inflation, Inflation);732                    add_benchmark!(params, batches, pallet_app_promotion, AppPromotion);733                    add_benchmark!(params, batches, pallet_fungible, Fungible);734                    add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);735736                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]737                    add_benchmark!(params, batches, pallet_refungible, Refungible);738739                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]740                    add_benchmark!(params, batches, pallet_unique_scheduler, Scheduler);741742                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]743                    add_benchmark!(params, batches, pallet_proxy_rmrk_core, RmrkCore);744745                    #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]746                    add_benchmark!(params, batches, pallet_proxy_rmrk_equip, RmrkEquip);747748                    // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);749750                    if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }751                    Ok(batches)752                }753            }754755            #[cfg(feature = "try-runtime")]756            impl frame_try_runtime::TryRuntime<Block> for Runtime {757                fn on_runtime_upgrade() -> (frame_support::pallet_prelude::Weight, frame_support::pallet_prelude::Weight) {758                    log::info!("try-runtime::on_runtime_upgrade unique-chain.");759                    let weight = Executive::try_runtime_upgrade().unwrap();760                    (weight, crate::config::substrate::RuntimeBlockWeights::get().max_block)761                }762763                fn execute_block_no_check(block: Block) -> frame_support::pallet_prelude::Weight {764                    Executive::execute_block_no_check(block)765                }766            }767        }768    }769}