difftreelog
Fix style
in: master
2 files changed
pallets/unique/src/sponsorship.rsdiffbeforeafterboth--- a/pallets/unique/src/sponsorship.rs
+++ b/pallets/unique/src/sponsorship.rs
@@ -365,16 +365,5 @@
} else {
None
}
-
- // // existance check
- // match collection.mode {
- // CollectionMode::NFT => <NftTransferBasket<T>>::get(collection.id, token),
- // CollectionMode::Fungible(_) => {
- // <FungibleTransferBasket<T>>::get(collection.id, who.as_sub())
- // }
- // CollectionMode::ReFungible => {
- // <ReFungibleTransferBasket<T>>::get((collection.id, token, who.as_sub()))
- // }
- // };
}
}
runtime/common/src/runtime_apis.rsdiffbeforeafterboth1#[macro_export]2macro_rules! impl_common_runtime_apis {3 (4 $(5 #![custom_apis]67 $($custom_apis:tt)+8 )?9 ) => {10 impl_runtime_apis! {11 $($($custom_apis)+)?1213 impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {14 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {15 dispatch_unique_runtime!(collection.account_tokens(account))16 }17 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {18 dispatch_unique_runtime!(collection.token_exists(token))19 }2021 fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {22 dispatch_unique_runtime!(collection.token_owner(token))23 }24 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {25 dispatch_unique_runtime!(collection.const_metadata(token))26 }27 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {28 dispatch_unique_runtime!(collection.variable_metadata(token))29 }3031 fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {32 dispatch_unique_runtime!(collection.collection_tokens())33 }34 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {35 dispatch_unique_runtime!(collection.account_balance(account))36 }37 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {38 dispatch_unique_runtime!(collection.balance(account, token))39 }40 fn allowance(41 collection: CollectionId,42 sender: CrossAccountId,43 spender: CrossAccountId,44 token: TokenId,45 ) -> Result<u128, DispatchError> {46 dispatch_unique_runtime!(collection.allowance(sender, spender, token))47 }4849 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {50 <pallet_unique::UniqueErcSupport<Runtime>>::get_code(&account)51 .or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))52 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))53 }54 fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {55 Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))56 }57 fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {58 Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))59 }60 fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {61 Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))62 }63 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {64 dispatch_unique_runtime!(collection.last_token_id())65 }66 fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {67 Ok(<pallet_common::CollectionById<Runtime>>::get(collection))68 }69 fn collection_stats() -> Result<CollectionStats, DispatchError> {70 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())71 }72 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {73 Ok(<pallet_unique::UniqueSponsorshipPredict<Runtime> as74 pallet_unique::SponsorshipPredict<Runtime>>::predict(75 collection,76 account,77 token))7879 fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {80 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))81 }82 }8384 impl sp_api::Core<Block> for Runtime {85 fn version() -> RuntimeVersion {86 VERSION87 }8889 fn execute_block(block: Block) {90 Executive::execute_block(block)91 }9293 fn initialize_block(header: &<Block as BlockT>::Header) {94 Executive::initialize_block(header)95 }96 }9798 impl sp_api::Metadata<Block> for Runtime {99 fn metadata() -> OpaqueMetadata {100 OpaqueMetadata::new(Runtime::metadata().into())101 }102 }103104 impl sp_block_builder::BlockBuilder<Block> for Runtime {105 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {106 Executive::apply_extrinsic(extrinsic)107 }108109 fn finalize_block() -> <Block as BlockT>::Header {110 Executive::finalize_block()111 }112113 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {114 data.create_extrinsics()115 }116117 fn check_inherents(118 block: Block,119 data: sp_inherents::InherentData,120 ) -> sp_inherents::CheckInherentsResult {121 data.check_extrinsics(&block)122 }123124 // fn random_seed() -> <Block as BlockT>::Hash {125 // RandomnessCollectiveFlip::random_seed().0126 // }127 }128129 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {130 fn validate_transaction(131 source: TransactionSource,132 tx: <Block as BlockT>::Extrinsic,133 hash: <Block as BlockT>::Hash,134 ) -> TransactionValidity {135 Executive::validate_transaction(source, tx, hash)136 }137 }138139 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {140 fn offchain_worker(header: &<Block as BlockT>::Header) {141 Executive::offchain_worker(header)142 }143 }144145 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {146 fn chain_id() -> u64 {147 <Runtime as pallet_evm::Config>::ChainId::get()148 }149150 fn account_basic(address: H160) -> EVMAccount {151 EVM::account_basic(&address)152 }153154 fn gas_price() -> U256 {155 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()156 }157158 fn account_code_at(address: H160) -> Vec<u8> {159 EVM::account_codes(address)160 }161162 fn author() -> H160 {163 <pallet_evm::Pallet<Runtime>>::find_author()164 }165166 fn storage_at(address: H160, index: U256) -> H256 {167 let mut tmp = [0u8; 32];168 index.to_big_endian(&mut tmp);169 EVM::account_storages(address, H256::from_slice(&tmp[..]))170 }171172 #[allow(clippy::redundant_closure)]173 fn call(174 from: H160,175 to: H160,176 data: Vec<u8>,177 value: U256,178 gas_limit: U256,179 max_fee_per_gas: Option<U256>,180 max_priority_fee_per_gas: Option<U256>,181 nonce: Option<U256>,182 estimate: bool,183 access_list: Option<Vec<(H160, Vec<H256>)>>,184 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {185 let config = if estimate {186 let mut config = <Runtime as pallet_evm::Config>::config().clone();187 config.estimate = true;188 Some(config)189 } else {190 None191 };192193 <Runtime as pallet_evm::Config>::Runner::call(194 CrossAccountId::from_eth(from),195 to,196 data,197 value,198 gas_limit.low_u64(),199 max_fee_per_gas,200 max_priority_fee_per_gas,201 nonce,202 access_list.unwrap_or_default(),203 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),204 ).map_err(|err| err.into())205 }206207 #[allow(clippy::redundant_closure)]208 fn create(209 from: H160,210 data: Vec<u8>,211 value: U256,212 gas_limit: U256,213 max_fee_per_gas: Option<U256>,214 max_priority_fee_per_gas: Option<U256>,215 nonce: Option<U256>,216 estimate: bool,217 access_list: Option<Vec<(H160, Vec<H256>)>>,218 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {219 let config = if estimate {220 let mut config = <Runtime as pallet_evm::Config>::config().clone();221 config.estimate = true;222 Some(config)223 } else {224 None225 };226227 <Runtime as pallet_evm::Config>::Runner::create(228 CrossAccountId::from_eth(from),229 data,230 value,231 gas_limit.low_u64(),232 max_fee_per_gas,233 max_priority_fee_per_gas,234 nonce,235 access_list.unwrap_or_default(),236 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),237 ).map_err(|err| err.into())238 }239240 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {241 Ethereum::current_transaction_statuses()242 }243244 fn current_block() -> Option<pallet_ethereum::Block> {245 Ethereum::current_block()246 }247248 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {249 Ethereum::current_receipts()250 }251252 fn current_all() -> (253 Option<pallet_ethereum::Block>,254 Option<Vec<pallet_ethereum::Receipt>>,255 Option<Vec<TransactionStatus>>256 ) {257 (258 Ethereum::current_block(),259 Ethereum::current_receipts(),260 Ethereum::current_transaction_statuses()261 )262 }263264 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {265 xts.into_iter().filter_map(|xt| match xt.0.function {266 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),267 _ => None268 }).collect()269 }270271 fn elasticity() -> Option<Permill> {272 None273 }274 }275276 impl sp_session::SessionKeys<Block> for Runtime {277 fn decode_session_keys(278 encoded: Vec<u8>,279 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {280 SessionKeys::decode_into_raw_public_keys(&encoded)281 }282283 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {284 SessionKeys::generate(seed)285 }286 }287288 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {289 fn slot_duration() -> sp_consensus_aura::SlotDuration {290 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())291 }292293 fn authorities() -> Vec<AuraId> {294 Aura::authorities().to_vec()295 }296 }297298 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {299 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {300 ParachainSystem::collect_collation_info(header)301 }302 }303304 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {305 fn account_nonce(account: AccountId) -> Index {306 System::account_nonce(account)307 }308 }309310 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {311 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {312 TransactionPayment::query_info(uxt, len)313 }314 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {315 TransactionPayment::query_fee_details(uxt, len)316 }317 }318319 /*320 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>321 for Runtime322 {323 fn call(324 origin: AccountId,325 dest: AccountId,326 value: Balance,327 gas_limit: u64,328 input_data: Vec<u8>,329 ) -> pallet_contracts_primitives::ContractExecResult {330 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)331 }332333 fn instantiate(334 origin: AccountId,335 endowment: Balance,336 gas_limit: u64,337 code: pallet_contracts_primitives::Code<Hash>,338 data: Vec<u8>,339 salt: Vec<u8>,340 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>341 {342 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)343 }344345 fn get_storage(346 address: AccountId,347 key: [u8; 32],348 ) -> pallet_contracts_primitives::GetStorageResult {349 Contracts::get_storage(address, key)350 }351352 fn rent_projection(353 address: AccountId,354 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {355 Contracts::rent_projection(address)356 }357 }358 */359360 #[cfg(feature = "runtime-benchmarks")]361 impl frame_benchmarking::Benchmark<Block> for Runtime {362 fn benchmark_metadata(extra: bool) -> (363 Vec<frame_benchmarking::BenchmarkList>,364 Vec<frame_support::traits::StorageInfo>,365 ) {366 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};367 use frame_support::traits::StorageInfoTrait;368369 let mut list = Vec::<BenchmarkList>::new();370371 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);372 list_benchmark!(list, extra, pallet_unique, Unique);373 list_benchmark!(list, extra, pallet_inflation, Inflation);374 list_benchmark!(list, extra, pallet_fungible, Fungible);375 list_benchmark!(list, extra, pallet_refungible, Refungible);376 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);377 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);378379 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();380381 return (list, storage_info)382 }383384 fn dispatch_benchmark(385 config: frame_benchmarking::BenchmarkConfig386 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {387 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};388389 let allowlist: Vec<TrackedStorageKey> = vec![390 // Block Number391 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),392 // Total Issuance393 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),394 // Execution Phase395 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),396 // Event Count397 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),398 // System Events399 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),400 ];401402 let mut batches = Vec::<BenchmarkBatch>::new();403 let params = (&config, &allowlist);404405 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);406 add_benchmark!(params, batches, pallet_unique, Unique);407 add_benchmark!(params, batches, pallet_inflation, Inflation);408 add_benchmark!(params, batches, pallet_fungible, Fungible);409 add_benchmark!(params, batches, pallet_refungible, Refungible);410 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);411 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);412413 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }414 Ok(batches)415 }416 }417 }418 }419}1#[macro_export]2macro_rules! impl_common_runtime_apis {3 (4 $(5 #![custom_apis]67 $($custom_apis:tt)+8 )?9 ) => {10 impl_runtime_apis! {11 $($($custom_apis)+)?1213 impl up_rpc::UniqueApi<Block, CrossAccountId, AccountId> for Runtime {14 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {15 dispatch_unique_runtime!(collection.account_tokens(account))16 }17 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {18 dispatch_unique_runtime!(collection.token_exists(token))19 }2021 fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {22 dispatch_unique_runtime!(collection.token_owner(token))23 }24 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {25 dispatch_unique_runtime!(collection.const_metadata(token))26 }27 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {28 dispatch_unique_runtime!(collection.variable_metadata(token))29 }3031 fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {32 dispatch_unique_runtime!(collection.collection_tokens())33 }34 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {35 dispatch_unique_runtime!(collection.account_balance(account))36 }37 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {38 dispatch_unique_runtime!(collection.balance(account, token))39 }40 fn allowance(41 collection: CollectionId,42 sender: CrossAccountId,43 spender: CrossAccountId,44 token: TokenId,45 ) -> Result<u128, DispatchError> {46 dispatch_unique_runtime!(collection.allowance(sender, spender, token))47 }4849 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {50 <pallet_unique::UniqueErcSupport<Runtime>>::get_code(&account)51 .or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))52 .or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))53 }54 fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {55 Ok(<pallet_common::Pallet<Runtime>>::adminlist(collection))56 }57 fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>, DispatchError> {58 Ok(<pallet_common::Pallet<Runtime>>::allowlist(collection))59 }60 fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool, DispatchError> {61 Ok(<pallet_common::Pallet<Runtime>>::allowed(collection, user))62 }63 fn last_token_id(collection: CollectionId) -> Result<TokenId, DispatchError> {64 dispatch_unique_runtime!(collection.last_token_id())65 }66 fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>, DispatchError> {67 Ok(<pallet_common::CollectionById<Runtime>>::get(collection))68 }69 fn collection_stats() -> Result<CollectionStats, DispatchError> {70 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())71 }72 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {73 Ok(<pallet_unique::UniqueSponsorshipPredict<Runtime> as74 pallet_unique::SponsorshipPredict<Runtime>>::predict(75 collection,76 account,77 token))78 }7980 fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {81 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))82 }83 }8485 impl sp_api::Core<Block> for Runtime {86 fn version() -> RuntimeVersion {87 VERSION88 }8990 fn execute_block(block: Block) {91 Executive::execute_block(block)92 }9394 fn initialize_block(header: &<Block as BlockT>::Header) {95 Executive::initialize_block(header)96 }97 }9899 impl sp_api::Metadata<Block> for Runtime {100 fn metadata() -> OpaqueMetadata {101 OpaqueMetadata::new(Runtime::metadata().into())102 }103 }104105 impl sp_block_builder::BlockBuilder<Block> for Runtime {106 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {107 Executive::apply_extrinsic(extrinsic)108 }109110 fn finalize_block() -> <Block as BlockT>::Header {111 Executive::finalize_block()112 }113114 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {115 data.create_extrinsics()116 }117118 fn check_inherents(119 block: Block,120 data: sp_inherents::InherentData,121 ) -> sp_inherents::CheckInherentsResult {122 data.check_extrinsics(&block)123 }124125 // fn random_seed() -> <Block as BlockT>::Hash {126 // RandomnessCollectiveFlip::random_seed().0127 // }128 }129130 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {131 fn validate_transaction(132 source: TransactionSource,133 tx: <Block as BlockT>::Extrinsic,134 hash: <Block as BlockT>::Hash,135 ) -> TransactionValidity {136 Executive::validate_transaction(source, tx, hash)137 }138 }139140 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {141 fn offchain_worker(header: &<Block as BlockT>::Header) {142 Executive::offchain_worker(header)143 }144 }145146 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {147 fn chain_id() -> u64 {148 <Runtime as pallet_evm::Config>::ChainId::get()149 }150151 fn account_basic(address: H160) -> EVMAccount {152 EVM::account_basic(&address)153 }154155 fn gas_price() -> U256 {156 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()157 }158159 fn account_code_at(address: H160) -> Vec<u8> {160 EVM::account_codes(address)161 }162163 fn author() -> H160 {164 <pallet_evm::Pallet<Runtime>>::find_author()165 }166167 fn storage_at(address: H160, index: U256) -> H256 {168 let mut tmp = [0u8; 32];169 index.to_big_endian(&mut tmp);170 EVM::account_storages(address, H256::from_slice(&tmp[..]))171 }172173 #[allow(clippy::redundant_closure)]174 fn call(175 from: H160,176 to: H160,177 data: Vec<u8>,178 value: U256,179 gas_limit: U256,180 max_fee_per_gas: Option<U256>,181 max_priority_fee_per_gas: Option<U256>,182 nonce: Option<U256>,183 estimate: bool,184 access_list: Option<Vec<(H160, Vec<H256>)>>,185 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {186 let config = if estimate {187 let mut config = <Runtime as pallet_evm::Config>::config().clone();188 config.estimate = true;189 Some(config)190 } else {191 None192 };193194 <Runtime as pallet_evm::Config>::Runner::call(195 CrossAccountId::from_eth(from),196 to,197 data,198 value,199 gas_limit.low_u64(),200 max_fee_per_gas,201 max_priority_fee_per_gas,202 nonce,203 access_list.unwrap_or_default(),204 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),205 ).map_err(|err| err.into())206 }207208 #[allow(clippy::redundant_closure)]209 fn create(210 from: H160,211 data: Vec<u8>,212 value: U256,213 gas_limit: U256,214 max_fee_per_gas: Option<U256>,215 max_priority_fee_per_gas: Option<U256>,216 nonce: Option<U256>,217 estimate: bool,218 access_list: Option<Vec<(H160, Vec<H256>)>>,219 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {220 let config = if estimate {221 let mut config = <Runtime as pallet_evm::Config>::config().clone();222 config.estimate = true;223 Some(config)224 } else {225 None226 };227228 <Runtime as pallet_evm::Config>::Runner::create(229 CrossAccountId::from_eth(from),230 data,231 value,232 gas_limit.low_u64(),233 max_fee_per_gas,234 max_priority_fee_per_gas,235 nonce,236 access_list.unwrap_or_default(),237 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),238 ).map_err(|err| err.into())239 }240241 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {242 Ethereum::current_transaction_statuses()243 }244245 fn current_block() -> Option<pallet_ethereum::Block> {246 Ethereum::current_block()247 }248249 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {250 Ethereum::current_receipts()251 }252253 fn current_all() -> (254 Option<pallet_ethereum::Block>,255 Option<Vec<pallet_ethereum::Receipt>>,256 Option<Vec<TransactionStatus>>257 ) {258 (259 Ethereum::current_block(),260 Ethereum::current_receipts(),261 Ethereum::current_transaction_statuses()262 )263 }264265 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {266 xts.into_iter().filter_map(|xt| match xt.0.function {267 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),268 _ => None269 }).collect()270 }271272 fn elasticity() -> Option<Permill> {273 None274 }275 }276277 impl sp_session::SessionKeys<Block> for Runtime {278 fn decode_session_keys(279 encoded: Vec<u8>,280 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {281 SessionKeys::decode_into_raw_public_keys(&encoded)282 }283284 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {285 SessionKeys::generate(seed)286 }287 }288289 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {290 fn slot_duration() -> sp_consensus_aura::SlotDuration {291 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())292 }293294 fn authorities() -> Vec<AuraId> {295 Aura::authorities().to_vec()296 }297 }298299 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {300 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {301 ParachainSystem::collect_collation_info(header)302 }303 }304305 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {306 fn account_nonce(account: AccountId) -> Index {307 System::account_nonce(account)308 }309 }310311 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {312 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {313 TransactionPayment::query_info(uxt, len)314 }315 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {316 TransactionPayment::query_fee_details(uxt, len)317 }318 }319320 /*321 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>322 for Runtime323 {324 fn call(325 origin: AccountId,326 dest: AccountId,327 value: Balance,328 gas_limit: u64,329 input_data: Vec<u8>,330 ) -> pallet_contracts_primitives::ContractExecResult {331 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)332 }333334 fn instantiate(335 origin: AccountId,336 endowment: Balance,337 gas_limit: u64,338 code: pallet_contracts_primitives::Code<Hash>,339 data: Vec<u8>,340 salt: Vec<u8>,341 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>342 {343 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)344 }345346 fn get_storage(347 address: AccountId,348 key: [u8; 32],349 ) -> pallet_contracts_primitives::GetStorageResult {350 Contracts::get_storage(address, key)351 }352353 fn rent_projection(354 address: AccountId,355 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {356 Contracts::rent_projection(address)357 }358 }359 */360361 #[cfg(feature = "runtime-benchmarks")]362 impl frame_benchmarking::Benchmark<Block> for Runtime {363 fn benchmark_metadata(extra: bool) -> (364 Vec<frame_benchmarking::BenchmarkList>,365 Vec<frame_support::traits::StorageInfo>,366 ) {367 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};368 use frame_support::traits::StorageInfoTrait;369370 let mut list = Vec::<BenchmarkList>::new();371372 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);373 list_benchmark!(list, extra, pallet_unique, Unique);374 list_benchmark!(list, extra, pallet_inflation, Inflation);375 list_benchmark!(list, extra, pallet_fungible, Fungible);376 list_benchmark!(list, extra, pallet_refungible, Refungible);377 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);378 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);379380 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();381382 return (list, storage_info)383 }384385 fn dispatch_benchmark(386 config: frame_benchmarking::BenchmarkConfig387 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {388 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};389390 let allowlist: Vec<TrackedStorageKey> = vec![391 // Block Number392 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),393 // Total Issuance394 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),395 // Execution Phase396 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),397 // Event Count398 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),399 // System Events400 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),401 ];402403 let mut batches = Vec::<BenchmarkBatch>::new();404 let params = (&config, &allowlist);405406 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);407 add_benchmark!(params, batches, pallet_unique, Unique);408 add_benchmark!(params, batches, pallet_inflation, Inflation);409 add_benchmark!(params, batches, pallet_fungible, Fungible);410 add_benchmark!(params, batches, pallet_refungible, Refungible);411 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);412 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);413414 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }415 Ok(batches)416 }417 }418 }419 }420}