difftreelog
Public storage
in: master
3 files changed
pallets/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,
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -58,18 +58,18 @@
}
#[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<T>,
QueryKind = OptionQuery,
@@ -77,7 +77,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>,
@@ -88,7 +88,7 @@
>;
#[pallet::storage]
- pub(super) type AccountBalance<T: Config> = StorageNMap<
+ pub type AccountBalance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -98,7 +98,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = T::CrossAccountId,
QueryKind = OptionQuery,
pallets/refungible/src/lib.rsdiffbeforeafterboth54 }54 }555556 #[pallet::pallet]56 #[pallet::pallet]57 #[pallet::generate_store(pub(super) trait Store)]57 #[pallet::generate_store(pub trait Store)]58 pub struct Pallet<T>(_);58 pub struct Pallet<T>(_);595960 #[pallet::storage]60 #[pallet::storage]61 pub(super) type TokensMinted<T: Config> =61 pub type TokensMinted<T: Config> =62 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;62 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;63 #[pallet::storage]63 #[pallet::storage]64 pub(super) type TokensBurnt<T: Config> =64 pub type TokensBurnt<T: Config> =65 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;65 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;666667 #[pallet::storage]67 #[pallet::storage]68 pub(super) type TokenData<T: Config> = StorageNMap<68 pub type TokenData<T: Config> = StorageNMap<69 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),69 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),70 Value = ItemData,70 Value = ItemData,71 QueryKind = ValueQuery,71 QueryKind = ValueQuery,72 >;72 >;737374 #[pallet::storage]74 #[pallet::storage]75 pub(super) type TotalSupply<T: Config> = StorageNMap<75 pub type TotalSupply<T: Config> = StorageNMap<76 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),76 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),77 Value = u128,77 Value = u128,78 QueryKind = ValueQuery,78 QueryKind = ValueQuery,79 >;79 >;808081 /// Used to enumerate tokens owned by account81 /// Used to enumerate tokens owned by account82 #[pallet::storage]82 #[pallet::storage]83 pub(super) type Owned<T: Config> = StorageNMap<83 pub type Owned<T: Config> = StorageNMap<84 Key = (84 Key = (85 Key<Twox64Concat, CollectionId>,85 Key<Twox64Concat, CollectionId>,86 Key<Blake2_128Concat, T::CrossAccountId>,86 Key<Blake2_128Concat, T::CrossAccountId>,91 >;91 >;929293 #[pallet::storage]93 #[pallet::storage]94 pub(super) type AccountBalance<T: Config> = StorageNMap<94 pub type AccountBalance<T: Config> = StorageNMap<95 Key = (95 Key = (96 Key<Twox64Concat, CollectionId>,96 Key<Twox64Concat, CollectionId>,97 // Owner97 // Owner102 >;102 >;103103104 #[pallet::storage]104 #[pallet::storage]105 pub(super) type Balance<T: Config> = StorageNMap<105 pub type Balance<T: Config> = StorageNMap<106 Key = (106 Key = (107 Key<Twox64Concat, CollectionId>,107 Key<Twox64Concat, CollectionId>,108 Key<Twox64Concat, TokenId>,108 Key<Twox64Concat, TokenId>,114 >;114 >;115115116 #[pallet::storage]116 #[pallet::storage]117 pub(super) type Allowance<T: Config> = StorageNMap<117 pub type Allowance<T: Config> = StorageNMap<118 Key = (118 Key = (119 Key<Twox64Concat, CollectionId>,119 Key<Twox64Concat, CollectionId>,120 Key<Twox64Concat, TokenId>,120 Key<Twox64Concat, TokenId>,