difftreelog
refactor rename dispatch_call to dispatch_tx
in: master
2 files changed
pallets/common/src/dispatch.rsdiffbeforeafterboth11use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};11use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};121213// TODO: move to benchmarking13// TODO: move to benchmarking14/// Price of [`dispatch_call`] call with noop `call` argument14/// Price of [`dispatch_tx`] call with noop `call` argument15pub fn dispatch_weight<T: Config>() -> Weight {15pub fn dispatch_weight<T: Config>() -> Weight {16 // Read collection16 // Read collection17 <T as frame_system::Config>::DbWeight::get().reads(1)17 <T as frame_system::Config>::DbWeight::get().reads(1)21}21}222223/// Helper function to implement substrate calls for common collection methods23/// Helper function to implement substrate calls for common collection methods24pub fn dispatch_call<24pub fn dispatch_tx<25 T: Config,25 T: Config,26 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,26 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,27>(27>(pallets/unique/src/lib.rsdiffbeforeafterboth44};44};45use pallet_evm::account::CrossAccountId;45use pallet_evm::account::CrossAccountId;46use pallet_common::{46use pallet_common::{47 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_call,47 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,48 dispatch::CollectionDispatch,48 dispatch::CollectionDispatch,49};49};50pub mod eth;50pub mod eth;581 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);581 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);582 let budget = budget::Value::new(NESTING_BUDGET);582 let budget = budget::Value::new(NESTING_BUDGET);583583584 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))584 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))585 }585 }586586587 /// This method creates multiple items in a collection created with CreateCollection method.587 /// This method creates multiple items in a collection created with CreateCollection method.609 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);609 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);610 let budget = budget::Value::new(NESTING_BUDGET);610 let budget = budget::Value::new(NESTING_BUDGET);611611612 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))612 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))613 }613 }614614615 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]615 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]623623624 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);624 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);625625626 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))626 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))627 }627 }628628629 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]629 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]637637638 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);638 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);639639640 dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))640 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))641 }641 }642642643 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]643 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]652652653 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);653 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);654654655 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))655 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))656 }656 }657657658 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]658 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]667667668 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);668 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);669669670 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))670 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))671 }671 }672672673 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]673 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]681681682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);683683684 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))684 dispatch_tx::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))685 }685 }686686687 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]687 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]690 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);690 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);691 let budget = budget::Value::new(NESTING_BUDGET);691 let budget = budget::Value::new(NESTING_BUDGET);692692693 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))693 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))694 }694 }695695696 // TODO! transaction weight696 // TODO! transaction weight738 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {738 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740740741 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;741 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;742 if value == 1 {742 if value == 1 {743 <NftTransferBasket<T>>::remove(collection_id, item_id);743 <NftTransferBasket<T>>::remove(collection_id, item_id);744 <NftApproveBasket<T>>::remove(collection_id, item_id);744 <NftApproveBasket<T>>::remove(collection_id, item_id);771 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);771 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);772 let budget = budget::Value::new(NESTING_BUDGET);772 let budget = budget::Value::new(NESTING_BUDGET);773773774 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))774 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))775 }775 }776776777 /// Change ownership of the token.777 /// Change ownership of the token.803 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);803 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);804 let budget = budget::Value::new(NESTING_BUDGET);804 let budget = budget::Value::new(NESTING_BUDGET);805805806 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))806 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))807 }807 }808808809 /// Set, change, or remove approved address to transfer the ownership of the NFT.809 /// Set, change, or remove approved address to transfer the ownership of the NFT.826 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {826 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {827 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);827 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);828828829 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))829 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))830 }830 }831831832 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.832 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.854 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);854 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);855 let budget = budget::Value::new(NESTING_BUDGET);855 let budget = budget::Value::new(NESTING_BUDGET);856856857 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))857 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))858 }858 }859859860 #[weight = <SelfWeightOf<T>>::set_collection_limits()]860 #[weight = <SelfWeightOf<T>>::set_collection_limits()]