difftreelog
Public storage
in: master
3 files changed
pallets/nft/src/sponsorship.rsdiffbeforeafterboth1use crate::{2 Config, Call, CreateItemBasket, VariableMetaDataBasket, ReFungibleTransferBasket,3 FungibleTransferBasket, NftTransferBasket, CreateItemData, CollectionMode, NftApproveBasket,4 FungibleApproveBasket, RefungibleApproveBasket,5};6use core::marker::PhantomData;7use up_sponsorship::SponsorshipHandler;8use frame_support::{9 traits::{IsSubType},10 storage::{StorageMap, StorageDoubleMap, StorageNMap},11};12use nft_data_structs::{13 CollectionId, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, NFT_SPONSOR_TRANSFER_TIMEOUT,14 REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, TokenId,15};16use pallet_common::{CollectionHandle};17use pallet_common::account::CrossAccountId;1819pub fn withdraw_transfer<T: Config>(20 collection: &CollectionHandle<T>,21 who: &T::AccountId,22 item_id: &TokenId,23) -> Option<()> {2425 // preliminary sponsoring correctness check26 if !((pallet_nonfungible::TokenData::<T>::get((collection.id, item_id))?.owner).as_sub()27 == who) || (pallet_refungible::Owned::<T>::get((28 collection.id,29 T::CrossAccountId::from_sub(who.clone()),30 item_id,31 ))) {32 return None;33 }34 35 // sponsor timeout36 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;37 let limit = collection38 .limits39 .sponsor_transfer_timeout(match collection.mode {40 CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,41 CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,42 CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,43 });4445 let last_tx_block = match collection.mode {46 CollectionMode::NFT => <NftTransferBasket<T>>::get(collection.id, item_id),47 CollectionMode::Fungible(_) => <FungibleTransferBasket<T>>::get(collection.id, who),48 CollectionMode::ReFungible => {49 <ReFungibleTransferBasket<T>>::get((collection.id, item_id, who))50 }51 };5253 if let Some(last_tx_block) = last_tx_block {54 let timeout = last_tx_block + limit.into();55 if block_number < timeout {56 return None;57 }58 }5960 match collection.mode {61 CollectionMode::NFT => <NftTransferBasket<T>>::insert(collection.id, item_id, block_number),62 CollectionMode::Fungible(_) => {63 <FungibleTransferBasket<T>>::insert(collection.id, who, block_number)64 }65 CollectionMode::ReFungible => {66 <ReFungibleTransferBasket<T>>::insert((collection.id, item_id, who), block_number)67 }68 };6970 Some(())71}7273pub fn withdraw_create_item<T: Config>(74 collection: &CollectionHandle<T>,75 who: &T::AccountId,76 _properties: &CreateItemData,77) -> Option<()> {78 if _properties.data_size() as u32 > collection.limits.sponsored_data_size() {79 return None;80 }8182 // sponsor timeout83 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;84 let limit = collection85 .limits86 .sponsor_transfer_timeout(match _properties {87 CreateItemData::NFT(_) => NFT_SPONSOR_TRANSFER_TIMEOUT,88 CreateItemData::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,89 CreateItemData::ReFungible(_) => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,90 });9192 if let Some(last_tx_block) = <CreateItemBasket<T>>::get((collection.id, &who)) {93 let timeout = last_tx_block + limit.into();94 if block_number < timeout {95 return None;96 }97 }9899 CreateItemBasket::<T>::insert((collection.id, who.clone()), block_number);100101 Some(())102}103104pub fn withdraw_set_variable_meta_data<T: Config>(105 who: &T::AccountId,106 collection: &CollectionHandle<T>,107 item_id: &TokenId,108 data: &[u8],109) -> Option<()> {110111 // preliminary sponsoring correctness check112 if !((pallet_nonfungible::TokenData::<T>::get((collection.id, item_id))?.owner).as_sub()113 == who) || (pallet_refungible::Owned::<T>::get((114 collection.id,115 T::CrossAccountId::from_sub(who.clone()),116 item_id,117 ))) {118 return None;119 }120121 // Can't sponsor fungible collection, this tx will be rejected122 // as invalid123 if matches!(collection.mode, CollectionMode::Fungible(_)) {124 return None;125 }126 if data.len() > collection.limits.sponsored_data_size() as usize {127 return None;128 }129130 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;131 let limit = collection.limits.sponsored_data_rate_limit()?;132133 if let Some(last_tx_block) = VariableMetaDataBasket::<T>::get(collection.id, item_id) {134 let timeout = last_tx_block + limit.into();135 if block_number < timeout {136 return None;137 }138 }139140 <VariableMetaDataBasket<T>>::insert(collection.id, item_id, block_number);141142 Some(())143}144145pub fn withdraw_approve<T: Config>(146 collection: &CollectionHandle<T>,147 who: &T::AccountId,148 item_id: &TokenId,149) -> Option<()> {150 // sponsor timeout151 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;152 let limit = collection.limits.sponsor_approve_timeout();153154 let last_tx_block = match collection.mode {155 CollectionMode::NFT => <NftApproveBasket<T>>::get(collection.id, item_id),156 CollectionMode::Fungible(_) => <FungibleApproveBasket<T>>::get(collection.id, who),157 CollectionMode::ReFungible => {158 <RefungibleApproveBasket<T>>::get((collection.id, item_id, who))159 }160 };161162 if let Some(last_tx_block) = last_tx_block {163 let timeout = last_tx_block + limit.into();164 if block_number < timeout {165 return None;166 }167 }168169 match collection.mode {170 CollectionMode::NFT => <NftApproveBasket<T>>::insert(collection.id, item_id, block_number),171 CollectionMode::Fungible(_) => {172 <FungibleApproveBasket<T>>::insert(collection.id, who, block_number)173 }174 CollectionMode::ReFungible => {175 <RefungibleApproveBasket<T>>::insert((collection.id, item_id, who), block_number)176 }177 };178179 Some(())180}181182fn load<T: Config>(id: CollectionId) -> Option<(T::AccountId, CollectionHandle<T>)> {183 let collection = CollectionHandle::new(id)?;184 let sponsor = collection.sponsorship.sponsor().cloned()?;185 Some((sponsor, collection))186}187188pub struct NftSponsorshipHandler<T>(PhantomData<T>);189impl<T, C> SponsorshipHandler<T::AccountId, C> for NftSponsorshipHandler<T>190where191 T: Config,192 C: IsSubType<Call<T>>,193{194 fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {195 match IsSubType::<Call<T>>::is_sub_type(call)? {196 Call::create_item {197 collection_id,198 data,199 ..200 } => {201 let (sponsor, collection) = load(*collection_id)?;202 withdraw_create_item::<T>(&collection, who, data).map(|()| sponsor)203 }204 Call::transfer {205 collection_id,206 item_id,207 ..208 }209 | Call::transfer_from {210 collection_id,211 item_id,212 ..213 } => {214 let (sponsor, collection) = load(*collection_id)?;215 withdraw_transfer::<T>(&collection, who, item_id).map(|()| sponsor)216 }217 Call::approve {218 collection_id,219 item_id,220 ..221 } => {222 let (sponsor, collection) = load(*collection_id)?;223 withdraw_approve::<T>(&collection, who, item_id).map(|()| sponsor)224 }225 Call::set_variable_meta_data {226 collection_id,227 item_id,228 data,229 } => {230 let (sponsor, collection) = load(*collection_id)?;231 withdraw_set_variable_meta_data::<T>(&who, &collection, item_id, data).map(|()| sponsor)232 }233 _ => None,234 }235 }236}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.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>,