1#[macro_export]2macro_rules! impl_common_runtime_apis {3 (4 $(5 #![custom_apis]67 $($custom_apis:tt)+8 )?9 ) => {10 impl_runtime_apis! {11 $($($custom_apis)+)?1213 impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {14 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {15 dispatch_unique_runtime!(collection.account_tokens(account))16 }17 fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {18 dispatch_unique_runtime!(collection.collection_tokens())19 }20 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {21 dispatch_unique_runtime!(collection.token_exists(token))22 }2324 fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {25 dispatch_unique_runtime!(collection.token_owner(token))26 }27 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {28 let budget = up_data_structs::budget::Value::new(5);2930 Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))31 }32 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {33 dispatch_unique_runtime!(collection.const_metadata(token))34 }3536 fn collection_properties(37 collection: CollectionId,38 keys: Option<Vec<Vec<u8>>>39 ) -> Result<Vec<Property>, DispatchError> {40 let keys = keys.map(41 |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)42 ).transpose()?;4344 pallet_common::Pallet::<Runtime>::filter_collection_properties(collection, keys)45 }4647 fn token_properties(48 collection: CollectionId,49 token_id: TokenId,50 keys: Option<Vec<Vec<u8>>>51 ) -> Result<Vec<Property>, DispatchError> {52 let keys = keys.map(53 |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)54 ).transpose()?;5556 dispatch_unique_runtime!(collection.token_properties(token_id, keys))57 }5859 fn property_permissions(60 collection: CollectionId,61 keys: Option<Vec<Vec<u8>>>62 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {63 let keys = keys.map(64 |keys| pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)65 ).transpose()?;6667 pallet_common::Pallet::<Runtime>::filter_property_permissions(collection, keys)68 }6970 fn token_data(71 collection: CollectionId,72 token_id: TokenId,73 keys: Option<Vec<Vec<u8>>>74 ) -> Result<TokenData<CrossAccountId>, DispatchError> {75 let token_data = TokenData {76 const_data: Self::const_metadata(collection, token_id)?,77 properties: Self::token_properties(collection, token_id, keys)?,78 owner: Self::token_owner(collection, token_id)?79 };8081 Ok(token_data)82 }8384 fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {85 dispatch_unique_runtime!(collection.total_supply())86 }87 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {88 dispatch_unique_runtime!(collection.account_balance(account))89 }90 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {91 dispatch_unique_runtime!(collection.balance(account, token))92 }93 fn allowance(94 collection: CollectionId,95 sender: CrossAccountId,96 spender: CrossAccountId,97 token: TokenId,98 ) -> Result<u128, DispatchError> {99 dispatch_unique_runtime!(collection.allowance(sender, spender, token))100 }101102 fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {103 Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))104 }105 fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {106 Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))107 }108 fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {109 Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))110 }111 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {112 dispatch_unique_runtime!(collection.last_token_id())113 }114 fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>, DispatchError> {115 Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(collection))116 }117 fn collection_stats() -> Result<CollectionStats, DispatchError> {118 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())119 }120 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {121 Ok(<$crate::sponsoring::UniqueSponsorshipPredict<Runtime> as122 $crate::sponsoring::SponsorshipPredict<Runtime>>::predict(123 collection,124 account,125 token))126 }127128 fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {129 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))130 }131 }132133 impl rmrk_rpc::RmrkApi<134 Block,135 AccountId,136 RmrkCollectionInfo<AccountId>,137 RmrkInstanceInfo<AccountId>,138 RmrkResourceInfo,139 RmrkPropertyInfo,140 RmrkBaseInfo<AccountId>,141 RmrkPartType,142 RmrkTheme143 > for Runtime {144 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {145 Ok(<pallet_common::CreatedCollectionCount<Runtime>>::get().0) 146 }147 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {148 149 use frame_support::BoundedVec;150 use scale_info::prelude::string::String;151 use pallet_proxy_rmrk_core::RmrkProperty;152153 154 155156 let collection_id = CollectionId(collection_id);157 let collection = <pallet_proxy_rmrk_core::Pallet<Runtime>>::get_nft_collection(collection_id)?;158 159 let metadata = BoundedVec::try_from(160 <pallet_proxy_rmrk_core::Pallet<Runtime>>::get_collection_property(collection_id, RmrkProperty::Metadata)?.into_inner()161 ).map_err(|_| <pallet_common::Error<Runtime>>::PropertyKeyIsTooLong)?;162 let nfts_count = (dispatch_unique_runtime!(collection_id.total_supply()) as Result<u32, DispatchError>)?; 163164 Ok(Some(RmrkCollectionInfo {165 issuer: collection.owner.clone(),166 metadata,167 max: collection.limits.token_limit,168 symbol: BoundedVec::try_from(169 collection.token_prefix.clone().into_inner()170 ).map_err(|_| <pallet_common::Error<Runtime>>::PropertyKeyIsTooLong)?,171 nfts_count172 }))173 }174 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {175 use frame_support::BoundedVec;176 use up_data_structs::mapping::TokenAddressMapping;177 use pallet_proxy_rmrk_core::RmrkProperty;178179 let collection_id = CollectionId(collection_id);180 let nft_id = TokenId(nft_by_id);181182 let owner = match (dispatch_unique_runtime!(collection_id.token_owner(nft_id)) as Result<Option<CrossAccountId>, DispatchError>)? {183 Some(owner) => match <Runtime as pallet_common::Config>::CrossTokenAddressMapping::address_to_token(&owner) {184 Some((col, tok)) => RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(col.0, tok.0),185 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())186 },187 None => return Ok(None)188 };189190 let keys = [191 RmrkProperty::Royalty,192 RmrkProperty::Metadata,193 RmrkProperty::Equipped,194 RmrkProperty::Pending,195 196 ];197198 let properties = keys.into_iter().map(199 |key| BoundedVec::try_from(200 201 <pallet_proxy_rmrk_core::Pallet<Runtime>>::get_nft_property(collection_id, nft_id, key).unwrap().into_inner()202 ).unwrap()203 )204 .collect::<Vec<RmrkString>>();205206 Ok(Some(RmrkInstanceInfo {207 owner: owner,208 209 royalty: None,210 metadata: properties[1].clone(),211 equipped: false, 212 pending: false, 213 }))214 }215 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {216 let cross_account_id = CrossAccountId::from_sub(account_id);217 let collection_id = CollectionId(collection_id);218 Ok(219 (dispatch_unique_runtime!(collection_id.account_tokens(cross_account_id)) as Result<Vec<TokenId>, DispatchError>)?220 221 .into_iter()222 .map(|token| token.0)223 .collect::<Vec<_>>()224 )225 }226 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {227 use up_data_structs::mapping::TokenAddressMapping;228229 let collection_id = CollectionId(collection_id);230 let nft_id = TokenId(nft_id);231 let cross_account_id = CrossAccountId::from_eth(232 EvmTokenAddressMapping::token_to_address(collection_id, nft_id)233 );234235 Ok(236 pallet_nonfungible::Owned::<Runtime>::iter_prefix((collection_id, cross_account_id))237 .map(|(child_id, _)| RmrkNftChild {238 collection_id: collection_id.0, 239 nft_id: child_id.0,240 })241 .collect()242 )243 }244 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {245 use frame_support::BoundedVec;246247 let collection_id = CollectionId(collection_id);248 let properties = pallet_common::Pallet::<Runtime>::collection_properties(collection_id);249250 return Ok(match filter_keys {251 Some(keys) => {252 let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;253 let properties = keys254 .into_iter()255 .filter_map(|key| {256 properties.get(&key).map(|value| RmrkPropertyInfo {257 key: BoundedVec::try_from(key.into_inner()).unwrap(),258 value: BoundedVec::try_from(value.clone().into_inner()).unwrap(),259 })260 })261 .collect();262263 properties264 }265 None => {266 properties267 .iter()268 .filter_map(|(key, value)| Some(RmrkPropertyInfo {269 key: BoundedVec::try_from(key.clone().into_inner()).unwrap(),270 value: BoundedVec::try_from(value.clone().into_inner()).unwrap(),271 }))272 .collect()273 }274 });275 }276 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {277 use frame_support::BoundedVec;278279 let collection_id = CollectionId(collection_id);280 let token_id = TokenId(nft_id);281282 let properties = pallet_nonfungible::Pallet::<Runtime>::token_properties((collection_id, token_id)); 283284 285 return Ok(match filter_keys {286 Some(keys) => {287 let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;288 let properties = keys289 .into_iter()290 .filter_map(|key| {291 properties.get(&key).map(|value| RmrkPropertyInfo {292 key: BoundedVec::try_from(key.into_inner()).unwrap(),293 value: BoundedVec::try_from(value.clone().into_inner()).unwrap(),294 })295 })296 .collect();297298 properties299 }300 None => {301 properties302 .iter()303 .filter_map(|(key, value)| Some(RmrkPropertyInfo {304 key: BoundedVec::try_from(key.clone().into_inner()).unwrap(),305 value: BoundedVec::try_from(value.clone().into_inner()).unwrap(),306 }))307 .collect()308 }309 });310 }311 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {312 use frame_support::BoundedVec;313 use pallet_proxy_rmrk_core::RmrkProperty;314315 let collection_id = CollectionId(collection_id);316 let nft_id = TokenId(nft_id);317318 let keys = [319 RmrkProperty::Royalty,320 RmrkProperty::Metadata,321 RmrkProperty::Equipped,322 RmrkProperty::Pending,323 324 ];325326 327328329330331332333 Ok(Vec::new(334335))336 }337 fn nft_resource_priorities(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceId>, DispatchError> {338 todo!()339 }340 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {341 use frame_support::BoundedVec;342 use scale_info::prelude::string::String;343 use pallet_proxy_rmrk_core::RmrkProperty;344345 let collection_id = CollectionId(base_id);346 let collection = <pallet_proxy_rmrk_core::Pallet<Runtime>>::get_nft_collection(collection_id)?;347348 349 let keys = [350 RmrkProperty::BaseType,351 ];352353 let properties = keys.into_iter().map(354 |key| BoundedVec::try_from(355 <pallet_proxy_rmrk_core::Pallet<Runtime>>::get_collection_property(collection_id, key).unwrap().into_inner()356 )357 )358 359 .collect::<Result<Vec<_>, _>>()360 .map_err(|_| <pallet_proxy_rmrk_core::Error<Runtime>>::CollectionUnknown)?;361362 Ok(Some(RmrkBaseInfo {363 issuer: collection.owner.clone(),364 base_type: properties[0].clone(),365 symbol: BoundedVec::try_from(366 collection.token_prefix.clone().into_inner()367 ).map_err(|_| <pallet_common::Error<Runtime>>::PropertyKeyIsTooLong)?,368 }))369 }370 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {371 use frame_support::BoundedVec;372 use pallet_proxy_rmrk_core::RmrkProperty;373374 let collection_id = CollectionId(base_id);375376 let keys = [377 378 379 RmrkProperty::Src,380 RmrkProperty::ZIndex,381 RmrkProperty::EquippableList,382 ];383384 let parts = (dispatch_unique_runtime!(collection_id.collection_tokens()) as Result<Vec<TokenId>, DispatchError>)?385 .iter()386 .filter_map(|token_id| {387 388389390391392393 394 395 let nft_type = "fixed-part";396397 match nft_type {398 "fixed-part" => Some(RmrkPartType::FixedPart(RmrkFixedPart {399 id: token_id.0,400 src: BoundedVec::default(), 401 z: 0, 402 })),403 "slot-part" => Some(RmrkPartType::SlotPart(RmrkSlotPart {404 id: token_id.0,405 equippable: RmrkEquippableList::Empty, 406 src: BoundedVec::default(), 407 z: 0, 408 })),409 _ => None410 }411412 })413 .collect();414415 Ok(parts)416 }417 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {418 use frame_support::BoundedVec;419420 let collection_id = CollectionId(base_id);421422 let theme_names = (dispatch_unique_runtime!(collection_id.collection_tokens()) as Result<Vec<TokenId>, DispatchError>)?423 .iter()424 .filter_map(|token_id| {425 let properties = pallet_nonfungible::Pallet::<Runtime>::token_properties((collection_id, token_id));426427 428 429 let nft_type = "theme";430 431 <pallet_nonfungible::TokenData<Runtime>>::get((collection_id, token_id))432 .map(|t| t.const_data.into_inner())433 434 435 })436 .collect();437438 Ok(theme_names)439 }440 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {441 use frame_support::BoundedVec;442443 let collection_id = CollectionId(base_id);444445 446 447 448 let themes = (dispatch_unique_runtime!(collection_id.collection_tokens()) as Result<Vec<TokenId>, DispatchError>)?449 .iter()450 .filter_map(|token_id| {451 let properties = pallet_nonfungible::Pallet::<Runtime>::token_properties((collection_id, token_id));452453 454 455 456 let nft_type = "theme";457 match nft_type {458 "theme" => Some(RmrkTheme {459 name: BoundedVec::try_from(460 <pallet_nonfungible::TokenData<Runtime>>::get((collection_id, token_id))461 .map(|t| t.const_data)462 .unwrap_or_default()463 .into_inner()464 ).unwrap(),465 466 properties: Vec::new(), 467 inherit: false, 468 }),469 _ => None470 }471 })472 .collect::<Vec<_>>();473474 475 Ok(Some(themes[0].clone()))476 }477 }478479 impl sp_api::Core<Block> for Runtime {480 fn version() -> RuntimeVersion {481 VERSION482 }483484 fn execute_block(block: Block) {485 Executive::execute_block(block)486 }487488 fn initialize_block(header: &<Block as BlockT>::Header) {489 Executive::initialize_block(header)490 }491 }492493 impl sp_api::Metadata<Block> for Runtime {494 fn metadata() -> OpaqueMetadata {495 OpaqueMetadata::new(Runtime::metadata().into())496 }497 }498499 impl sp_block_builder::BlockBuilder<Block> for Runtime {500 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {501 Executive::apply_extrinsic(extrinsic)502 }503504 fn finalize_block() -> <Block as BlockT>::Header {505 Executive::finalize_block()506 }507508 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {509 data.create_extrinsics()510 }511512 fn check_inherents(513 block: Block,514 data: sp_inherents::InherentData,515 ) -> sp_inherents::CheckInherentsResult {516 data.check_extrinsics(&block)517 }518519 520 521 522 }523524 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {525 fn validate_transaction(526 source: TransactionSource,527 tx: <Block as BlockT>::Extrinsic,528 hash: <Block as BlockT>::Hash,529 ) -> TransactionValidity {530 Executive::validate_transaction(source, tx, hash)531 }532 }533534 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {535 fn offchain_worker(header: &<Block as BlockT>::Header) {536 Executive::offchain_worker(header)537 }538 }539540 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {541 fn chain_id() -> u64 {542 <Runtime as pallet_evm::Config>::ChainId::get()543 }544545 fn account_basic(address: H160) -> EVMAccount {546 EVM::account_basic(&address)547 }548549 fn gas_price() -> U256 {550 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()551 }552553 fn account_code_at(address: H160) -> Vec<u8> {554 EVM::account_codes(address)555 }556557 fn author() -> H160 {558 <pallet_evm::Pallet<Runtime>>::find_author()559 }560561 fn storage_at(address: H160, index: U256) -> H256 {562 let mut tmp = [0u8; 32];563 index.to_big_endian(&mut tmp);564 EVM::account_storages(address, H256::from_slice(&tmp[..]))565 }566567 #[allow(clippy::redundant_closure)]568 fn call(569 from: H160,570 to: H160,571 data: Vec<u8>,572 value: U256,573 gas_limit: U256,574 max_fee_per_gas: Option<U256>,575 max_priority_fee_per_gas: Option<U256>,576 nonce: Option<U256>,577 estimate: bool,578 access_list: Option<Vec<(H160, Vec<H256>)>>,579 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {580 let config = if estimate {581 let mut config = <Runtime as pallet_evm::Config>::config().clone();582 config.estimate = true;583 Some(config)584 } else {585 None586 };587588 let is_transactional = false;589 <Runtime as pallet_evm::Config>::Runner::call(590 CrossAccountId::from_eth(from),591 to,592 data,593 value,594 gas_limit.low_u64(),595 max_fee_per_gas,596 max_priority_fee_per_gas,597 nonce,598 access_list.unwrap_or_default(),599 is_transactional,600 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),601 ).map_err(|err| err.into())602 }603604 #[allow(clippy::redundant_closure)]605 fn create(606 from: H160,607 data: Vec<u8>,608 value: U256,609 gas_limit: U256,610 max_fee_per_gas: Option<U256>,611 max_priority_fee_per_gas: Option<U256>,612 nonce: Option<U256>,613 estimate: bool,614 access_list: Option<Vec<(H160, Vec<H256>)>>,615 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {616 let config = if estimate {617 let mut config = <Runtime as pallet_evm::Config>::config().clone();618 config.estimate = true;619 Some(config)620 } else {621 None622 };623624 let is_transactional = false;625 <Runtime as pallet_evm::Config>::Runner::create(626 CrossAccountId::from_eth(from),627 data,628 value,629 gas_limit.low_u64(),630 max_fee_per_gas,631 max_priority_fee_per_gas,632 nonce,633 access_list.unwrap_or_default(),634 is_transactional,635 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),636 ).map_err(|err| err.into())637 }638639 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {640 Ethereum::current_transaction_statuses()641 }642643 fn current_block() -> Option<pallet_ethereum::Block> {644 Ethereum::current_block()645 }646647 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {648 Ethereum::current_receipts()649 }650651 fn current_all() -> (652 Option<pallet_ethereum::Block>,653 Option<Vec<pallet_ethereum::Receipt>>,654 Option<Vec<TransactionStatus>>655 ) {656 (657 Ethereum::current_block(),658 Ethereum::current_receipts(),659 Ethereum::current_transaction_statuses()660 )661 }662663 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {664 xts.into_iter().filter_map(|xt| match xt.0.function {665 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),666 _ => None667 }).collect()668 }669670 fn elasticity() -> Option<Permill> {671 None672 }673 }674675 impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {676 fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic {677 UncheckedExtrinsic::new_unsigned(678 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),679 )680 }681 }682683 impl sp_session::SessionKeys<Block> for Runtime {684 fn decode_session_keys(685 encoded: Vec<u8>,686 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {687 SessionKeys::decode_into_raw_public_keys(&encoded)688 }689690 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {691 SessionKeys::generate(seed)692 }693 }694695 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {696 fn slot_duration() -> sp_consensus_aura::SlotDuration {697 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())698 }699700 fn authorities() -> Vec<AuraId> {701 Aura::authorities().to_vec()702 }703 }704705 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {706 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {707 ParachainSystem::collect_collation_info(header)708 }709 }710711 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {712 fn account_nonce(account: AccountId) -> Index {713 System::account_nonce(account)714 }715 }716717 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {718 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {719 TransactionPayment::query_info(uxt, len)720 }721 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {722 TransactionPayment::query_fee_details(uxt, len)723 }724 }725726 727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767 #[cfg(feature = "runtime-benchmarks")]768 impl frame_benchmarking::Benchmark<Block> for Runtime {769 fn benchmark_metadata(extra: bool) -> (770 Vec<frame_benchmarking::BenchmarkList>,771 Vec<frame_support::traits::StorageInfo>,772 ) {773 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};774 use frame_support::traits::StorageInfoTrait;775776 let mut list = Vec::<BenchmarkList>::new();777778 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);779 list_benchmark!(list, extra, pallet_unique, Unique);780 list_benchmark!(list, extra, pallet_structure, Structure);781 list_benchmark!(list, extra, pallet_inflation, Inflation);782 list_benchmark!(list, extra, pallet_fungible, Fungible);783 list_benchmark!(list, extra, pallet_refungible, Refungible);784 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);785 786787 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();788789 return (list, storage_info)790 }791792 fn dispatch_benchmark(793 config: frame_benchmarking::BenchmarkConfig794 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {795 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};796797 let allowlist: Vec<TrackedStorageKey> = vec![798 799 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),800 801 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),802 803 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),804 805 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),806 807 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),808809 810 hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),811 ];812813 let mut batches = Vec::<BenchmarkBatch>::new();814 let params = (&config, &allowlist);815816 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);817 add_benchmark!(params, batches, pallet_unique, Unique);818 add_benchmark!(params, batches, pallet_structure, Structure);819 add_benchmark!(params, batches, pallet_inflation, Inflation);820 add_benchmark!(params, batches, pallet_fungible, Fungible);821 add_benchmark!(params, batches, pallet_refungible, Refungible);822 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);823 824825 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }826 Ok(batches)827 }828 }829830 #[cfg(feature = "try-runtime")]831 impl frame_try_runtime::TryRuntime<Block> for Runtime {832 fn on_runtime_upgrade() -> (Weight, Weight) {833 log::info!("try-runtime::on_runtime_upgrade unique-chain.");834 let weight = Executive::try_runtime_upgrade().unwrap();835 (weight, RuntimeBlockWeights::get().max_block)836 }837838 fn execute_block_no_check(block: Block) -> Weight {839 Executive::execute_block_no_check(block)840 }841 }842 }843 }844}