difftreelog
fix(rpc) wrong return type for collectionTokens call
in: master
7 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -33,6 +33,12 @@
account: CrossAccountId,
at: Option<BlockHash>,
) -> Result<Vec<TokenId>>;
+ #[rpc(name = "unique_collectionTokens")]
+ fn collection_tokens(
+ &self,
+ collection: CollectionId,
+ at: Option<BlockHash>,
+ ) -> Result<Vec<TokenId>>;
#[rpc(name = "unique_tokenExists")]
fn token_exists(
&self,
@@ -70,8 +76,6 @@
at: Option<BlockHash>,
) -> Result<Vec<u8>>;
- #[rpc(name = "unique_collectionTokens")]
- fn collection_tokens(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;
#[rpc(name = "unique_accountBalance")]
fn account_balance(
&self,
@@ -226,6 +230,7 @@
CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,
{
pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);
+ pass_method!(collection_tokens(collection: CollectionId) -> Vec<TokenId>);
pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);
pass_method!(
token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;
@@ -234,7 +239,6 @@
pass_method!(topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>);
pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);
pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);
- pass_method!(collection_tokens(collection: CollectionId) -> u32);
pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);
pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());
pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -924,6 +924,7 @@
) -> DispatchResult;
fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;
+ fn collection_tokens(&self) -> Vec<TokenId>;
fn token_exists(&self, token: TokenId) -> bool;
fn last_token_id(&self) -> TokenId;
@@ -931,8 +932,6 @@
fn const_metadata(&self, token: TokenId) -> Vec<u8>;
fn variable_metadata(&self, token: TokenId) -> Vec<u8>;
- /// How many tokens collection contains (Applicable to nonfungible/refungible)
- fn collection_tokens(&self) -> u32;
/// Amount of different tokens account has (Applicable to nonfungible/refungible)
fn account_balance(&self, account: T::CrossAccountId) -> u32;
/// Amount of specific token account have (Applicable to fungible/refungible)
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -270,8 +270,8 @@
Vec::new()
}
- fn collection_tokens(&self) -> u32 {
- 1
+ fn collection_tokens(&self) -> Vec<TokenId> {
+ vec![TokenId::default()]
}
fn account_balance(&self, account: T::CrossAccountId) -> u32 {
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -264,6 +264,12 @@
.collect()
}
+ fn collection_tokens(&self) -> Vec<TokenId> {
+ <TokenData<T>>::iter_prefix((self.id,))
+ .map(|(id, _)| id)
+ .collect()
+ }
+
fn token_exists(&self, token: TokenId) -> bool {
<Pallet<T>>::token_exists(self, token)
}
@@ -286,10 +292,6 @@
.map(|t| t.variable_data)
.unwrap_or_default()
.into_inner()
- }
-
- fn collection_tokens(&self) -> u32 {
- <Pallet<T>>::total_supply(self)
}
fn account_balance(&self, account: T::CrossAccountId) -> u32 {
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -273,6 +273,12 @@
.collect()
}
+ fn collection_tokens(&self) -> Vec<TokenId> {
+ <TokenData<T>>::iter_prefix((self.id,))
+ .map(|(id, _)| id)
+ .collect()
+ }
+
fn token_exists(&self, token: TokenId) -> bool {
<Pallet<T>>::token_exists(self, token)
}
@@ -293,10 +299,6 @@
<TokenData<T>>::get((self.id, token))
.variable_data
.into_inner()
- }
-
- fn collection_tokens(&self) -> u32 {
- <Pallet<T>>::total_supply(self)
}
fn account_balance(&self, account: T::CrossAccountId) -> u32 {
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -33,6 +33,7 @@
fn token_owner(collection: CollectionId, token: TokenId) -> Result<CrossAccountId>;
fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>>;
+ fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>>;
fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool>;
fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;
@@ -40,7 +41,6 @@
fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
- fn collection_tokens(collection: CollectionId) -> Result<u32>;
fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;
fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;
fn allowance(
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 topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {25 let budget = up_data_structs::budget::Value::new(5);2627 Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))28 }29 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {30 dispatch_unique_runtime!(collection.const_metadata(token))31 }32 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {33 dispatch_unique_runtime!(collection.variable_metadata(token))34 }3536 fn collection_tokens(collection: CollectionId) -> Result<u32, DispatchError> {37 dispatch_unique_runtime!(collection.collection_tokens())38 }39 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {40 dispatch_unique_runtime!(collection.account_balance(account))41 }42 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {43 dispatch_unique_runtime!(collection.balance(account, token))44 }45 fn allowance(46 collection: CollectionId,47 sender: CrossAccountId,48 spender: CrossAccountId,49 token: TokenId,50 ) -> Result<u128, DispatchError> {51 dispatch_unique_runtime!(collection.allowance(sender, spender, token))52 }5354 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<RpcCollection<AccountId>>, DispatchError> {67 Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(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 let is_transactional = false;195 <Runtime as pallet_evm::Config>::Runner::call(196 CrossAccountId::from_eth(from),197 to,198 data,199 value,200 gas_limit.low_u64(),201 max_fee_per_gas,202 max_priority_fee_per_gas,203 nonce,204 access_list.unwrap_or_default(),205 is_transactional,206 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),207 ).map_err(|err| err.into())208 }209210 #[allow(clippy::redundant_closure)]211 fn create(212 from: H160,213 data: Vec<u8>,214 value: U256,215 gas_limit: U256,216 max_fee_per_gas: Option<U256>,217 max_priority_fee_per_gas: Option<U256>,218 nonce: Option<U256>,219 estimate: bool,220 access_list: Option<Vec<(H160, Vec<H256>)>>,221 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {222 let config = if estimate {223 let mut config = <Runtime as pallet_evm::Config>::config().clone();224 config.estimate = true;225 Some(config)226 } else {227 None228 };229230 let is_transactional = false;231 <Runtime as pallet_evm::Config>::Runner::create(232 CrossAccountId::from_eth(from),233 data,234 value,235 gas_limit.low_u64(),236 max_fee_per_gas,237 max_priority_fee_per_gas,238 nonce,239 access_list.unwrap_or_default(),240 is_transactional,241 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),242 ).map_err(|err| err.into())243 }244245 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {246 Ethereum::current_transaction_statuses()247 }248249 fn current_block() -> Option<pallet_ethereum::Block> {250 Ethereum::current_block()251 }252253 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {254 Ethereum::current_receipts()255 }256257 fn current_all() -> (258 Option<pallet_ethereum::Block>,259 Option<Vec<pallet_ethereum::Receipt>>,260 Option<Vec<TransactionStatus>>261 ) {262 (263 Ethereum::current_block(),264 Ethereum::current_receipts(),265 Ethereum::current_transaction_statuses()266 )267 }268269 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {270 xts.into_iter().filter_map(|xt| match xt.0.function {271 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),272 _ => None273 }).collect()274 }275276 fn elasticity() -> Option<Permill> {277 None278 }279 }280281 impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {282 fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic {283 UncheckedExtrinsic::new_unsigned(284 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),285 )286 }287 }288289 impl sp_session::SessionKeys<Block> for Runtime {290 fn decode_session_keys(291 encoded: Vec<u8>,292 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {293 SessionKeys::decode_into_raw_public_keys(&encoded)294 }295296 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {297 SessionKeys::generate(seed)298 }299 }300301 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {302 fn slot_duration() -> sp_consensus_aura::SlotDuration {303 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())304 }305306 fn authorities() -> Vec<AuraId> {307 Aura::authorities().to_vec()308 }309 }310311 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {312 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {313 ParachainSystem::collect_collation_info(header)314 }315 }316317 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {318 fn account_nonce(account: AccountId) -> Index {319 System::account_nonce(account)320 }321 }322323 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {324 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {325 TransactionPayment::query_info(uxt, len)326 }327 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {328 TransactionPayment::query_fee_details(uxt, len)329 }330 }331332 /*333 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>334 for Runtime335 {336 fn call(337 origin: AccountId,338 dest: AccountId,339 value: Balance,340 gas_limit: u64,341 input_data: Vec<u8>,342 ) -> pallet_contracts_primitives::ContractExecResult {343 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)344 }345346 fn instantiate(347 origin: AccountId,348 endowment: Balance,349 gas_limit: u64,350 code: pallet_contracts_primitives::Code<Hash>,351 data: Vec<u8>,352 salt: Vec<u8>,353 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>354 {355 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)356 }357358 fn get_storage(359 address: AccountId,360 key: [u8; 32],361 ) -> pallet_contracts_primitives::GetStorageResult {362 Contracts::get_storage(address, key)363 }364365 fn rent_projection(366 address: AccountId,367 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {368 Contracts::rent_projection(address)369 }370 }371 */372373 #[cfg(feature = "runtime-benchmarks")]374 impl frame_benchmarking::Benchmark<Block> for Runtime {375 fn benchmark_metadata(extra: bool) -> (376 Vec<frame_benchmarking::BenchmarkList>,377 Vec<frame_support::traits::StorageInfo>,378 ) {379 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};380 use frame_support::traits::StorageInfoTrait;381382 let mut list = Vec::<BenchmarkList>::new();383384 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);385 list_benchmark!(list, extra, pallet_unique, Unique);386 list_benchmark!(list, extra, pallet_structure, Structure);387 list_benchmark!(list, extra, pallet_inflation, Inflation);388 list_benchmark!(list, extra, pallet_fungible, Fungible);389 list_benchmark!(list, extra, pallet_refungible, Refungible);390 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);391 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);392393 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();394395 return (list, storage_info)396 }397398 fn dispatch_benchmark(399 config: frame_benchmarking::BenchmarkConfig400 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {401 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};402403 let allowlist: Vec<TrackedStorageKey> = vec![404 // Block Number405 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),406 // Total Issuance407 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),408 // Execution Phase409 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),410 // Event Count411 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),412 // System Events413 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),414415 // Transactional depth416 hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),417 ];418419 let mut batches = Vec::<BenchmarkBatch>::new();420 let params = (&config, &allowlist);421422 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);423 add_benchmark!(params, batches, pallet_unique, Unique);424 add_benchmark!(params, batches, pallet_structure, Structure);425 add_benchmark!(params, batches, pallet_inflation, Inflation);426 add_benchmark!(params, batches, pallet_fungible, Fungible);427 add_benchmark!(params, batches, pallet_refungible, Refungible);428 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);429 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);430431 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }432 Ok(batches)433 }434 }435436 #[cfg(feature = "try-runtime")]437 impl frame_try_runtime::TryRuntime<Block> for Runtime {438 fn on_runtime_upgrade() -> (Weight, Weight) {439 log::info!("try-runtime::on_runtime_upgrade unique-chain.");440 let weight = Executive::try_runtime_upgrade().unwrap();441 (weight, RuntimeBlockWeights::get().max_block)442 }443444 fn execute_block_no_check(block: Block) -> Weight {445 Executive::execute_block_no_check(block)446 }447 }448 }449 }450}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 topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {25 let budget = up_data_structs::budget::Value::new(5);2627 Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))28 }29 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {30 dispatch_unique_runtime!(collection.const_metadata(token))31 }32 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>, DispatchError> {33 dispatch_unique_runtime!(collection.variable_metadata(token))34 }3536 fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {37 dispatch_unique_runtime!(collection.collection_tokens())38 }39 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {40 dispatch_unique_runtime!(collection.account_balance(account))41 }42 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128, DispatchError> {43 dispatch_unique_runtime!(collection.balance(account, token))44 }45 fn allowance(46 collection: CollectionId,47 sender: CrossAccountId,48 spender: CrossAccountId,49 token: TokenId,50 ) -> Result<u128, DispatchError> {51 dispatch_unique_runtime!(collection.allowance(sender, spender, token))52 }5354 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<RpcCollection<AccountId>>, DispatchError> {67 Ok(<pallet_common::Pallet<Runtime>>::rpc_collection(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 let is_transactional = false;195 <Runtime as pallet_evm::Config>::Runner::call(196 CrossAccountId::from_eth(from),197 to,198 data,199 value,200 gas_limit.low_u64(),201 max_fee_per_gas,202 max_priority_fee_per_gas,203 nonce,204 access_list.unwrap_or_default(),205 is_transactional,206 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),207 ).map_err(|err| err.into())208 }209210 #[allow(clippy::redundant_closure)]211 fn create(212 from: H160,213 data: Vec<u8>,214 value: U256,215 gas_limit: U256,216 max_fee_per_gas: Option<U256>,217 max_priority_fee_per_gas: Option<U256>,218 nonce: Option<U256>,219 estimate: bool,220 access_list: Option<Vec<(H160, Vec<H256>)>>,221 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {222 let config = if estimate {223 let mut config = <Runtime as pallet_evm::Config>::config().clone();224 config.estimate = true;225 Some(config)226 } else {227 None228 };229230 let is_transactional = false;231 <Runtime as pallet_evm::Config>::Runner::create(232 CrossAccountId::from_eth(from),233 data,234 value,235 gas_limit.low_u64(),236 max_fee_per_gas,237 max_priority_fee_per_gas,238 nonce,239 access_list.unwrap_or_default(),240 is_transactional,241 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),242 ).map_err(|err| err.into())243 }244245 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {246 Ethereum::current_transaction_statuses()247 }248249 fn current_block() -> Option<pallet_ethereum::Block> {250 Ethereum::current_block()251 }252253 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {254 Ethereum::current_receipts()255 }256257 fn current_all() -> (258 Option<pallet_ethereum::Block>,259 Option<Vec<pallet_ethereum::Receipt>>,260 Option<Vec<TransactionStatus>>261 ) {262 (263 Ethereum::current_block(),264 Ethereum::current_receipts(),265 Ethereum::current_transaction_statuses()266 )267 }268269 fn extrinsic_filter(xts: Vec<<Block as sp_api::BlockT>::Extrinsic>) -> Vec<pallet_ethereum::Transaction> {270 xts.into_iter().filter_map(|xt| match xt.0.function {271 Call::Ethereum(pallet_ethereum::Call::transact { transaction }) => Some(transaction),272 _ => None273 }).collect()274 }275276 fn elasticity() -> Option<Permill> {277 None278 }279 }280281 impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {282 fn convert_transaction(transaction: pallet_ethereum::Transaction) -> <Block as BlockT>::Extrinsic {283 UncheckedExtrinsic::new_unsigned(284 pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),285 )286 }287 }288289 impl sp_session::SessionKeys<Block> for Runtime {290 fn decode_session_keys(291 encoded: Vec<u8>,292 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {293 SessionKeys::decode_into_raw_public_keys(&encoded)294 }295296 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {297 SessionKeys::generate(seed)298 }299 }300301 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {302 fn slot_duration() -> sp_consensus_aura::SlotDuration {303 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())304 }305306 fn authorities() -> Vec<AuraId> {307 Aura::authorities().to_vec()308 }309 }310311 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {312 fn collect_collation_info(header: &<Block as BlockT>::Header) -> cumulus_primitives_core::CollationInfo {313 ParachainSystem::collect_collation_info(header)314 }315 }316317 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {318 fn account_nonce(account: AccountId) -> Index {319 System::account_nonce(account)320 }321 }322323 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {324 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {325 TransactionPayment::query_info(uxt, len)326 }327 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {328 TransactionPayment::query_fee_details(uxt, len)329 }330 }331332 /*333 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>334 for Runtime335 {336 fn call(337 origin: AccountId,338 dest: AccountId,339 value: Balance,340 gas_limit: u64,341 input_data: Vec<u8>,342 ) -> pallet_contracts_primitives::ContractExecResult {343 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)344 }345346 fn instantiate(347 origin: AccountId,348 endowment: Balance,349 gas_limit: u64,350 code: pallet_contracts_primitives::Code<Hash>,351 data: Vec<u8>,352 salt: Vec<u8>,353 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>354 {355 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)356 }357358 fn get_storage(359 address: AccountId,360 key: [u8; 32],361 ) -> pallet_contracts_primitives::GetStorageResult {362 Contracts::get_storage(address, key)363 }364365 fn rent_projection(366 address: AccountId,367 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {368 Contracts::rent_projection(address)369 }370 }371 */372373 #[cfg(feature = "runtime-benchmarks")]374 impl frame_benchmarking::Benchmark<Block> for Runtime {375 fn benchmark_metadata(extra: bool) -> (376 Vec<frame_benchmarking::BenchmarkList>,377 Vec<frame_support::traits::StorageInfo>,378 ) {379 use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};380 use frame_support::traits::StorageInfoTrait;381382 let mut list = Vec::<BenchmarkList>::new();383384 list_benchmark!(list, extra, pallet_evm_migration, EvmMigration);385 list_benchmark!(list, extra, pallet_unique, Unique);386 list_benchmark!(list, extra, pallet_structure, Structure);387 list_benchmark!(list, extra, pallet_inflation, Inflation);388 list_benchmark!(list, extra, pallet_fungible, Fungible);389 list_benchmark!(list, extra, pallet_refungible, Refungible);390 list_benchmark!(list, extra, pallet_nonfungible, Nonfungible);391 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);392393 let storage_info = AllPalletsReversedWithSystemFirst::storage_info();394395 return (list, storage_info)396 }397398 fn dispatch_benchmark(399 config: frame_benchmarking::BenchmarkConfig400 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {401 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};402403 let allowlist: Vec<TrackedStorageKey> = vec![404 // Block Number405 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),406 // Total Issuance407 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),408 // Execution Phase409 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),410 // Event Count411 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),412 // System Events413 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),414415 // Transactional depth416 hex_literal::hex!("3a7472616e73616374696f6e5f6c6576656c3a").to_vec().into(),417 ];418419 let mut batches = Vec::<BenchmarkBatch>::new();420 let params = (&config, &allowlist);421422 add_benchmark!(params, batches, pallet_evm_migration, EvmMigration);423 add_benchmark!(params, batches, pallet_unique, Unique);424 add_benchmark!(params, batches, pallet_structure, Structure);425 add_benchmark!(params, batches, pallet_inflation, Inflation);426 add_benchmark!(params, batches, pallet_fungible, Fungible);427 add_benchmark!(params, batches, pallet_refungible, Refungible);428 add_benchmark!(params, batches, pallet_nonfungible, Nonfungible);429 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);430431 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }432 Ok(batches)433 }434 }435436 #[cfg(feature = "try-runtime")]437 impl frame_try_runtime::TryRuntime<Block> for Runtime {438 fn on_runtime_upgrade() -> (Weight, Weight) {439 log::info!("try-runtime::on_runtime_upgrade unique-chain.");440 let weight = Executive::try_runtime_upgrade().unwrap();441 (weight, RuntimeBlockWeights::get().max_block)442 }443444 fn execute_block_no_check(block: Block) -> Weight {445 Executive::execute_block_no_check(block)446 }447 }448 }449 }450}