From f8774b896e5b387fe4e1171ec0f9c8ce551bbbd6 Mon Sep 17 00:00:00 2001 From: str-mv Date: Mon, 22 Nov 2021 16:38:11 +0000 Subject: [PATCH] Public storage --- --- 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( collection: &CollectionHandle, who: &T::AccountId, item_id: &TokenId, ) -> Option<()> { + + // preliminary sponsoring correctness check + if !((pallet_nonfungible::TokenData::::get((collection.id, item_id))?.owner).as_sub() + == who) || (pallet_refungible::Owned::::get(( + collection.id, + T::CrossAccountId::from_sub(who.clone()), + item_id, + ))) { + return None; + } + // sponsor timeout let block_number = >::block_number() as T::BlockNumber; let limit = collection @@ -90,10 +102,22 @@ } pub fn withdraw_set_variable_meta_data( + who: &T::AccountId, collection: &CollectionHandle, item_id: &TokenId, data: &[u8], ) -> Option<()> { + + // preliminary sponsoring correctness check + if !((pallet_nonfungible::TokenData::::get((collection.id, item_id))?.owner).as_sub() + == who) || (pallet_refungible::Owned::::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::(&collection, item_id, data).map(|()| sponsor) + withdraw_set_variable_meta_data::(&who, &collection, item_id, data).map(|()| sponsor) } _ => None, } --- 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(_); #[pallet::storage] - pub(super) type TokensMinted = + pub type TokensMinted = StorageMap; #[pallet::storage] - pub(super) type TokensBurnt = + pub type TokensBurnt = StorageMap; #[pallet::storage] - pub(super) type TokenData = StorageNMap< + pub type TokenData = StorageNMap< Key = (Key, Key), Value = ItemData, QueryKind = OptionQuery, @@ -77,7 +77,7 @@ /// Used to enumerate tokens owned by account #[pallet::storage] - pub(super) type Owned = StorageNMap< + pub type Owned = StorageNMap< Key = ( Key, Key, @@ -88,7 +88,7 @@ >; #[pallet::storage] - pub(super) type AccountBalance = StorageNMap< + pub type AccountBalance = StorageNMap< Key = ( Key, Key, @@ -98,7 +98,7 @@ >; #[pallet::storage] - pub(super) type Allowance = StorageNMap< + pub type Allowance = StorageNMap< Key = (Key, Key), Value = T::CrossAccountId, QueryKind = OptionQuery, --- 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(_); #[pallet::storage] - pub(super) type TokensMinted = + pub type TokensMinted = StorageMap; #[pallet::storage] - pub(super) type TokensBurnt = + pub type TokensBurnt = StorageMap; #[pallet::storage] - pub(super) type TokenData = StorageNMap< + pub type TokenData = StorageNMap< Key = (Key, Key), Value = ItemData, QueryKind = ValueQuery, >; #[pallet::storage] - pub(super) type TotalSupply = StorageNMap< + pub type TotalSupply = StorageNMap< Key = (Key, Key), Value = u128, QueryKind = ValueQuery, @@ -80,7 +80,7 @@ /// Used to enumerate tokens owned by account #[pallet::storage] - pub(super) type Owned = StorageNMap< + pub type Owned = StorageNMap< Key = ( Key, Key, @@ -91,7 +91,7 @@ >; #[pallet::storage] - pub(super) type AccountBalance = StorageNMap< + pub type AccountBalance = StorageNMap< Key = ( Key, // Owner @@ -102,7 +102,7 @@ >; #[pallet::storage] - pub(super) type Balance = StorageNMap< + pub type Balance = StorageNMap< Key = ( Key, Key, @@ -114,7 +114,7 @@ >; #[pallet::storage] - pub(super) type Allowance = StorageNMap< + pub type Allowance = StorageNMap< Key = ( Key, Key, -- gitstuff