git.delta.rocks / unique-network / refs/commits / 5a68a95f44d7

difftreelog

fix usage of nesting_budget in pallet-unique

Daniel Shiposha2023-10-11parent: #437764b.patch.diff
in: master

2 files changed

modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
93 use frame_system::{ensure_root, ensure_signed};93 use frame_system::{ensure_root, ensure_signed};
94 use pallet_common::{94 use pallet_common::{
95 dispatch::{dispatch_tx, CollectionDispatch},95 dispatch::{dispatch_tx, CollectionDispatch},
96 CollectionHandle, CommonCollectionOperations, CommonWeightInfo, Pallet as PalletCommon,96 CollectionHandle, CommonWeightInfo, Pallet as PalletCommon, RefungibleExtensionsWeightInfo,
97 RefungibleExtensionsWeightInfo,
98 };97 };
99 use pallet_evm::account::CrossAccountId;98 use pallet_evm::account::CrossAccountId;
682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);681 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
683 let budget = Self::structure_nesting_budget();682 let budget = Self::structure_nesting_budget();
684683
685 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {684 Self::refund_nesting_budget(
685 dispatch_tx::<T, _>(collection_id, |d| {
686 d.create_item(sender, owner, data, &budget)686 d.create_item(sender, owner, data, &budget)
687 })687 }),
688 budget,
689 )
688 }690 }
689691
717 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);719 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
718 let budget = Self::structure_nesting_budget();720 let budget = Self::structure_nesting_budget();
719721
720 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {722 Self::refund_nesting_budget(
723 dispatch_tx::<T, _>(collection_id, |d| {
721 d.create_multiple_items(sender, owner, items_data, &budget)724 d.create_multiple_items(sender, owner, items_data, &budget)
722 })725 }),
726 budget,
727 )
723 }728 }
724729
809 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);814 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
810 let budget = Self::structure_nesting_budget();815 let budget = Self::structure_nesting_budget();
811816
812 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {817 Self::refund_nesting_budget(
818 dispatch_tx::<T, _>(collection_id, |d| {
813 d.set_token_properties(sender, token_id, properties, &budget)819 d.set_token_properties(sender, token_id, properties, &budget)
814 })820 }),
821 budget,
822 )
815 }823 }
816824
842 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);850 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
843 let budget = Self::structure_nesting_budget();851 let budget = Self::structure_nesting_budget();
844852
845 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {853 Self::refund_nesting_budget(
854 dispatch_tx::<T, _>(collection_id, |d| {
846 d.delete_token_properties(sender, token_id, property_keys, &budget)855 d.delete_token_properties(sender, token_id, property_keys, &budget)
847 })856 }),
857 budget,
858 )
848 }859 }
849860
903 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);914 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
904 let budget = Self::structure_nesting_budget();915 let budget = Self::structure_nesting_budget();
905916
906 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {917 Self::refund_nesting_budget(
918 dispatch_tx::<T, _>(collection_id, |d| {
907 d.create_multiple_items_ex(sender, data, &budget)919 d.create_multiple_items_ex(sender, data, &budget)
908 })920 }),
921 budget,
922 )
909 }923 }
910924
1012 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1026 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1013 let budget = Self::structure_nesting_budget();1027 let budget = Self::structure_nesting_budget();
10141028
1015 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {1029 Self::refund_nesting_budget(
1030 dispatch_tx::<T, _>(collection_id, |d| {
1016 d.burn_from(sender, from, item_id, value, &budget)1031 d.burn_from(sender, from, item_id, value, &budget)
1017 })1032 }),
1033 budget,
1034 )
1018 }1035 }
10191036
1050 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1067 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1051 let budget = Self::structure_nesting_budget();1068 let budget = Self::structure_nesting_budget();
10521069
1053 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {1070 Self::refund_nesting_budget(
1071 dispatch_tx::<T, _>(collection_id, |d| {
1054 d.transfer(sender, recipient, item_id, value, &budget)1072 d.transfer(sender, recipient, item_id, value, &budget)
1055 })1073 }),
1074 budget,
1075 )
1056 }1076 }
10571077
1156 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1176 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1157 let budget = Self::structure_nesting_budget();1177 let budget = Self::structure_nesting_budget();
11581178
1159 Self::dispatch_tx_with_nesting_budget(collection_id, &budget, |d| {1179 Self::refund_nesting_budget(
1180 dispatch_tx::<T, _>(collection_id, |d| {
1160 d.transfer_from(sender, from, recipient, item_id, value, &budget)1181 d.transfer_from(sender, from, recipient, item_id, value, &budget)
1161 })1182 }),
1183 budget,
1184 )
1162 }1185 }
11631186
1359 budget::Value::new(Self::nesting_budget())1382 budget::Value::new(Self::nesting_budget())
1360 }1383 }
13611384
1362 fn nesting_budget_weight(value: &budget::Value) -> Weight {1385 fn nesting_budget_predispatch_weight() -> Weight {
1363 T::StructureWeightInfo::find_parent().saturating_mul(value.remaining() as u64)1386 T::StructureWeightInfo::find_parent().saturating_mul(Self::nesting_budget() as u64)
1364 }1387 }
1365
1366 fn nesting_budget_predispatch_weight() -> Weight {
1367 Self::nesting_budget_weight(&Self::structure_nesting_budget())
1368 }
13691388
1370 pub fn dispatch_tx_with_nesting_budget<1389 pub fn refund_nesting_budget(
1371 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,1390 mut result: DispatchResultWithPostInfo,
1372 >(
1373 collection: CollectionId,
1374 budget: &budget::Value,1391 budget: budget::Value,
1375 call: C,
1376 ) -> DispatchResultWithPostInfo {1392 ) -> DispatchResultWithPostInfo {
1393 let refund_amount = budget.refund_amount();
1377 let mut result = dispatch_tx::<T, _>(collection, call);1394 let consumed = Self::nesting_budget() - refund_amount;
13781395
1379 match &mut result {1396 match &mut result {
1380 Ok(PostDispatchInfo {1397 Ok(PostDispatchInfo {
1387 ..1404 ..
1388 },1405 },
1389 ..1406 ..
1390 }) => *weight += Self::nesting_budget_weight(budget),1407 }) => {
1408 *weight += T::StructureWeightInfo::find_parent().saturating_mul(consumed as u64)
1409 }
1391 _ => {}1410 _ => {}
1392 }1411 }
13931412
modifiedprimitives/data-structs/src/budget.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/budget.rs
+++ b/primitives/data-structs/src/budget.rs
@@ -22,7 +22,7 @@
 	pub fn new(v: u32) -> Self {
 		Self(Cell::new(v))
 	}
-	pub fn remaining(&self) -> u32 {
+	pub fn refund_amount(self) -> u32 {
 		self.0.get()
 	}
 }