difftreelog
fix use allow on whole impl
in: master
1 file changed
runtime/common/src/runtime_apis.rsdiffbeforeafterboth1// 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! impl_common_runtime_apis {19 (20 $(21 #![custom_apis]2223 $($custom_apis:tt)+24 )?25 ) => {26 impl_runtime_apis! {27 $($($custom_apis)+)?2829 impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {30 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {31 dispatch_unique_runtime!(collection.account_tokens(account))32 }33 fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {34 dispatch_unique_runtime!(collection.collection_tokens())35 }36 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {37 dispatch_unique_runtime!(collection.token_exists(token))38 }3940 fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {41 dispatch_unique_runtime!(collection.token_owner(token))42 }4344 fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>, DispatchError> {45 dispatch_unique_runtime!(collection.token_owners(token))46 }4748 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {49 let budget = up_data_structs::budget::Value::new(10);5051 Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))52 }53 fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>, DispatchError> {54 Ok(<pallet_nonfungible::Pallet<Runtime>>::token_children_ids(collection, token))55 }56 fn collection_properties(57 collection: CollectionId,58 keys: Option<Vec<Vec<u8>>>59 ) -> Result<Vec<Property>, DispatchError> {60 let keys = keys.map(61 |keys| Common::bytes_keys_to_property_keys(keys)62 ).transpose()?;6364 Common::filter_collection_properties(collection, keys)65 }6667 fn token_properties(68 collection: CollectionId,69 token_id: TokenId,70 keys: Option<Vec<Vec<u8>>>71 ) -> Result<Vec<Property>, DispatchError> {72 let keys = keys.map(73 |keys| Common::bytes_keys_to_property_keys(keys)74 ).transpose()?;7576 dispatch_unique_runtime!(collection.token_properties(token_id, keys))77 }7879 fn property_permissions(80 collection: CollectionId,81 keys: Option<Vec<Vec<u8>>>82 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {83 let keys = keys.map(84 |keys| Common::bytes_keys_to_property_keys(keys)85 ).transpose()?;8687 Common::filter_property_permissions(collection, keys)88 }8990 fn token_data(91 collection: CollectionId,92 token_id: TokenId,93 keys: Option<Vec<Vec<u8>>>94 ) -> Result<TokenData<CrossAccountId>, DispatchError> {95 let token_data = TokenData {96 properties: Self::token_properties(collection, token_id, keys)?,97 owner: Self::token_owner(collection, token_id)?,98 pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0),99 };100101 Ok(token_data)102 }103104 fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {105 dispatch_unique_runtime!(collection.total_supply())106 }107 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {108 dispatch_unique_runtime!(collection.account_balance(account))109 }110 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {111 dispatch_unique_runtime!(collection.balance(account, token))112 }113 fn allowance(114 collection: CollectionId,115 sender: CrossAccountId,116 spender: CrossAccountId,117 token: TokenId,118 ) -> Result<u128, DispatchError> {119 dispatch_unique_runtime!(collection.allowance(sender, spender, token))120 }121122 fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {123 Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))124 }125 fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {126 Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))127 }128 fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {129 Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))130 }131 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {132 dispatch_unique_runtime!(collection.last_token_id())133 }134 fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>, DispatchError> {135 Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(collection))136 }137 fn collection_stats() -> Result<CollectionStats, DispatchError> {138 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())139 }140 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {141 Ok(<$crate::sponsoring::UniqueSponsorshipPredict<Runtime> as142 $crate::sponsoring::SponsorshipPredict<Runtime>>::predict(143 collection,144 account,145 token))146 }147148 fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {149 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))150 }151152 fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<Option<u128>, DispatchError> {153 dispatch_unique_runtime!(collection.total_pieces(token_id))154 }155 }156157 impl rmrk_rpc::RmrkApi<158 Block,159 AccountId,160 RmrkCollectionInfo<AccountId>,161 RmrkInstanceInfo<AccountId>,162 RmrkResourceInfo,163 RmrkPropertyInfo,164 RmrkBaseInfo<AccountId>,165 RmrkPartType,166 RmrkTheme167 > for Runtime {168 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {169 #[cfg(feature = "rmrk")]170 return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();171172 #[cfg(not(feature = "rmrk"))]173 return Ok(Default::default());174 }175176 fn collection_by_id(177 #[allow(unused_variables)]178 collection_id: RmrkCollectionId179 ) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {180 #[cfg(feature = "rmrk")]181 return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);182183 #[cfg(not(feature = "rmrk"))]184 return Ok(Default::default())185 }186187 fn nft_by_id(188 #[allow(unused_variables)]189 collection_id: RmrkCollectionId,190191 #[allow(unused_variables)]192 nft_by_id: RmrkNftId193 ) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {194 #[cfg(feature = "rmrk")]195 return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);196197 #[cfg(not(feature = "rmrk"))]198 return Ok(Default::default())199 }200201 fn account_tokens(202 #[allow(unused_variables)]203 account_id: AccountId,204205 #[allow(unused_variables)]206 collection_id: RmrkCollectionId207 ) -> Result<Vec<RmrkNftId>, DispatchError> {208 #[cfg(feature = "rmrk")]209 return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);210211 #[cfg(not(feature = "rmrk"))]212 return Ok(Default::default())213 }214215 fn nft_children(216 #[allow(unused_variables)]217 collection_id: RmrkCollectionId,218219 #[allow(unused_variables)]220 nft_id: RmrkNftId221 ) -> Result<Vec<RmrkNftChild>, DispatchError> {222 #[cfg(feature = "rmrk")]223 return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);224225 #[cfg(not(feature = "rmrk"))]226 return Ok(Default::default())227 }228229 fn collection_properties(230 #[allow(unused_variables)]231 collection_id: RmrkCollectionId,232233 #[allow(unused_variables)]234 filter_keys: Option<Vec<RmrkPropertyKey>>235 ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {236 #[cfg(feature = "rmrk")]237 return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);238239 #[cfg(not(feature = "rmrk"))]240 return Ok(Default::default())241 }242243 fn nft_properties(244 #[allow(unused_variables)]245 collection_id: RmrkCollectionId,246247 #[allow(unused_variables)]248 nft_id: RmrkNftId,249250 #[allow(unused_variables)]251 filter_keys: Option<Vec<RmrkPropertyKey>>252 ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {253 #[cfg(feature = "rmrk")]254 return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);255256 #[cfg(not(feature = "rmrk"))]257 return Ok(Default::default())258 }259260 fn nft_resources(261 #[allow(unused_variables)]262 collection_id: RmrkCollectionId,263264 #[allow(unused_variables)]265 nft_id: RmrkNftId266 ) -> Result<Vec<RmrkResourceInfo>, DispatchError> {267 #[cfg(feature = "rmrk")]268 return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);269270 #[cfg(not(feature = "rmrk"))]271 return Ok(Default::default())272 }273274 fn nft_resource_priority(275 #[allow(unused_variables)]276 collection_id: RmrkCollectionId,277278 #[allow(unused_variables)]279 nft_id: RmrkNftId,280281 #[allow(unused_variables)]282 resource_id: RmrkResourceId283 ) -> Result<Option<u32>, DispatchError> {284 #[cfg(feature = "rmrk")]285 return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);286287 #[cfg(not(feature = "rmrk"))]288 return Ok(Default::default())289 }290291 fn base(292 #[allow(unused_variables)]293 base_id: RmrkBaseId294 ) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {295 #[cfg(feature = "rmrk")]296 return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);297298 #[cfg(not(feature = "rmrk"))]299 return Ok(Default::default())300 }301302 fn base_parts(303 #[allow(unused_variables)]304 base_id: RmrkBaseId305 ) -> Result<Vec<RmrkPartType>, DispatchError> {306 #[cfg(feature = "rmrk")]307 return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);308309 #[cfg(not(feature = "rmrk"))]310 return Ok(Default::default())311 }312313 fn theme_names(314 #[allow(unused_variables)]315 base_id: RmrkBaseId316 ) -> Result<Vec<RmrkThemeName>, DispatchError> {317 #[cfg(feature = "rmrk")]318 return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);319320 #[cfg(not(feature = "rmrk"))]321 Ok(Default::default())322 }323324 fn theme(325 #[allow(unused_variables)]326 base_id: RmrkBaseId,327328 #[allow(unused_variables)]329 theme_name: RmrkThemeName,330331 #[allow(unused_variables)]332 filter_keys: Option<Vec<RmrkPropertyKey>>333 ) -> Result<Option<RmrkTheme>, DispatchError> {334 #[cfg(feature = "rmrk")]335 return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);336337 #[cfg(not(feature = "rmrk"))]338 return Ok(Default::default())339 }340 }341342 impl sp_api::Core<Block> for Runtime {343 fn version() -> RuntimeVersion {344 VERSION345 }346347 fn execute_block(block: Block) {348 Executive::execute_block(block)349 }350351 fn initialize_block(header: &<Block as BlockT>::Header) {352 Executive::initialize_block(header)353 }354 }355356 impl sp_api::Metadata<Block> for Runtime {357 fn metadata() -> OpaqueMetadata {358 OpaqueMetadata::new(Runtime::metadata().into())359 }360 }361362 impl sp_block_builder::BlockBuilder<Block> for Runtime {363 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {364 Executive::apply_extrinsic(extrinsic)365 }366367 fn finalize_block() -> <Block as BlockT>::Header {368 Executive::finalize_block()369 }370371 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {372 data.create_extrinsics()373 }374375 fn check_inherents(376 block: Block,377 data: sp_inherents::InherentData,378 ) -> sp_inherents::CheckInherentsResult {379 data.check_extrinsics(&block)380 }381382 // fn random_seed() -> <Block as BlockT>::Hash {383 // RandomnessCollectiveFlip::random_seed().0384 // }385 }386387 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {388 fn validate_transaction(389 source: TransactionSource,390 tx: <Block as BlockT>::Extrinsic,391 hash: <Block as BlockT>::Hash,392 ) -> TransactionValidity {393 Executive::validate_transaction(source, tx, hash)394 }395 }396397 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {398 fn offchain_worker(header: &<Block as BlockT>::Header) {399 Executive::offchain_worker(header)400 }401 }402403 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {404 fn chain_id() -> u64 {405 <Runtime as pallet_evm::Config>::ChainId::get()406 }407408 fn account_basic(address: H160) -> EVMAccount {409 let (account, _) = EVM::account_basic(&address);410 account411 }412413 fn gas_price() -> U256 {414 let (price, _) = <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price();415 price416 }417418 fn account_code_at(address: H160) -> Vec<u8> {419 EVM::account_codes(address)420 }421422 fn author() -> H160 {423 <pallet_evm::Pallet<Runtime>>::find_author()424 }425426 fn storage_at(address: H160, index: U256) -> H256 {427 let mut tmp = [0u8; 32];428 index.to_big_endian(&mut tmp);429 EVM::account_storages(address, H256::from_slice(&tmp[..]))430 }431432 #[allow(clippy::redundant_closure)]433 fn call(434 from: H160,435 to: H160,436 data: Vec<u8>,437 value: U256,438 gas_limit: U256,439 max_fee_per_gas: Option<U256>,440 max_priority_fee_per_gas: Option<U256>,441 nonce: Option<U256>,442 estimate: bool,443 access_list: Option<Vec<(H160, Vec<H256>)>>,444 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {445 let config = if estimate {446 let mut config = <Runtime as pallet_evm::Config>::config().clone();447 config.estimate = true;448 Some(config)449 } else {450 None451 };452453 let is_transactional = false;454 <Runtime as pallet_evm::Config>::Runner::call(455 CrossAccountId::from_eth(from),456 to,457 data,458 value,459 gas_limit.low_u64(),460 max_fee_per_gas,461 max_priority_fee_per_gas,462 nonce,463 access_list.unwrap_or_default(),464 is_transactional,465 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),466 ).map_err(|err| err.error.into())467 }468469 #[allow(clippy::redundant_closure)]470 fn create(471 from: H160,472 data: Vec<u8>,473 value: U256,474 gas_limit: U256,475 max_fee_per_gas: Option<U256>,476 max_priority_fee_per_gas: Option<U256>,477 nonce: Option<U256>,478 estimate: bool,479 access_list: Option<Vec<(H160, Vec<H256>)>>,480 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {481 let config = if estimate {482 let mut config = <Runtime as pallet_evm::Config>::config().clone();483 config.estimate = true;484 Some(config)485 } else {486 None487 };488489 let is_transactional = false;490 <Runtime as pallet_evm::Config>::Runner::create(491 CrossAccountId::from_eth(from),492 data,493 value,494 gas_limit.low_u64(),495 max_fee_per_gas,496 max_priority_fee_per_gas,497 nonce,498 access_list.unwrap_or_default(),499 is_transactional,500 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),501 ).map_err(|err| err.error.into())502 }503504 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {505 Ethereum::current_transaction_statuses()506 }507508 fn current_block() -> Option<pallet_ethereum::Block> {509 Ethereum::current_block()510 }511512 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {513 Ethereum::current_receipts()514 }515516 fn current_all() -> (517 Option<pallet_ethereum::Block>,518 Option<Vec<pallet_ethereum::Receipt>>,519 Option<Vec<TransactionStatus>>520 ) {521 (522 Ethereum::current_block(),523 Ethereum::current_receipts(),524 Ethereum::current_transaction_statuses()525 )526 }527528 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {529 xts.into_iter().filter_map(|xt| match xt.0.function {530 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),531 _ => None532 }).collect()533 }534535 fn elasticity() -> Option<Permill> {536 None537 }538 }539540 impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {541 fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic {542 UncheckedExtrinsic::new_unsigned(543 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),544 )545 }546 }547548 impl sp_session::SessionKeys<Block> for Runtime {549 fn decode_session_keys(550 encoded: Vec<u8>,551 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {552 SessionKeys::decode_into_raw_public_keys(&encoded)553 }554555 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {556 SessionKeys::generate(seed)557 }558 }559560 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {561 fn slot_duration() -> sp_consensus_aura::SlotDuration {562 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())563 }564565 fn authorities() -> Vec<AuraId> {566 Aura::authorities().to_vec()567 }568 }569570 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {571 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {572 ParachainSystem::collect_collation_info(header)573 }574 }575576 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {577 fn account_nonce(account: AccountId) -> Index {578 System::account_nonce(account)579 }580 }581582 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {583 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {584 TransactionPayment::query_info(uxt, len)585 }586 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {587 TransactionPayment::query_fee_details(uxt, len)588 }589 }590591 /*592 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>593 for Runtime594 {595 fn call(596 origin: AccountId,597 dest: AccountId,598 value: Balance,599 gas_limit: u64,600 input_data: Vec<u8>,601 ) -> pallet_contracts_primitives::ContractExecResult {602 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)603 }604605 fn instantiate(606 origin: AccountId,607 endowment: Balance,608 gas_limit: u64,609 code: pallet_contracts_primitives::Code<Hash>,610 data: Vec<u8>,611 salt: Vec<u8>,612 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>613 {614 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)615 }616617 fn get_storage(618 address: AccountId,619 key: [u8; 32],620 ) -> pallet_contracts_primitives::GetStorageResult {621 Contracts::get_storage(address, key)622 }623624 fn rent_projection(625 address: AccountId,626 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {627 Contracts::rent_projection(address)628 }629 }630 */631632 #[cfg(feature = "runtime-benchmarks")]633 impl frame_benchmarking::Benchmark<Block> for Runtime {634 fn benchmark_metadata(extra: bool) -> (635 Vec<frame_benchmarking::BenchmarkList>,636 Vec<frame_support::traits::StorageInfo>,637 ) {638 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};639 use frame_support::traits::StorageInfoTrait;640641 let mut list = Vec::<BenchmarkList>::new();642643 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);644 list_benchmark!(list, extra, pallet_common, Common);645 list_benchmark!(list, extra, pallet_unique, Unique);646 list_benchmark!(list, extra, pallet_structure, Structure);647 list_benchmark!(list, extra, pallet_inflation, Inflation);648 list_benchmark!(list, extra, pallet_fungible, Fungible);649 list_benchmark!(list, extra, pallet_refungible, Refungible);650 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);651 list_benchmark!(list, extra, pallet_unique_scheduler, Scheduler);652653 #[cfg(not(feature = "unique-runtime"))]654 list_benchmark!(list, extra, pallet_proxy_rmrk_core, RmrkCore);655656 #[cfg(not(feature = "unique-runtime"))]657 list_benchmark!(list, extra, pallet_proxy_rmrk_equip, RmrkEquip);658659 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);660661 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();662663 return (list, storage_info)664 }665666 fn dispatch_benchmark(667 config: frame_benchmarking::BenchmarkConfig668 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {669 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};670671 let allowlist: Vec<TrackedStorageKey> = vec![672 // Total Issuance673 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),674675 // Block Number676 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),677 // Execution Phase678 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),679 // Event Count680 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),681 // System Events682 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),683684 // Evm CurrentLogs685 hex_literal::hex!("1da53b775b270400e7e61ed5cbc5a146547f210cec367e9af919603343b9cb56").to_vec().into(),686687 // Transactional depth688 hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),689 ];690691 let mut batches = Vec::<BenchmarkBatch>::new();692 let params = (&config, &allowlist);693694 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);695 add_benchmark!(params, batches, pallet_common, Common);696 add_benchmark!(params, batches, pallet_unique, Unique);697 add_benchmark!(params, batches, pallet_structure, Structure);698 add_benchmark!(params, batches, pallet_inflation, Inflation);699 add_benchmark!(params, batches, pallet_fungible, Fungible);700 add_benchmark!(params, batches, pallet_refungible, Refungible);701 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);702 add_benchmark!(params, batches, pallet_unique_scheduler, Scheduler);703704 #[cfg(not(feature = "unique-runtime"))]705 add_benchmark!(params, batches, pallet_proxy_rmrk_core, RmrkCore);706707 #[cfg(not(feature = "unique-runtime"))]708 add_benchmark!(params, batches, pallet_proxy_rmrk_equip, RmrkEquip);709710 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);711712 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }713 Ok(batches)714 }715 }716717 #[cfg(feature = "try-runtime")]718 impl frame_try_runtime::TryRuntime<Block> for Runtime {719 fn on_runtime_upgrade() -> (Weight, Weight) {720 log::info!("try-runtime::on_runtime_upgrade unique-chain.");721 let weight = Executive::try_runtime_upgrade().unwrap();722 (weight, RuntimeBlockWeights::get().max_block)723 }724725 fn execute_block_no_check(block: Block) -> Weight {726 Executive::execute_block_no_check(block)727 }728 }729 }730 }731}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! impl_common_runtime_apis {19 (20 $(21 #![custom_apis]2223 $($custom_apis:tt)+24 )?25 ) => {26 impl_runtime_apis! {27 $($($custom_apis)+)?2829 impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {30 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {31 dispatch_unique_runtime!(collection.account_tokens(account))32 }33 fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {34 dispatch_unique_runtime!(collection.collection_tokens())35 }36 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {37 dispatch_unique_runtime!(collection.token_exists(token))38 }3940 fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {41 dispatch_unique_runtime!(collection.token_owner(token))42 }4344 fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>, DispatchError> {45 dispatch_unique_runtime!(collection.token_owners(token))46 }4748 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {49 let budget = up_data_structs::budget::Value::new(10);5051 Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))52 }53 fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>, DispatchError> {54 Ok(<pallet_nonfungible::Pallet<Runtime>>::token_children_ids(collection, token))55 }56 fn collection_properties(57 collection: CollectionId,58 keys: Option<Vec<Vec<u8>>>59 ) -> Result<Vec<Property>, DispatchError> {60 let keys = keys.map(61 |keys| Common::bytes_keys_to_property_keys(keys)62 ).transpose()?;6364 Common::filter_collection_properties(collection, keys)65 }6667 fn token_properties(68 collection: CollectionId,69 token_id: TokenId,70 keys: Option<Vec<Vec<u8>>>71 ) -> Result<Vec<Property>, DispatchError> {72 let keys = keys.map(73 |keys| Common::bytes_keys_to_property_keys(keys)74 ).transpose()?;7576 dispatch_unique_runtime!(collection.token_properties(token_id, keys))77 }7879 fn property_permissions(80 collection: CollectionId,81 keys: Option<Vec<Vec<u8>>>82 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {83 let keys = keys.map(84 |keys| Common::bytes_keys_to_property_keys(keys)85 ).transpose()?;8687 Common::filter_property_permissions(collection, keys)88 }8990 fn token_data(91 collection: CollectionId,92 token_id: TokenId,93 keys: Option<Vec<Vec<u8>>>94 ) -> Result<TokenData<CrossAccountId>, DispatchError> {95 let token_data = TokenData {96 properties: Self::token_properties(collection, token_id, keys)?,97 owner: Self::token_owner(collection, token_id)?,98 pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0),99 };100101 Ok(token_data)102 }103104 fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {105 dispatch_unique_runtime!(collection.total_supply())106 }107 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {108 dispatch_unique_runtime!(collection.account_balance(account))109 }110 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {111 dispatch_unique_runtime!(collection.balance(account, token))112 }113 fn allowance(114 collection: CollectionId,115 sender: CrossAccountId,116 spender: CrossAccountId,117 token: TokenId,118 ) -> Result<u128, DispatchError> {119 dispatch_unique_runtime!(collection.allowance(sender, spender, token))120 }121122 fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {123 Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))124 }125 fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {126 Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))127 }128 fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {129 Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))130 }131 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {132 dispatch_unique_runtime!(collection.last_token_id())133 }134 fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>, DispatchError> {135 Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(collection))136 }137 fn collection_stats() -> Result<CollectionStats, DispatchError> {138 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())139 }140 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {141 Ok(<$crate::sponsoring::UniqueSponsorshipPredict<Runtime> as142 $crate::sponsoring::SponsorshipPredict<Runtime>>::predict(143 collection,144 account,145 token))146 }147148 fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {149 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))150 }151152 fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<Option<u128>, DispatchError> {153 dispatch_unique_runtime!(collection.total_pieces(token_id))154 }155 }156157 #[allow(unused_variables)]158 impl rmrk_rpc::RmrkApi<159 Block,160 AccountId,161 RmrkCollectionInfo<AccountId>,162 RmrkInstanceInfo<AccountId>,163 RmrkResourceInfo,164 RmrkPropertyInfo,165 RmrkBaseInfo<AccountId>,166 RmrkPartType,167 RmrkTheme168 > for Runtime {169 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {170 #[cfg(feature = "rmrk")]171 return pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>();172173 #[cfg(not(feature = "rmrk"))]174 return Ok(Default::default());175 }176177 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {178 #[cfg(feature = "rmrk")]179 return pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id);180181 #[cfg(not(feature = "rmrk"))]182 return Ok(Default::default())183 }184185 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {186 #[cfg(feature = "rmrk")]187 return pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id);188189 #[cfg(not(feature = "rmrk"))]190 return Ok(Default::default())191 }192193 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {194 #[cfg(feature = "rmrk")]195 return pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id);196197 #[cfg(not(feature = "rmrk"))]198 return Ok(Default::default())199 }200201 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {202 #[cfg(feature = "rmrk")]203 return pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id);204205 #[cfg(not(feature = "rmrk"))]206 return Ok(Default::default())207 }208209 fn collection_properties(210 collection_id: RmrkCollectionId,211 filter_keys: Option<Vec<RmrkPropertyKey>>212 ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {213 #[cfg(feature = "rmrk")]214 return pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys);215216 #[cfg(not(feature = "rmrk"))]217 return Ok(Default::default())218 }219220 fn nft_properties(221 collection_id: RmrkCollectionId,222 nft_id: RmrkNftId,223 filter_keys: Option<Vec<RmrkPropertyKey>>224 ) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {225 #[cfg(feature = "rmrk")]226 return pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys);227228 #[cfg(not(feature = "rmrk"))]229 return Ok(Default::default())230 }231232 fn nft_resources(collection_id: RmrkCollectionId,nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {233 #[cfg(feature = "rmrk")]234 return pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id);235236 #[cfg(not(feature = "rmrk"))]237 return Ok(Default::default())238 }239240 fn nft_resource_priority(241 collection_id: RmrkCollectionId,242 nft_id: RmrkNftId,243 resource_id: RmrkResourceId244 ) -> Result<Option<u32>, DispatchError> {245 #[cfg(feature = "rmrk")]246 return pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id);247248 #[cfg(not(feature = "rmrk"))]249 return Ok(Default::default())250 }251252 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {253 #[cfg(feature = "rmrk")]254 return pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id);255256 #[cfg(not(feature = "rmrk"))]257 return Ok(Default::default())258 }259260 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {261 #[cfg(feature = "rmrk")]262 return pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id);263264 #[cfg(not(feature = "rmrk"))]265 return Ok(Default::default())266 }267268 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {269 #[cfg(feature = "rmrk")]270 return pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id);271272 #[cfg(not(feature = "rmrk"))]273 Ok(Default::default())274 }275276 fn theme(277 base_id: RmrkBaseId,278 theme_name: RmrkThemeName,279 filter_keys: Option<Vec<RmrkPropertyKey>>280 ) -> Result<Option<RmrkTheme>, DispatchError> {281 #[cfg(feature = "rmrk")]282 return pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys);283284 #[cfg(not(feature = "rmrk"))]285 return Ok(Default::default())286 }287 }288289 impl sp_api::Core<Block> for Runtime {290 fn version() -> RuntimeVersion {291 VERSION292 }293294 fn execute_block(block: Block) {295 Executive::execute_block(block)296 }297298 fn initialize_block(header: &<Block as BlockT>::Header) {299 Executive::initialize_block(header)300 }301 }302303 impl sp_api::Metadata<Block> for Runtime {304 fn metadata() -> OpaqueMetadata {305 OpaqueMetadata::new(Runtime::metadata().into())306 }307 }308309 impl sp_block_builder::BlockBuilder<Block> for Runtime {310 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {311 Executive::apply_extrinsic(extrinsic)312 }313314 fn finalize_block() -> <Block as BlockT>::Header {315 Executive::finalize_block()316 }317318 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {319 data.create_extrinsics()320 }321322 fn check_inherents(323 block: Block,324 data: sp_inherents::InherentData,325 ) -> sp_inherents::CheckInherentsResult {326 data.check_extrinsics(&block)327 }328329 // fn random_seed() -> <Block as BlockT>::Hash {330 // RandomnessCollectiveFlip::random_seed().0331 // }332 }333334 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {335 fn validate_transaction(336 source: TransactionSource,337 tx: <Block as BlockT>::Extrinsic,338 hash: <Block as BlockT>::Hash,339 ) -> TransactionValidity {340 Executive::validate_transaction(source, tx, hash)341 }342 }343344 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {345 fn offchain_worker(header: &<Block as BlockT>::Header) {346 Executive::offchain_worker(header)347 }348 }349350 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {351 fn chain_id() -> u64 {352 <Runtime as pallet_evm::Config>::ChainId::get()353 }354355 fn account_basic(address: H160) -> EVMAccount {356 let (account, _) = EVM::account_basic(&address);357 account358 }359360 fn gas_price() -> U256 {361 let (price, _) = <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price();362 price363 }364365 fn account_code_at(address: H160) -> Vec<u8> {366 EVM::account_codes(address)367 }368369 fn author() -> H160 {370 <pallet_evm::Pallet<Runtime>>::find_author()371 }372373 fn storage_at(address: H160, index: U256) -> H256 {374 let mut tmp = [0u8; 32];375 index.to_big_endian(&mut tmp);376 EVM::account_storages(address, H256::from_slice(&tmp[..]))377 }378379 #[allow(clippy::redundant_closure)]380 fn call(381 from: H160,382 to: H160,383 data: Vec<u8>,384 value: U256,385 gas_limit: U256,386 max_fee_per_gas: Option<U256>,387 max_priority_fee_per_gas: Option<U256>,388 nonce: Option<U256>,389 estimate: bool,390 access_list: Option<Vec<(H160, Vec<H256>)>>,391 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {392 let config = if estimate {393 let mut config = <Runtime as pallet_evm::Config>::config().clone();394 config.estimate = true;395 Some(config)396 } else {397 None398 };399400 let is_transactional = false;401 <Runtime as pallet_evm::Config>::Runner::call(402 CrossAccountId::from_eth(from),403 to,404 data,405 value,406 gas_limit.low_u64(),407 max_fee_per_gas,408 max_priority_fee_per_gas,409 nonce,410 access_list.unwrap_or_default(),411 is_transactional,412 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),413 ).map_err(|err| err.error.into())414 }415416 #[allow(clippy::redundant_closure)]417 fn create(418 from: H160,419 data: Vec<u8>,420 value: U256,421 gas_limit: U256,422 max_fee_per_gas: Option<U256>,423 max_priority_fee_per_gas: Option<U256>,424 nonce: Option<U256>,425 estimate: bool,426 access_list: Option<Vec<(H160, Vec<H256>)>>,427 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {428 let config = if estimate {429 let mut config = <Runtime as pallet_evm::Config>::config().clone();430 config.estimate = true;431 Some(config)432 } else {433 None434 };435436 let is_transactional = false;437 <Runtime as pallet_evm::Config>::Runner::create(438 CrossAccountId::from_eth(from),439 data,440 value,441 gas_limit.low_u64(),442 max_fee_per_gas,443 max_priority_fee_per_gas,444 nonce,445 access_list.unwrap_or_default(),446 is_transactional,447 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),448 ).map_err(|err| err.error.into())449 }450451 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {452 Ethereum::current_transaction_statuses()453 }454455 fn current_block() -> Option<pallet_ethereum::Block> {456 Ethereum::current_block()457 }458459 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {460 Ethereum::current_receipts()461 }462463 fn current_all() -> (464 Option<pallet_ethereum::Block>,465 Option<Vec<pallet_ethereum::Receipt>>,466 Option<Vec<TransactionStatus>>467 ) {468 (469 Ethereum::current_block(),470 Ethereum::current_receipts(),471 Ethereum::current_transaction_statuses()472 )473 }474475 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {476 xts.into_iter().filter_map(|xt| match xt.0.function {477 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),478 _ => None479 }).collect()480 }481482 fn elasticity() -> Option<Permill> {483 None484 }485 }486487 impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {488 fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic {489 UncheckedExtrinsic::new_unsigned(490 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),491 )492 }493 }494495 impl sp_session::SessionKeys<Block> for Runtime {496 fn decode_session_keys(497 encoded: Vec<u8>,498 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {499 SessionKeys::decode_into_raw_public_keys(&encoded)500 }501502 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {503 SessionKeys::generate(seed)504 }505 }506507 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {508 fn slot_duration() -> sp_consensus_aura::SlotDuration {509 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())510 }511512 fn authorities() -> Vec<AuraId> {513 Aura::authorities().to_vec()514 }515 }516517 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {518 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {519 ParachainSystem::collect_collation_info(header)520 }521 }522523 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {524 fn account_nonce(account: AccountId) -> Index {525 System::account_nonce(account)526 }527 }528529 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {530 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {531 TransactionPayment::query_info(uxt, len)532 }533 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {534 TransactionPayment::query_fee_details(uxt, len)535 }536 }537538 /*539 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>540 for Runtime541 {542 fn call(543 origin: AccountId,544 dest: AccountId,545 value: Balance,546 gas_limit: u64,547 input_data: Vec<u8>,548 ) -> pallet_contracts_primitives::ContractExecResult {549 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)550 }551552 fn instantiate(553 origin: AccountId,554 endowment: Balance,555 gas_limit: u64,556 code: pallet_contracts_primitives::Code<Hash>,557 data: Vec<u8>,558 salt: Vec<u8>,559 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>560 {561 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)562 }563564 fn get_storage(565 address: AccountId,566 key: [u8; 32],567 ) -> pallet_contracts_primitives::GetStorageResult {568 Contracts::get_storage(address, key)569 }570571 fn rent_projection(572 address: AccountId,573 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {574 Contracts::rent_projection(address)575 }576 }577 */578579 #[cfg(feature = "runtime-benchmarks")]580 impl frame_benchmarking::Benchmark<Block> for Runtime {581 fn benchmark_metadata(extra: bool) -> (582 Vec<frame_benchmarking::BenchmarkList>,583 Vec<frame_support::traits::StorageInfo>,584 ) {585 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};586 use frame_support::traits::StorageInfoTrait;587588 let mut list = Vec::<BenchmarkList>::new();589590 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);591 list_benchmark!(list, extra, pallet_common, Common);592 list_benchmark!(list, extra, pallet_unique, Unique);593 list_benchmark!(list, extra, pallet_structure, Structure);594 list_benchmark!(list, extra, pallet_inflation, Inflation);595 list_benchmark!(list, extra, pallet_fungible, Fungible);596 list_benchmark!(list, extra, pallet_refungible, Refungible);597 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);598 list_benchmark!(list, extra, pallet_unique_scheduler, Scheduler);599600 #[cfg(not(feature = "unique-runtime"))]601 list_benchmark!(list, extra, pallet_proxy_rmrk_core, RmrkCore);602603 #[cfg(not(feature = "unique-runtime"))]604 list_benchmark!(list, extra, pallet_proxy_rmrk_equip, RmrkEquip);605606 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);607608 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();609610 return (list, storage_info)611 }612613 fn dispatch_benchmark(614 config: frame_benchmarking::BenchmarkConfig615 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {616 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};617618 let allowlist: Vec<TrackedStorageKey> = vec![619 // Total Issuance620 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),621622 // Block Number623 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),624 // Execution Phase625 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),626 // Event Count627 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),628 // System Events629 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),630631 // Evm CurrentLogs632 hex_literal::hex!("1da53b775b270400e7e61ed5cbc5a146547f210cec367e9af919603343b9cb56").to_vec().into(),633634 // Transactional depth635 hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),636 ];637638 let mut batches = Vec::<BenchmarkBatch>::new();639 let params = (&config, &allowlist);640641 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);642 add_benchmark!(params, batches, pallet_common, Common);643 add_benchmark!(params, batches, pallet_unique, Unique);644 add_benchmark!(params, batches, pallet_structure, Structure);645 add_benchmark!(params, batches, pallet_inflation, Inflation);646 add_benchmark!(params, batches, pallet_fungible, Fungible);647 add_benchmark!(params, batches, pallet_refungible, Refungible);648 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);649 add_benchmark!(params, batches, pallet_unique_scheduler, Scheduler);650651 #[cfg(not(feature = "unique-runtime"))]652 add_benchmark!(params, batches, pallet_proxy_rmrk_core, RmrkCore);653654 #[cfg(not(feature = "unique-runtime"))]655 add_benchmark!(params, batches, pallet_proxy_rmrk_equip, RmrkEquip);656657 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);658659 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }660 Ok(batches)661 }662 }663664 #[cfg(feature = "try-runtime")]665 impl frame_try_runtime::TryRuntime<Block> for Runtime {666 fn on_runtime_upgrade() -> (Weight, Weight) {667 log::info!("try-runtime::on_runtime_upgrade unique-chain.");668 let weight = Executive::try_runtime_upgrade().unwrap();669 (weight, RuntimeBlockWeights::get().max_block)670 }671672 fn execute_block_no_check(block: Block) -> Weight {673 Executive::execute_block_no_check(block)674 }675 }676 }677 }678}