git.delta.rocks / unique-network / refs/commits / 8bbc7539fcb3

difftreelog

CORE-178

str-mv2022-04-08parent: #219f5f0.patch.diff
in: master

7 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
120 #[rpc(name = "unique_collectionStats")]120 #[rpc(name = "unique_collectionStats")]
121 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;121 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;
122
123 #[rpc(name = "unique_nextSponsored")]
124 fn next_sponsored(
125 &self,
126 collection: CollectionId,
127 account: CrossAccountId,
128 token: TokenId,
129 at: Option<BlockHash>,
130 ) -> Result<Option<u64>>;
122}131}
123132
124pub struct Unique<C, P> {133pub struct Unique<C, P> {
222 pass_method!(last_token_id(collection: CollectionId) -> TokenId);231 pass_method!(last_token_id(collection: CollectionId) -> TokenId);
223 pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);232 pass_method!(collection_by_id(collection: CollectionId) -> Option<Collection<AccountId>>);
224 pass_method!(collection_stats() -> CollectionStats);233 pass_method!(collection_stats() -> CollectionStats);
234 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>);
225}235}
226236
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
6969
70mod eth;70mod eth;
71mod sponsorship;71mod sponsorship;
72pub use sponsorship::UniqueSponsorshipHandler;72pub use sponsorship::{UniqueSponsorshipHandler, UniqueSponsorshipPredict};
73pub use eth::sponsoring::UniqueEthSponsorshipHandler;73pub use eth::sponsoring::UniqueEthSponsorshipHandler;
7474
75pub use eth::UniqueErcSupport;75pub use eth::UniqueErcSupport;
84pub mod weights;84pub mod weights;
85use weights::WeightInfo;85use weights::WeightInfo;
86
87pub trait SponsorshipPredict<T: Config> {
88 fn predict(collection: CollectionId, account: T::CrossAccountId, token: TokenId) -> Option<u64>
89 where
90 u64: From<<T as frame_system::Config>::BlockNumber>;
91}
8692
87decl_error! {93decl_error! {
88 /// Error for non-fungible-token module.94 /// Error for non-fungible-token module.
modifiedpallets/unique/src/sponsorship.rsdiffbeforeafterboth
302 }302 }
303}303}
304
305use crate::SponsorshipPredict;
306use up_data_structs::SponsorshipState;
307pub struct UniqueSponsorshipPredict<T>(PhantomData<T>);
308
309impl<T> SponsorshipPredict<T> for UniqueSponsorshipPredict<T>
310where
311 T: Config,
312{
313 fn predict(collection_id: CollectionId, who: T::CrossAccountId, token: TokenId) -> Option<u64>
314 where
315 u64: From<<T as frame_system::Config>::BlockNumber>,
316 {
317 let collection = <CollectionHandle<T>>::try_get(collection_id).ok()?;
318
319 // preliminary sponsoring correctness check
320 match collection.sponsorship {
321 SponsorshipState::Disabled | SponsorshipState::Unconfirmed(_) => return None,
322 _ => (),
323 }
324
325 // sponsor timeout
326 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
327 let limit = collection
328 .limits
329 .sponsor_transfer_timeout(match collection.mode {
330 CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,
331 CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
332 CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
333 });
334
335 let last_tx_block = match collection.mode {
336 CollectionMode::NFT => <NftTransferBasket<T>>::get(collection.id, token),
337 CollectionMode::Fungible(_) => {
338 <FungibleTransferBasket<T>>::get(collection.id, who.as_sub())
339 }
340 CollectionMode::ReFungible => {
341 <ReFungibleTransferBasket<T>>::get((collection.id, token, who.as_sub()))
342 }
343 };
344
345 if let Some(last_tx_block) = last_tx_block {
346 let timeout = last_tx_block + limit.into();
347 if block_number < timeout {
348 return Some((timeout - block_number).into());
349 }
350 return Some(0);
351 }
352
353 let token_exists = match collection.mode {
354 CollectionMode::NFT => {
355 <pallet_nonfungible::TokenData<T>>::contains_key((collection.id, token))
356 }
357 CollectionMode::Fungible(_) => true,
358 CollectionMode::ReFungible => {
359 <pallet_refungible::TotalSupply<T>>::contains_key((collection.id, token))
360 }
361 };
362
363 if token_exists {
364 Some(0)
365 } else {
366 None
367 }
368
369 // // existance check
370 // match collection.mode {
371 // CollectionMode::NFT => <NftTransferBasket<T>>::get(collection.id, token),
372 // CollectionMode::Fungible(_) => {
373 // <FungibleTransferBasket<T>>::get(collection.id, who.as_sub())
374 // }
375 // CollectionMode::ReFungible => {
376 // <ReFungibleTransferBasket<T>>::get((collection.id, token, who.as_sub()))
377 // }
378 // };
379 }
380}
304381
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
59 fn last_token_id(collection: CollectionId) -> Result<TokenId>;59 fn last_token_id(collection: CollectionId) -> Result<TokenId>;
60 fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>>;60 fn collection_by_id(collection: CollectionId) -> Result<Option<Collection<AccountId>>>;
61 fn collection_stats() -> Result<CollectionStats>;61 fn collection_stats() -> Result<CollectionStats>;
62 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
62 }63 }
63}64}
6465
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
69 fn collection_stats() -> Result<CollectionStats, DispatchError> {69 fn collection_stats() -> Result<CollectionStats, DispatchError> {
70 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())70 Ok(<pallet_common::Pallet<Runtime>>::collection_stats())
71 }71 }
72 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>, DispatchError> {
73 Ok(<pallet_unique::UniqueSponsorshipPredict<Runtime> as
74 pallet_unique::SponsorshipPredict<Runtime>>::predict(
75 collection,
76 account,
77 token))
78 }
72 }79 }
7380
74 impl sp_api::Core<Block> for Runtime {81 impl sp_api::Core<Block> for Runtime {
modifiedtests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth
619 * Get token variable metadata619 * Get token variable metadata
620 **/620 **/
621 variableMetadata: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Bytes>>;621 variableMetadata: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Bytes>>;
622 /**
623 * nextSponsored transaction
624 **/
625 nextSponsored: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, account: PalletCommonAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<u64>>>;
622 };626 };
623 web3: {627 web3: {
624 /**628 /**
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
55 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsCollection>'),55 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsCollection>'),
56 collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),56 collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),
57 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),57 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),
58 nextSponsored: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam(), tokenParam], 'Option<u64>'),
58 },59 },
59};60};
6061