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