git.delta.rocks / unique-network / refs/commits / 1d826475f55f

difftreelog

Move runtime apis to common

Daniel Shiposha2022-03-10parent: #8060528.patch.diff
in: master

5 files changed

modifiedruntime/common/src/lib.rsdiffbeforeafterboth
--- a/runtime/common/src/lib.rs
+++ b/runtime/common/src/lib.rs
@@ -1,4 +1,5 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 
+pub mod runtime_apis;
 pub mod constants;
 pub mod types;
addedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/src/runtime_apis.rs
@@ -0,0 +1,409 @@
+#[macro_export]
+macro_rules! impl_common_runtime_apis {
+    (
+        $(
+            #![custom_apis]
+
+            $($custom_apis:tt)+
+        )?
+    ) => {
+        impl_runtime_apis! {
+            $($($custom_apis)+)?
+
+            impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {
+                fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {
+                    dispatch_unique_runtime!(collection.account_tokens(account))
+                }
+                fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {
+                    dispatch_unique_runtime!(collection.token_exists(token))
+                }
+
+                fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {
+                    dispatch_unique_runtime!(collection.token_owner(token))
+                }
+                fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
+                    dispatch_unique_runtime!(collection.const_metadata(token))
+                }
+                fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
+                    dispatch_unique_runtime!(collection.variable_metadata(token))
+                }
+
+                fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {
+                    dispatch_unique_runtime!(collection.collection_tokens())
+                }
+                fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {
+                    dispatch_unique_runtime!(collection.account_balance(account))
+                }
+                fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {
+                    dispatch_unique_runtime!(collection.balance(account, token))
+                }
+                fn allowance(
+                    collection: CollectionId,
+                    sender: CrossAccountId,
+                    spender: CrossAccountId,
+                    token: TokenId,
+                ) -> Result<u128, DispatchError> {
+                    dispatch_unique_runtime!(collection.allowance(sender, spender, token))
+                }
+
+                fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
+                    <pallet_unique::UniqueErcSupport<Runtime>>::get_code(&account)
+                        .or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))
+                        .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
+                }
+                fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
+                    Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))
+                }
+                fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
+                    Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))
+                }
+                fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {
+                    Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))
+                }
+                fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {
+                    dispatch_unique_runtime!(collection.last_token_id())
+                }
+                fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {
+                    Ok(<pallet_common::CollectionById<Runtime>>::get(collection))
+                }
+                fn collection_stats() -> Result<CollectionStats, DispatchError> {
+                    Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
+                }
+            }
+
+            impl sp_api::Core<Block> for Runtime {
+                fn version() -> RuntimeVersion {
+                    VERSION
+                }
+
+                fn execute_block(block: Block) {
+                    Executive::execute_block(block)
+                }
+
+                fn initialize_block(header: &<Block as BlockT>::Header) {
+                    Executive::initialize_block(header)
+                }
+            }
+
+            impl sp_api::Metadata<Block> for Runtime {
+                fn metadata() -> OpaqueMetadata {
+                    OpaqueMetadata::new(Runtime::metadata().into())
+                }
+            }
+
+            impl sp_block_builder::BlockBuilder<Block> for Runtime {
+                fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
+                    Executive::apply_extrinsic(extrinsic)
+                }
+
+                fn finalize_block() -> <Block as BlockT>::Header {
+                    Executive::finalize_block()
+                }
+
+                fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
+                    data.create_extrinsics()
+                }
+
+                fn check_inherents(
+                    block: Block,
+                    data: sp_inherents::InherentData,
+                ) -> sp_inherents::CheckInherentsResult {
+                    data.check_extrinsics(&block)
+                }
+
+                // fn random_seed() -> <Block as BlockT>::Hash {
+                //     RandomnessCollectiveFlip::random_seed().0
+                // }
+            }
+
+            impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
+                fn validate_transaction(
+                    source: TransactionSource,
+                    tx: <Block as BlockT>::Extrinsic,
+                    hash: <Block as BlockT>::Hash,
+                ) -> TransactionValidity {
+                    Executive::validate_transaction(source, tx, hash)
+                }
+            }
+
+            impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
+                fn offchain_worker(header: &<Block as BlockT>::Header) {
+                    Executive::offchain_worker(header)
+                }
+            }
+
+            impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
+                fn chain_id() -> u64 {
+                    <Runtime as pallet_evm::Config>::ChainId::get()
+                }
+
+                fn account_basic(address: H160) -> EVMAccount {
+                    EVM::account_basic(&address)
+                }
+
+                fn gas_price() -> U256 {
+                    <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()
+                }
+
+                fn account_code_at(address: H160) -> Vec<u8> {
+                    EVM::account_codes(address)
+                }
+
+                fn author() -> H160 {
+                    <pallet_evm::Pallet<Runtime>>::find_author()
+                }
+
+                fn storage_at(address: H160, index: U256) -> H256 {
+                    let mut tmp = [0u8; 32];
+                    index.to_big_endian(&mut tmp);
+                    EVM::account_storages(address, H256::from_slice(&tmp[..]))
+                }
+
+                #[allow(clippy::redundant_closure)]
+                fn call(
+                    from: H160,
+                    to: H160,
+                    data: Vec<u8>,
+                    value: U256,
+                    gas_limit: U256,
+                    max_fee_per_gas: Option<U256>,
+                    max_priority_fee_per_gas: Option<U256>,
+                    nonce: Option<U256>,
+                    estimate: bool,
+                    access_list: Option<Vec<(H160, Vec<H256>)>>,
+                ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {
+                    let config = if estimate {
+                        let mut config = <Runtime as pallet_evm::Config>::config().clone();
+                        config.estimate = true;
+                        Some(config)
+                    } else {
+                        None
+                    };
+
+                    <Runtime as pallet_evm::Config>::Runner::call(
+                        from,
+                        to,
+                        data,
+                        value,
+                        gas_limit.low_u64(),
+                        max_fee_per_gas,
+                        max_priority_fee_per_gas,
+                        nonce,
+                        access_list.unwrap_or_default(),
+                        config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
+                    ).map_err(|err| err.into())
+                }
+
+                #[allow(clippy::redundant_closure)]
+                fn create(
+                    from: H160,
+                    data: Vec<u8>,
+                    value: U256,
+                    gas_limit: U256,
+                    max_fee_per_gas: Option<U256>,
+                    max_priority_fee_per_gas: Option<U256>,
+                    nonce: Option<U256>,
+                    estimate: bool,
+                    access_list: Option<Vec<(H160, Vec<H256>)>>,
+                ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {
+                    let config = if estimate {
+                        let mut config = <Runtime as pallet_evm::Config>::config().clone();
+                        config.estimate = true;
+                        Some(config)
+                    } else {
+                        None
+                    };
+
+                    <Runtime as pallet_evm::Config>::Runner::create(
+                        from,
+                        data,
+                        value,
+                        gas_limit.low_u64(),
+                        max_fee_per_gas,
+                        max_priority_fee_per_gas,
+                        nonce,
+                        access_list.unwrap_or_default(),
+                        config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
+                    ).map_err(|err| err.into())
+                }
+
+                fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {
+                    Ethereum::current_transaction_statuses()
+                }
+
+                fn current_block() -> Option<pallet_ethereum::Block> {
+                    Ethereum::current_block()
+                }
+
+                fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {
+                    Ethereum::current_receipts()
+                }
+
+                fn current_all() -> (
+                    Option<pallet_ethereum::Block>,
+                    Option<Vec<pallet_ethereum::Receipt>>,
+                    Option<Vec<TransactionStatus>>
+                ) {
+                    (
+                        Ethereum::current_block(),
+                        Ethereum::current_receipts(),
+                        Ethereum::current_transaction_statuses()
+                    )
+                }
+
+                fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {
+                    xts.into_iter().filter_map(|xt| match xt.0.function {
+                        Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),
+                        _ => None
+                    }).collect()
+                }
+
+                fn elasticity() -> Option<Permill> {
+                    None
+                }
+            }
+
+            impl sp_session::SessionKeys<Block> for Runtime {
+                fn decode_session_keys(
+                    encoded: Vec<u8>,
+                ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
+                    SessionKeys::decode_into_raw_public_keys(&encoded)
+                }
+
+                fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
+                    SessionKeys::generate(seed)
+                }
+            }
+
+            impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
+                fn slot_duration() -> sp_consensus_aura::SlotDuration {
+                    sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
+                }
+
+                fn authorities() -> Vec<AuraId> {
+                    Aura::authorities().to_vec()
+                }
+            }
+
+            impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
+                fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
+                    ParachainSystem::collect_collation_info(header)
+                }
+            }
+
+            impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
+                fn account_nonce(account: AccountId) -> Index {
+                    System::account_nonce(account)
+                }
+            }
+
+            impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
+                fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
+                    TransactionPayment::query_info(uxt, len)
+                }
+                fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
+                    TransactionPayment::query_fee_details(uxt, len)
+                }
+            }
+
+            /*
+            impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>
+                for Runtime
+            {
+                fn call(
+                    origin: AccountId,
+                    dest: AccountId,
+                    value: Balance,
+                    gas_limit: u64,
+                    input_data: Vec<u8>,
+                ) -> pallet_contracts_primitives::ContractExecResult {
+                    Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)
+                }
+
+                fn instantiate(
+                    origin: AccountId,
+                    endowment: Balance,
+                    gas_limit: u64,
+                    code: pallet_contracts_primitives::Code<Hash>,
+                    data: Vec<u8>,
+                    salt: Vec<u8>,
+                ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>
+                {
+                    Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)
+                }
+
+                fn get_storage(
+                    address: AccountId,
+                    key: [u8; 32],
+                ) -> pallet_contracts_primitives::GetStorageResult {
+                    Contracts::get_storage(address, key)
+                }
+
+                fn rent_projection(
+                    address: AccountId,
+                ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
+                    Contracts::rent_projection(address)
+                }
+            }
+            */
+
+            #[cfg(feature = "runtime-benchmarks")]
+            impl frame_benchmarking::Benchmark<Block> for Runtime {
+                fn benchmark_metadata(extra: bool) -> (
+                    Vec<frame_benchmarking::BenchmarkList>,
+                    Vec<frame_support::traits::StorageInfo>,
+                ) {
+                    use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
+                    use frame_support::traits::StorageInfoTrait;
+
+                    let mut list = Vec::<BenchmarkList>::new();
+
+                    list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);
+                    list_benchmark!(list, extra, pallet_unique, Unique);
+                    list_benchmark!(list, extra, pallet_inflation, Inflation);
+                    list_benchmark!(list, extra, pallet_fungible, Fungible);
+                    list_benchmark!(list, extra, pallet_refungible, Refungible);
+                    list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
+                    // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
+
+                    let storage_info = AllPalletsReversedWithSystemFirst::storage_info();
+
+                    return (list, storage_info)
+                }
+
+                fn dispatch_benchmark(
+                    config: frame_benchmarking::BenchmarkConfig
+                ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
+                    use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
+
+                    let allowlist: Vec<TrackedStorageKey> = vec![
+                        // Block Number
+                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
+                        // Total Issuance
+                        hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
+                        // Execution Phase
+                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
+                        // Event Count
+                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
+                        // System Events
+                        hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
+                    ];
+
+                    let mut batches = Vec::<BenchmarkBatch>::new();
+                    let params = (&config, &allowlist);
+
+                    add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
+                    add_benchmark!(params, batches, pallet_unique, Unique);
+                    add_benchmark!(params, batches, pallet_inflation, Inflation);
+                    add_benchmark!(params, batches, pallet_fungible, Fungible);
+                    add_benchmark!(params, batches, pallet_refungible, Refungible);
+                    add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
+                    // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
+
+                    if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
+                    Ok(batches)
+                }
+            }
+        }
+    }
+}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -112,7 +112,7 @@
 //use xcm_executor::traits::MatchesFungible;
 use sp_runtime::traits::CheckedConversion;
 
-use unique_runtime_common::{types::*, constants::*};
+use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
 
 pub const RUNTIME_NAME: &str = "Opal";
 
@@ -1111,404 +1111,8 @@
 		Ok(dispatch.$method($($name),*))
 	}};
 }
-impl_runtime_apis! {
-	impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId>
-		for Runtime
-	{
-		fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {
-			dispatch_unique_runtime!(collection.account_tokens(account))
-		}
-		fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {
-			dispatch_unique_runtime!(collection.token_exists(token))
-		}
 
-		fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {
-			dispatch_unique_runtime!(collection.token_owner(token))
-		}
-		fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
-			dispatch_unique_runtime!(collection.const_metadata(token))
-		}
-		fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
-			dispatch_unique_runtime!(collection.variable_metadata(token))
-		}
-
-		fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {
-			dispatch_unique_runtime!(collection.collection_tokens())
-		}
-		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {
-			dispatch_unique_runtime!(collection.account_balance(account))
-		}
-		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {
-			dispatch_unique_runtime!(collection.balance(account, token))
-		}
-		fn allowance(
-			collection: CollectionId,
-			sender: CrossAccountId,
-			spender: CrossAccountId,
-			token: TokenId,
-		) -> Result<u128, DispatchError> {
-			dispatch_unique_runtime!(collection.allowance(sender, spender, token))
-		}
-
-		fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
-			<pallet_unique::UniqueErcSupport<Runtime>>::get_code(&account)
-				.or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))
-				.or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
-		}
-		fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))
-		}
-		fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))
-		}
-		fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))
-		}
-		fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {
-			dispatch_unique_runtime!(collection.last_token_id())
-		}
-		fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {
-			Ok(<pallet_common::CollectionById<Runtime>>::get(collection))
-		}
-		fn collection_stats() -> Result<CollectionStats, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
-		}
-	}
-
-	impl sp_api::Core<Block> for Runtime {
-		fn version() -> RuntimeVersion {
-			VERSION
-		}
-
-		fn execute_block(block: Block) {
-			Executive::execute_block(block)
-		}
-
-		fn initialize_block(header: &<Block as BlockT>::Header) {
-			Executive::initialize_block(header)
-		}
-	}
-
-	impl sp_api::Metadata<Block> for Runtime {
-		fn metadata() -> OpaqueMetadata {
-			OpaqueMetadata::new(Runtime::metadata().into())
-		}
-	}
-
-	impl sp_block_builder::BlockBuilder<Block> for Runtime {
-		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
-			Executive::apply_extrinsic(extrinsic)
-		}
-
-		fn finalize_block() -> <Block as BlockT>::Header {
-			Executive::finalize_block()
-		}
-
-		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
-			data.create_extrinsics()
-		}
-
-		fn check_inherents(
-			block: Block,
-			data: sp_inherents::InherentData,
-		) -> sp_inherents::CheckInherentsResult {
-			data.check_extrinsics(&block)
-		}
-
-		// fn random_seed() -> <Block as BlockT>::Hash {
-		//     RandomnessCollectiveFlip::random_seed().0
-		// }
-	}
-
-	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
-		fn validate_transaction(
-			source: TransactionSource,
-			tx: <Block as BlockT>::Extrinsic,
-			hash: <Block as BlockT>::Hash,
-		) -> TransactionValidity {
-			Executive::validate_transaction(source, tx, hash)
-		}
-	}
-
-	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
-		fn offchain_worker(header: &<Block as BlockT>::Header) {
-			Executive::offchain_worker(header)
-		}
-	}
-
-	impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
-		fn chain_id() -> u64 {
-			<Runtime as pallet_evm::Config>::ChainId::get()
-		}
-
-		fn account_basic(address: H160) -> EVMAccount {
-			EVM::account_basic(&address)
-		}
-
-		fn gas_price() -> U256 {
-			<Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()
-		}
-
-		fn account_code_at(address: H160) -> Vec<u8> {
-			EVM::account_codes(address)
-		}
-
-		fn author() -> H160 {
-			<pallet_evm::Pallet<Runtime>>::find_author()
-		}
-
-		fn storage_at(address: H160, index: U256) -> H256 {
-			let mut tmp = [0u8; 32];
-			index.to_big_endian(&mut tmp);
-			EVM::account_storages(address, H256::from_slice(&tmp[..]))
-		}
-
-		#[allow(clippy::redundant_closure)]
-		fn call(
-			from: H160,
-			to: H160,
-			data: Vec<u8>,
-			value: U256,
-			gas_limit: U256,
-			max_fee_per_gas: Option<U256>,
-			max_priority_fee_per_gas: Option<U256>,
-			nonce: Option<U256>,
-			estimate: bool,
-			access_list: Option<Vec<(H160, Vec<H256>)>>,
-		) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {
-			let config = if estimate {
-				let mut config = <Runtime as pallet_evm::Config>::config().clone();
-				config.estimate = true;
-				Some(config)
-			} else {
-				None
-			};
-
-			<Runtime as pallet_evm::Config>::Runner::call(
-				from,
-				to,
-				data,
-				value,
-				gas_limit.low_u64(),
-				max_fee_per_gas,
-				max_priority_fee_per_gas,
-				nonce,
-				access_list.unwrap_or_default(),
-				config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
-			).map_err(|err| err.into())
-		}
-
-		#[allow(clippy::redundant_closure)]
-		fn create(
-			from: H160,
-			data: Vec<u8>,
-			value: U256,
-			gas_limit: U256,
-			max_fee_per_gas: Option<U256>,
-			max_priority_fee_per_gas: Option<U256>,
-			nonce: Option<U256>,
-			estimate: bool,
-			access_list: Option<Vec<(H160, Vec<H256>)>>,
-		) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {
-			let config = if estimate {
-				let mut config = <Runtime as pallet_evm::Config>::config().clone();
-				config.estimate = true;
-				Some(config)
-			} else {
-				None
-			};
-
-			<Runtime as pallet_evm::Config>::Runner::create(
-				from,
-				data,
-				value,
-				gas_limit.low_u64(),
-				max_fee_per_gas,
-				max_priority_fee_per_gas,
-				nonce,
-				access_list.unwrap_or_default(),
-				config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
-			).map_err(|err| err.into())
-		}
-
-		fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {
-			Ethereum::current_transaction_statuses()
-		}
-
-		fn current_block() -> Option<pallet_ethereum::Block> {
-			Ethereum::current_block()
-		}
-
-		fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {
-			Ethereum::current_receipts()
-		}
-
-		fn current_all() -> (
-			Option<pallet_ethereum::Block>,
-			Option<Vec<pallet_ethereum::Receipt>>,
-			Option<Vec<TransactionStatus>>
-		) {
-			(
-				Ethereum::current_block(),
-				Ethereum::current_receipts(),
-				Ethereum::current_transaction_statuses()
-			)
-		}
-
-		fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {
-			xts.into_iter().filter_map(|xt| match xt.0.function {
-				Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),
-				_ => None
-			}).collect()
-		}
-
-		fn elasticity() -> Option<Permill> {
-			None
-		}
-	}
-
-	impl sp_session::SessionKeys<Block> for Runtime {
-		fn decode_session_keys(
-			encoded: Vec<u8>,
-		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
-			SessionKeys::decode_into_raw_public_keys(&encoded)
-		}
-
-		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
-			SessionKeys::generate(seed)
-		}
-	}
-
-	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
-		fn slot_duration() -> sp_consensus_aura::SlotDuration {
-			sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
-		}
-
-		fn authorities() -> Vec<AuraId> {
-			Aura::authorities().to_vec()
-		}
-	}
-
-	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
-		fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
-			ParachainSystem::collect_collation_info(header)
-		}
-	}
-
-	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
-		fn account_nonce(account: AccountId) -> Index {
-			System::account_nonce(account)
-		}
-	}
-
-	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
-		fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
-			TransactionPayment::query_info(uxt, len)
-		}
-		fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
-			TransactionPayment::query_fee_details(uxt, len)
-		}
-	}
-
-	/*
-	impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>
-		for Runtime
-	{
-		fn call(
-			origin: AccountId,
-			dest: AccountId,
-			value: Balance,
-			gas_limit: u64,
-			input_data: Vec<u8>,
-		) -> pallet_contracts_primitives::ContractExecResult {
-			Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)
-		}
-
-		fn instantiate(
-			origin: AccountId,
-			endowment: Balance,
-			gas_limit: u64,
-			code: pallet_contracts_primitives::Code<Hash>,
-			data: Vec<u8>,
-			salt: Vec<u8>,
-		) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>
-		{
-			Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)
-		}
-
-		fn get_storage(
-			address: AccountId,
-			key: [u8; 32],
-		) -> pallet_contracts_primitives::GetStorageResult {
-			Contracts::get_storage(address, key)
-		}
-
-		fn rent_projection(
-			address: AccountId,
-		) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
-			Contracts::rent_projection(address)
-		}
-	}
-	*/
-
-	#[cfg(feature = "runtime-benchmarks")]
-	impl frame_benchmarking::Benchmark<Block> for Runtime {
-		fn benchmark_metadata(extra: bool) -> (
-			Vec<frame_benchmarking::BenchmarkList>,
-			Vec<frame_support::traits::StorageInfo>,
-		) {
-			use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
-			use frame_support::traits::StorageInfoTrait;
-
-			let mut list = Vec::<BenchmarkList>::new();
-
-			list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);
-			list_benchmark!(list, extra, pallet_unique, Unique);
-			list_benchmark!(list, extra, pallet_inflation, Inflation);
-			list_benchmark!(list, extra, pallet_fungible, Fungible);
-			list_benchmark!(list, extra, pallet_refungible, Refungible);
-			list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
-			// list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
-
-			let storage_info = AllPalletsReversedWithSystemFirst::storage_info();
-
-			return (list, storage_info)
-		}
-
-		fn dispatch_benchmark(
-			config: frame_benchmarking::BenchmarkConfig
-		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
-			use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
-
-			let allowlist: Vec<TrackedStorageKey> = vec![
-				// Block Number
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
-				// Total Issuance
-				hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
-				// Execution Phase
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
-				// Event Count
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
-				// System Events
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
-			];
-
-			let mut batches = Vec::<BenchmarkBatch>::new();
-			let params = (&config, &allowlist);
-
-			add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
-			add_benchmark!(params, batches, pallet_unique, Unique);
-			add_benchmark!(params, batches, pallet_inflation, Inflation);
-			add_benchmark!(params, batches, pallet_fungible, Fungible);
-			add_benchmark!(params, batches, pallet_refungible, Refungible);
-			add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
-			// add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
-
-			if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
-			Ok(batches)
-		}
-	}
-}
+impl_common_runtime_apis!();
 
 struct CheckInherents;
 
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -112,7 +112,7 @@
 //use xcm_executor::traits::MatchesFungible;
 use sp_runtime::traits::CheckedConversion;
 
-use unique_runtime_common::{types::*, constants::*};
+use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
 
 pub const RUNTIME_NAME: &str = "Quartz";
 
@@ -1115,404 +1115,8 @@
 		Ok(dispatch.$method($($name),*))
 	}};
 }
-impl_runtime_apis! {
-	impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId>
-		for Runtime
-	{
-		fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {
-			dispatch_unique_runtime!(collection.account_tokens(account))
-		}
-		fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {
-			dispatch_unique_runtime!(collection.token_exists(token))
-		}
 
-		fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {
-			dispatch_unique_runtime!(collection.token_owner(token))
-		}
-		fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
-			dispatch_unique_runtime!(collection.const_metadata(token))
-		}
-		fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
-			dispatch_unique_runtime!(collection.variable_metadata(token))
-		}
-
-		fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {
-			dispatch_unique_runtime!(collection.collection_tokens())
-		}
-		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {
-			dispatch_unique_runtime!(collection.account_balance(account))
-		}
-		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {
-			dispatch_unique_runtime!(collection.balance(account, token))
-		}
-		fn allowance(
-			collection: CollectionId,
-			sender: CrossAccountId,
-			spender: CrossAccountId,
-			token: TokenId,
-		) -> Result<u128, DispatchError> {
-			dispatch_unique_runtime!(collection.allowance(sender, spender, token))
-		}
-
-		fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
-			<pallet_unique::UniqueErcSupport<Runtime>>::get_code(&account)
-				.or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))
-				.or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
-		}
-		fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))
-		}
-		fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))
-		}
-		fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))
-		}
-		fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {
-			dispatch_unique_runtime!(collection.last_token_id())
-		}
-		fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {
-			Ok(<pallet_common::CollectionById<Runtime>>::get(collection))
-		}
-		fn collection_stats() -> Result<CollectionStats, DispatchError> {
-			Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
-		}
-	}
-
-	impl sp_api::Core<Block> for Runtime {
-		fn version() -> RuntimeVersion {
-			VERSION
-		}
-
-		fn execute_block(block: Block) {
-			Executive::execute_block(block)
-		}
-
-		fn initialize_block(header: &<Block as BlockT>::Header) {
-			Executive::initialize_block(header)
-		}
-	}
-
-	impl sp_api::Metadata<Block> for Runtime {
-		fn metadata() -> OpaqueMetadata {
-			OpaqueMetadata::new(Runtime::metadata().into())
-		}
-	}
-
-	impl sp_block_builder::BlockBuilder<Block> for Runtime {
-		fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
-			Executive::apply_extrinsic(extrinsic)
-		}
-
-		fn finalize_block() -> <Block as BlockT>::Header {
-			Executive::finalize_block()
-		}
-
-		fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
-			data.create_extrinsics()
-		}
-
-		fn check_inherents(
-			block: Block,
-			data: sp_inherents::InherentData,
-		) -> sp_inherents::CheckInherentsResult {
-			data.check_extrinsics(&block)
-		}
-
-		// fn random_seed() -> <Block as BlockT>::Hash {
-		//     RandomnessCollectiveFlip::random_seed().0
-		// }
-	}
-
-	impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
-		fn validate_transaction(
-			source: TransactionSource,
-			tx: <Block as BlockT>::Extrinsic,
-			hash: <Block as BlockT>::Hash,
-		) -> TransactionValidity {
-			Executive::validate_transaction(source, tx, hash)
-		}
-	}
-
-	impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
-		fn offchain_worker(header: &<Block as BlockT>::Header) {
-			Executive::offchain_worker(header)
-		}
-	}
-
-	impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
-		fn chain_id() -> u64 {
-			<Runtime as pallet_evm::Config>::ChainId::get()
-		}
-
-		fn account_basic(address: H160) -> EVMAccount {
-			EVM::account_basic(&address)
-		}
-
-		fn gas_price() -> U256 {
-			<Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()
-		}
-
-		fn account_code_at(address: H160) -> Vec<u8> {
-			EVM::account_codes(address)
-		}
-
-		fn author() -> H160 {
-			<pallet_evm::Pallet<Runtime>>::find_author()
-		}
-
-		fn storage_at(address: H160, index: U256) -> H256 {
-			let mut tmp = [0u8; 32];
-			index.to_big_endian(&mut tmp);
-			EVM::account_storages(address, H256::from_slice(&tmp[..]))
-		}
-
-		#[allow(clippy::redundant_closure)]
-		fn call(
-			from: H160,
-			to: H160,
-			data: Vec<u8>,
-			value: U256,
-			gas_limit: U256,
-			max_fee_per_gas: Option<U256>,
-			max_priority_fee_per_gas: Option<U256>,
-			nonce: Option<U256>,
-			estimate: bool,
-			access_list: Option<Vec<(H160, Vec<H256>)>>,
-		) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {
-			let config = if estimate {
-				let mut config = <Runtime as pallet_evm::Config>::config().clone();
-				config.estimate = true;
-				Some(config)
-			} else {
-				None
-			};
-
-			<Runtime as pallet_evm::Config>::Runner::call(
-				from,
-				to,
-				data,
-				value,
-				gas_limit.low_u64(),
-				max_fee_per_gas,
-				max_priority_fee_per_gas,
-				nonce,
-				access_list.unwrap_or_default(),
-				config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
-			).map_err(|err| err.into())
-		}
-
-		#[allow(clippy::redundant_closure)]
-		fn create(
-			from: H160,
-			data: Vec<u8>,
-			value: U256,
-			gas_limit: U256,
-			max_fee_per_gas: Option<U256>,
-			max_priority_fee_per_gas: Option<U256>,
-			nonce: Option<U256>,
-			estimate: bool,
-			access_list: Option<Vec<(H160, Vec<H256>)>>,
-		) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {
-			let config = if estimate {
-				let mut config = <Runtime as pallet_evm::Config>::config().clone();
-				config.estimate = true;
-				Some(config)
-			} else {
-				None
-			};
-
-			<Runtime as pallet_evm::Config>::Runner::create(
-				from,
-				data,
-				value,
-				gas_limit.low_u64(),
-				max_fee_per_gas,
-				max_priority_fee_per_gas,
-				nonce,
-				access_list.unwrap_or_default(),
-				config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
-			).map_err(|err| err.into())
-		}
-
-		fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {
-			Ethereum::current_transaction_statuses()
-		}
-
-		fn current_block() -> Option<pallet_ethereum::Block> {
-			Ethereum::current_block()
-		}
-
-		fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {
-			Ethereum::current_receipts()
-		}
-
-		fn current_all() -> (
-			Option<pallet_ethereum::Block>,
-			Option<Vec<pallet_ethereum::Receipt>>,
-			Option<Vec<TransactionStatus>>
-		) {
-			(
-				Ethereum::current_block(),
-				Ethereum::current_receipts(),
-				Ethereum::current_transaction_statuses()
-			)
-		}
-
-		fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {
-			xts.into_iter().filter_map(|xt| match xt.0.function {
-				Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),
-				_ => None
-			}).collect()
-		}
-
-		fn elasticity() -> Option<Permill> {
-			None
-		}
-	}
-
-	impl sp_session::SessionKeys<Block> for Runtime {
-		fn decode_session_keys(
-			encoded: Vec<u8>,
-		) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
-			SessionKeys::decode_into_raw_public_keys(&encoded)
-		}
-
-		fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
-			SessionKeys::generate(seed)
-		}
-	}
-
-	impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
-		fn slot_duration() -> sp_consensus_aura::SlotDuration {
-			sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
-		}
-
-		fn authorities() -> Vec<AuraId> {
-			Aura::authorities().to_vec()
-		}
-	}
-
-	impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
-		fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
-			ParachainSystem::collect_collation_info(header)
-		}
-	}
-
-	impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
-		fn account_nonce(account: AccountId) -> Index {
-			System::account_nonce(account)
-		}
-	}
-
-	impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
-		fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
-			TransactionPayment::query_info(uxt, len)
-		}
-		fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
-			TransactionPayment::query_fee_details(uxt, len)
-		}
-	}
-
-	/*
-	impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>
-		for Runtime
-	{
-		fn call(
-			origin: AccountId,
-			dest: AccountId,
-			value: Balance,
-			gas_limit: u64,
-			input_data: Vec<u8>,
-		) -> pallet_contracts_primitives::ContractExecResult {
-			Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)
-		}
-
-		fn instantiate(
-			origin: AccountId,
-			endowment: Balance,
-			gas_limit: u64,
-			code: pallet_contracts_primitives::Code<Hash>,
-			data: Vec<u8>,
-			salt: Vec<u8>,
-		) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>
-		{
-			Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)
-		}
-
-		fn get_storage(
-			address: AccountId,
-			key: [u8; 32],
-		) -> pallet_contracts_primitives::GetStorageResult {
-			Contracts::get_storage(address, key)
-		}
-
-		fn rent_projection(
-			address: AccountId,
-		) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
-			Contracts::rent_projection(address)
-		}
-	}
-	*/
-
-	#[cfg(feature = "runtime-benchmarks")]
-	impl frame_benchmarking::Benchmark<Block> for Runtime {
-		fn benchmark_metadata(extra: bool) -> (
-			Vec<frame_benchmarking::BenchmarkList>,
-			Vec<frame_support::traits::StorageInfo>,
-		) {
-			use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
-			use frame_support::traits::StorageInfoTrait;
-
-			let mut list = Vec::<BenchmarkList>::new();
-
-			list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);
-			list_benchmark!(list, extra, pallet_unique, Unique);
-			list_benchmark!(list, extra, pallet_inflation, Inflation);
-			list_benchmark!(list, extra, pallet_fungible, Fungible);
-			list_benchmark!(list, extra, pallet_refungible, Refungible);
-			list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
-			// list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
-
-			let storage_info = AllPalletsReversedWithSystemFirst::storage_info();
-
-			return (list, storage_info)
-		}
-
-		fn dispatch_benchmark(
-			config: frame_benchmarking::BenchmarkConfig
-		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
-			use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
-
-			let allowlist: Vec<TrackedStorageKey> = vec![
-				// Block Number
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
-				// Total Issuance
-				hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
-				// Execution Phase
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
-				// Event Count
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
-				// System Events
-				hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
-			];
-
-			let mut batches = Vec::<BenchmarkBatch>::new();
-			let params = (&config, &allowlist);
-
-			add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
-			add_benchmark!(params, batches, pallet_unique, Unique);
-			add_benchmark!(params, batches, pallet_inflation, Inflation);
-			add_benchmark!(params, batches, pallet_fungible, Fungible);
-			add_benchmark!(params, batches, pallet_refungible, Refungible);
-			add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
-			// add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
-
-			if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
-			Ok(batches)
-		}
-	}
-}
+impl_common_runtime_apis!();
 
 struct CheckInherents;
 
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
112//use xcm_executor::traits::MatchesFungible;112//use xcm_executor::traits::MatchesFungible;
113use sp_runtime::traits::CheckedConversion;113use sp_runtime::traits::CheckedConversion;
114114
115use unique_runtime_common::{types::*, constants::*};115use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
116116
117pub const RUNTIME_NAME: &str = "Unique";117pub const RUNTIME_NAME: &str = "Unique";
118118
1117 }};1117 }};
1118}1118}
1119
1119impl_runtime_apis! {1120impl_common_runtime_apis!();
1120 impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId>
1121 for Runtime
1122 {
1123 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {
1124 dispatch_unique_runtime!(collection.account_tokens(account))
1125 }
1126 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {
1127 dispatch_unique_runtime!(collection.token_exists(token))
1128 }
1129
1130 fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {
1131 dispatch_unique_runtime!(collection.token_owner(token))
1132 }
1133 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
1134 dispatch_unique_runtime!(collection.const_metadata(token))
1135 }
1136 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {
1137 dispatch_unique_runtime!(collection.variable_metadata(token))
1138 }
1139
1140 fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {
1141 dispatch_unique_runtime!(collection.collection_tokens())
1142 }
1143 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {
1144 dispatch_unique_runtime!(collection.account_balance(account))
1145 }
1146 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {
1147 dispatch_unique_runtime!(collection.balance(account, token))
1148 }
1149 fn allowance(
1150 collection: CollectionId,
1151 sender: CrossAccountId,
1152 spender: CrossAccountId,
1153 token: TokenId,
1154 ) -> Result<u128, DispatchError> {
1155 dispatch_unique_runtime!(collection.allowance(sender, spender, token))
1156 }
1157
1158 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
1159 <pallet_unique::UniqueErcSupport<Runtime>>::get_code(&account)
1160 .or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))
1161 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
1162 }
1163 fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
1164 Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))
1165 }
1166 fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {
1167 Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))
1168 }
1169 fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {
1170 Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))
1171 }
1172 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {
1173 dispatch_unique_runtime!(collection.last_token_id())
1174 }
1175 fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {
1176 Ok(<pallet_common::CollectionById<Runtime>>::get(collection))
1177 }
1178 fn collection_stats() -> Result<CollectionStats, DispatchError> {
1179 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
1180 }
1181 }
1182
1183 impl sp_api::Core<Block> for Runtime {
1184 fn version() -> RuntimeVersion {
1185 VERSION
1186 }
1187
1188 fn execute_block(block: Block) {
1189 Executive::execute_block(block)
1190 }
1191
1192 fn initialize_block(header: &<Block as BlockT>::Header) {
1193 Executive::initialize_block(header)
1194 }
1195 }
1196
1197 impl sp_api::Metadata<Block> for Runtime {
1198 fn metadata() -> OpaqueMetadata {
1199 OpaqueMetadata::new(Runtime::metadata().into())
1200 }
1201 }
1202
1203 impl sp_block_builder::BlockBuilder<Block> for Runtime {
1204 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
1205 Executive::apply_extrinsic(extrinsic)
1206 }
1207
1208 fn finalize_block() -> <Block as BlockT>::Header {
1209 Executive::finalize_block()
1210 }
1211
1212 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
1213 data.create_extrinsics()
1214 }
1215
1216 fn check_inherents(
1217 block: Block,
1218 data: sp_inherents::InherentData,
1219 ) -> sp_inherents::CheckInherentsResult {
1220 data.check_extrinsics(&block)
1221 }
1222
1223 // fn random_seed() -> <Block as BlockT>::Hash {
1224 // RandomnessCollectiveFlip::random_seed().0
1225 // }
1226 }
1227
1228 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
1229 fn validate_transaction(
1230 source: TransactionSource,
1231 tx: <Block as BlockT>::Extrinsic,
1232 hash: <Block as BlockT>::Hash,
1233 ) -> TransactionValidity {
1234 Executive::validate_transaction(source, tx, hash)
1235 }
1236 }
1237
1238 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
1239 fn offchain_worker(header: &<Block as BlockT>::Header) {
1240 Executive::offchain_worker(header)
1241 }
1242 }
1243
1244 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
1245 fn chain_id() -> u64 {
1246 <Runtime as pallet_evm::Config>::ChainId::get()
1247 }
1248
1249 fn account_basic(address: H160) -> EVMAccount {
1250 EVM::account_basic(&address)
1251 }
1252
1253 fn gas_price() -> U256 {
1254 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()
1255 }
1256
1257 fn account_code_at(address: H160) -> Vec<u8> {
1258 EVM::account_codes(address)
1259 }
1260
1261 fn author() -> H160 {
1262 <pallet_evm::Pallet<Runtime>>::find_author()
1263 }
1264
1265 fn storage_at(address: H160, index: U256) -> H256 {
1266 let mut tmp = [0u8; 32];
1267 index.to_big_endian(&mut tmp);
1268 EVM::account_storages(address, H256::from_slice(&tmp[..]))
1269 }
1270
1271 #[allow(clippy::redundant_closure)]
1272 fn call(
1273 from: H160,
1274 to: H160,
1275 data: Vec<u8>,
1276 value: U256,
1277 gas_limit: U256,
1278 max_fee_per_gas: Option<U256>,
1279 max_priority_fee_per_gas: Option<U256>,
1280 nonce: Option<U256>,
1281 estimate: bool,
1282 access_list: Option<Vec<(H160, Vec<H256>)>>,
1283 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {
1284 let config = if estimate {
1285 let mut config = <Runtime as pallet_evm::Config>::config().clone();
1286 config.estimate = true;
1287 Some(config)
1288 } else {
1289 None
1290 };
1291
1292 <Runtime as pallet_evm::Config>::Runner::call(
1293 from,
1294 to,
1295 data,
1296 value,
1297 gas_limit.low_u64(),
1298 max_fee_per_gas,
1299 max_priority_fee_per_gas,
1300 nonce,
1301 access_list.unwrap_or_default(),
1302 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
1303 ).map_err(|err| err.into())
1304 }
1305
1306 #[allow(clippy::redundant_closure)]
1307 fn create(
1308 from: H160,
1309 data: Vec<u8>,
1310 value: U256,
1311 gas_limit: U256,
1312 max_fee_per_gas: Option<U256>,
1313 max_priority_fee_per_gas: Option<U256>,
1314 nonce: Option<U256>,
1315 estimate: bool,
1316 access_list: Option<Vec<(H160, Vec<H256>)>>,
1317 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {
1318 let config = if estimate {
1319 let mut config = <Runtime as pallet_evm::Config>::config().clone();
1320 config.estimate = true;
1321 Some(config)
1322 } else {
1323 None
1324 };
1325
1326 <Runtime as pallet_evm::Config>::Runner::create(
1327 from,
1328 data,
1329 value,
1330 gas_limit.low_u64(),
1331 max_fee_per_gas,
1332 max_priority_fee_per_gas,
1333 nonce,
1334 access_list.unwrap_or_default(),
1335 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
1336 ).map_err(|err| err.into())
1337 }
1338
1339 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {
1340 Ethereum::current_transaction_statuses()
1341 }
1342
1343 fn current_block() -> Option<pallet_ethereum::Block> {
1344 Ethereum::current_block()
1345 }
1346
1347 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {
1348 Ethereum::current_receipts()
1349 }
1350
1351 fn current_all() -> (
1352 Option<pallet_ethereum::Block>,
1353 Option<Vec<pallet_ethereum::Receipt>>,
1354 Option<Vec<TransactionStatus>>
1355 ) {
1356 (
1357 Ethereum::current_block(),
1358 Ethereum::current_receipts(),
1359 Ethereum::current_transaction_statuses()
1360 )
1361 }
1362
1363 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {
1364 xts.into_iter().filter_map(|xt| match xt.0.function {
1365 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),
1366 _ => None
1367 }).collect()
1368 }
1369
1370 fn elasticity() -> Option<Permill> {
1371 None
1372 }
1373 }
1374
1375 impl sp_session::SessionKeys<Block> for Runtime {
1376 fn decode_session_keys(
1377 encoded: Vec<u8>,
1378 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
1379 SessionKeys::decode_into_raw_public_keys(&encoded)
1380 }
1381
1382 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
1383 SessionKeys::generate(seed)
1384 }
1385 }
1386
1387 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
1388 fn slot_duration() -> sp_consensus_aura::SlotDuration {
1389 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())
1390 }
1391
1392 fn authorities() -> Vec<AuraId> {
1393 Aura::authorities().to_vec()
1394 }
1395 }
1396
1397 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {
1398 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {
1399 ParachainSystem::collect_collation_info(header)
1400 }
1401 }
1402
1403 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
1404 fn account_nonce(account: AccountId) -> Index {
1405 System::account_nonce(account)
1406 }
1407 }
1408
1409 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {
1410 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {
1411 TransactionPayment::query_info(uxt, len)
1412 }
1413 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
1414 TransactionPayment::query_fee_details(uxt, len)
1415 }
1416 }
1417
1418 /*
1419 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>
1420 for Runtime
1421 {
1422 fn call(
1423 origin: AccountId,
1424 dest: AccountId,
1425 value: Balance,
1426 gas_limit: u64,
1427 input_data: Vec<u8>,
1428 ) -> pallet_contracts_primitives::ContractExecResult {
1429 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)
1430 }
1431
1432 fn instantiate(
1433 origin: AccountId,
1434 endowment: Balance,
1435 gas_limit: u64,
1436 code: pallet_contracts_primitives::Code<Hash>,
1437 data: Vec<u8>,
1438 salt: Vec<u8>,
1439 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>
1440 {
1441 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)
1442 }
1443
1444 fn get_storage(
1445 address: AccountId,
1446 key: [u8; 32],
1447 ) -> pallet_contracts_primitives::GetStorageResult {
1448 Contracts::get_storage(address, key)
1449 }
1450
1451 fn rent_projection(
1452 address: AccountId,
1453 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {
1454 Contracts::rent_projection(address)
1455 }
1456 }
1457 */
1458
1459 #[cfg(feature = "runtime-benchmarks")]
1460 impl frame_benchmarking::Benchmark<Block> for Runtime {
1461 fn benchmark_metadata(extra: bool) -> (
1462 Vec<frame_benchmarking::BenchmarkList>,
1463 Vec<frame_support::traits::StorageInfo>,
1464 ) {
1465 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
1466 use frame_support::traits::StorageInfoTrait;
1467
1468 let mut list = Vec::<BenchmarkList>::new();
1469
1470 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);
1471 list_benchmark!(list, extra, pallet_unique, Unique);
1472 list_benchmark!(list, extra, pallet_inflation, Inflation);
1473 list_benchmark!(list, extra, pallet_fungible, Fungible);
1474 list_benchmark!(list, extra, pallet_refungible, Refungible);
1475 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);
1476 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);
1477
1478 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();
1479
1480 return (list, storage_info)
1481 }
1482
1483 fn dispatch_benchmark(
1484 config: frame_benchmarking::BenchmarkConfig
1485 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
1486 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
1487
1488 let allowlist: Vec<TrackedStorageKey> = vec![
1489 // Block Number
1490 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
1491 // Total Issuance
1492 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
1493 // Execution Phase
1494 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
1495 // Event Count
1496 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
1497 // System Events
1498 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
1499 ];
1500
1501 let mut batches = Vec::<BenchmarkBatch>::new();
1502 let params = (&config, &allowlist);
1503
1504 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);
1505 add_benchmark!(params, batches, pallet_unique, Unique);
1506 add_benchmark!(params, batches, pallet_inflation, Inflation);
1507 add_benchmark!(params, batches, pallet_fungible, Fungible);
1508 add_benchmark!(params, batches, pallet_refungible, Refungible);
1509 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);
1510 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);
1511
1512 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1513 Ok(batches)
1514 }
1515 }
1516}
15171121
1518struct CheckInherents;1122struct CheckInherents;
15191123