git.delta.rocks / unique-network / refs/commits / 29e2c31254c0

difftreelog

refactor rename dispatch_call to dispatch_tx

Daniel Shiposha2022-06-09parent: #d35835c.patch.diff
in: master

2 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
11use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};11use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
1212
13// TODO: move to benchmarking13// TODO: move to benchmarking
14/// Price of [`dispatch_call`] call with noop `call` argument14/// Price of [`dispatch_tx`] call with noop `call` argument
15pub fn dispatch_weight<T: Config>() -> Weight {15pub fn dispatch_weight<T: Config>() -> Weight {
16 // Read collection16 // Read collection
17 <T as frame_system::Config>::DbWeight::get().reads(1)17 <T as frame_system::Config>::DbWeight::get().reads(1)
21}21}
2222
23/// Helper function to implement substrate calls for common collection methods23/// Helper function to implement substrate calls for common collection methods
24pub 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>(
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
44};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);
583583
584 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 }
586586
587 /// 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);
611611
612 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 }
614614
615 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]615 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]
623623
624 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);624 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
625625
626 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 }
628628
629 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]629 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]
637637
638 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);638 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
639639
640 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 }
642642
643 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]643 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]
652652
653 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);653 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
654654
655 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 }
657657
658 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]658 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]
667667
668 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);668 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
669669
670 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 }
672672
673 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]673 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]
681681
682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
683683
684 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 }
686686
687 #[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);
692692
693 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 }
695695
696 // TODO! transaction weight696 // TODO! transaction weight
738 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)?);
740740
741 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);
773773
774 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 }
776776
777 /// 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);
805805
806 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 }
808808
809 /// 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)?);
828828
829 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 }
831831
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.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);
856856
857 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 }
859859
860 #[weight = <SelfWeightOf<T>>::set_collection_limits()]860 #[weight = <SelfWeightOf<T>>::set_collection_limits()]