git.delta.rocks / unique-network / refs/commits / f8774b896e5b

difftreelog

Public storage

str-mv2021-11-22parent: #946ee50.patch.diff
in: master

3 files changed

modifiedpallets/nft/src/sponsorship.rsdiffbeforeafterboth
--- a/pallets/nft/src/sponsorship.rs
+++ b/pallets/nft/src/sponsorship.rs
@@ -14,12 +14,24 @@
 	REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, TokenId,
 };
 use pallet_common::{CollectionHandle};
+use pallet_common::account::CrossAccountId;
 
 pub fn withdraw_transfer<T: Config>(
 	collection: &CollectionHandle<T>,
 	who: &T::AccountId,
 	item_id: &TokenId,
 ) -> Option<()> {
+
+	// preliminary sponsoring correctness check
+	if !((pallet_nonfungible::TokenData::<T>::get((collection.id, item_id))?.owner).as_sub()
+		== who) || (pallet_refungible::Owned::<T>::get((
+		collection.id,
+		T::CrossAccountId::from_sub(who.clone()),
+		item_id,
+	))) {
+		return None;
+	}
+	
 	// sponsor timeout
 	let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
 	let limit = collection
@@ -90,10 +102,22 @@
 }
 
 pub fn withdraw_set_variable_meta_data<T: Config>(
+	who: &T::AccountId,
 	collection: &CollectionHandle<T>,
 	item_id: &TokenId,
 	data: &[u8],
 ) -> Option<()> {
+
+	// preliminary sponsoring correctness check
+	if !((pallet_nonfungible::TokenData::<T>::get((collection.id, item_id))?.owner).as_sub()
+		== who) || (pallet_refungible::Owned::<T>::get((
+		collection.id,
+		T::CrossAccountId::from_sub(who.clone()),
+		item_id,
+	))) {
+		return None;
+	}
+
 	// Can't sponsor fungible collection, this tx will be rejected
 	// as invalid
 	if matches!(collection.mode, CollectionMode::Fungible(_)) {
@@ -204,7 +228,7 @@
 				data,
 			} => {
 				let (sponsor, collection) = load(*collection_id)?;
-				withdraw_set_variable_meta_data::<T>(&collection, item_id, data).map(|()| sponsor)
+				withdraw_set_variable_meta_data::<T>(&who, &collection, item_id, data).map(|()| sponsor)
 			}
 			_ => None,
 		}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
58 }58 }
5959
60 #[pallet::pallet]60 #[pallet::pallet]
61 #[pallet::generate_store(pub(super) trait Store)]61 #[pallet::generate_store(pub trait Store)]
62 pub struct Pallet<T>(_);62 pub struct Pallet<T>(_);
6363
64 #[pallet::storage]64 #[pallet::storage]
65 pub(super) type TokensMinted<T: Config> =65 pub type TokensMinted<T: Config> =
66 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;66 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
67 #[pallet::storage]67 #[pallet::storage]
68 pub(super) type TokensBurnt<T: Config> =68 pub type TokensBurnt<T: Config> =
69 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;69 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
7070
71 #[pallet::storage]71 #[pallet::storage]
72 pub(super) type TokenData<T: Config> = StorageNMap<72 pub type TokenData<T: Config> = StorageNMap<
73 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),73 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
74 Value = ItemData<T>,74 Value = ItemData<T>,
75 QueryKind = OptionQuery,75 QueryKind = OptionQuery,
76 >;76 >;
7777
78 /// Used to enumerate tokens owned by account78 /// Used to enumerate tokens owned by account
79 #[pallet::storage]79 #[pallet::storage]
80 pub(super) type Owned<T: Config> = StorageNMap<80 pub type Owned<T: Config> = StorageNMap<
81 Key = (81 Key = (
82 Key<Twox64Concat, CollectionId>,82 Key<Twox64Concat, CollectionId>,
83 Key<Blake2_128Concat, T::CrossAccountId>,83 Key<Blake2_128Concat, T::CrossAccountId>,
88 >;88 >;
8989
90 #[pallet::storage]90 #[pallet::storage]
91 pub(super) type AccountBalance<T: Config> = StorageNMap<91 pub type AccountBalance<T: Config> = StorageNMap<
92 Key = (92 Key = (
93 Key<Twox64Concat, CollectionId>,93 Key<Twox64Concat, CollectionId>,
94 Key<Blake2_128Concat, T::CrossAccountId>,94 Key<Blake2_128Concat, T::CrossAccountId>,
98 >;98 >;
9999
100 #[pallet::storage]100 #[pallet::storage]
101 pub(super) type Allowance<T: Config> = StorageNMap<101 pub type Allowance<T: Config> = StorageNMap<
102 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),102 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
103 Value = T::CrossAccountId,103 Value = T::CrossAccountId,
104 QueryKind = OptionQuery,104 QueryKind = OptionQuery,
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -54,25 +54,25 @@
 	}
 
 	#[pallet::pallet]
-	#[pallet::generate_store(pub(super) trait Store)]
+	#[pallet::generate_store(pub trait Store)]
 	pub struct Pallet<T>(_);
 
 	#[pallet::storage]
-	pub(super) type TokensMinted<T: Config> =
+	pub type TokensMinted<T: Config> =
 		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
 	#[pallet::storage]
-	pub(super) type TokensBurnt<T: Config> =
+	pub type TokensBurnt<T: Config> =
 		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
 
 	#[pallet::storage]
-	pub(super) type TokenData<T: Config> = StorageNMap<
+	pub type TokenData<T: Config> = StorageNMap<
 		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
 		Value = ItemData,
 		QueryKind = ValueQuery,
 	>;
 
 	#[pallet::storage]
-	pub(super) type TotalSupply<T: Config> = StorageNMap<
+	pub type TotalSupply<T: Config> = StorageNMap<
 		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
 		Value = u128,
 		QueryKind = ValueQuery,
@@ -80,7 +80,7 @@
 
 	/// Used to enumerate tokens owned by account
 	#[pallet::storage]
-	pub(super) type Owned<T: Config> = StorageNMap<
+	pub type Owned<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
 			Key<Blake2_128Concat, T::CrossAccountId>,
@@ -91,7 +91,7 @@
 	>;
 
 	#[pallet::storage]
-	pub(super) type AccountBalance<T: Config> = StorageNMap<
+	pub type AccountBalance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
 			// Owner
@@ -102,7 +102,7 @@
 	>;
 
 	#[pallet::storage]
-	pub(super) type Balance<T: Config> = StorageNMap<
+	pub type Balance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
 			Key<Twox64Concat, TokenId>,
@@ -114,7 +114,7 @@
 	>;
 
 	#[pallet::storage]
-	pub(super) type Allowance<T: Config> = StorageNMap<
+	pub type Allowance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
 			Key<Twox64Concat, TokenId>,