git.delta.rocks / unique-network / refs/commits / 6f9cded09d5c

difftreelog

feat explicit collection creation fee

Yaroslav Bolyukin2021-03-17parent: #5df4938.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -20,7 +20,7 @@
     ensure, fail, parameter_types,
     traits::{
         Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,
-        Randomness, IsSubType,
+        Randomness, IsSubType, WithdrawReasons,
     },
     weights::{
         constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
@@ -435,7 +435,9 @@
     /// Weight information for extrinsics in this pallet.
 	type WeightInfo: WeightInfo;
 
-    type CollectionCreationPrice: Get<BalanceOf<Self>>;
+    type Currency: Currency<Self::AccountId>;
+    type CollectionCreationPrice: Get<<<Self as Config>::Currency as Currency<Self::AccountId>>::Balance>;
+    type TreasuryAccountId: Get<Self::AccountId>;
 }
 
 #[cfg(feature = "runtime-benchmarks")]
@@ -663,6 +665,18 @@
             // Anyone can create a collection
             let who = ensure_signed(origin)?;
 
+            let mut imbalance = <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();
+            imbalance.subsume(<<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(
+                &T::TreasuryAccountId::get(),
+                T::CollectionCreationPrice::get(),
+            ));
+            <T as Config>::Currency::settle(
+                &who,
+                imbalance,
+                WithdrawReasons::TRANSFER,
+                ExistenceRequirement::KeepAlive,
+            ).map_err(|_| Error::<T>::NoPermission)?;
+
             let decimal_points = match mode {
                 CollectionMode::Fungible(points) => points,
                 _ => 0
@@ -2537,10 +2551,7 @@
 	> {
         let tip = self.0;
 
-        let fee = match call.is_sub_type() {
-            Some(Call::create_collection(..)) => T::CollectionCreationPrice::get(),
-            _ => Self::traditional_fee(len, info, tip),
-        };
+        let fee = Self::traditional_fee(len, info, tip);
 
         // Only mess with balances if fee is not zero.
         if fee.is_zero() {
modifiedruntime/src/lib.rsdiffbeforeafterboth
24 create_runtime_str, generic, impl_opaque_keys,24 create_runtime_str, generic, impl_opaque_keys,
25 traits::{25 traits::{
26 Convert, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, 26 Convert, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount,
27 IdentityLookup, NumberFor, Verify,27 IdentityLookup, NumberFor, Verify, AccountIdConversion,
28 },28 },
29 transaction_validity::{TransactionSource, TransactionValidity},29 transaction_validity::{TransactionSource, TransactionValidity},
30 ApplyExtrinsicResult, MultiSignature,30 ApplyExtrinsicResult, MultiSignature,
510510
511parameter_types! {511parameter_types! {
512 pub const MinVestedTransfer: Balance = 10 * UNIQUE;512 pub const MinVestedTransfer: Balance = 10 * UNIQUE;
513 pub const CollectionCreationPrice: Balance = 100 * UNIQUE;
514}513}
515514
516impl pallet_vesting::Config for Runtime {515impl pallet_vesting::Config for Runtime {
521 type WeightInfo = ();520 type WeightInfo = ();
522}521}
522
523parameter_types! {
524 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();
525 pub const CollectionCreationPrice: Balance = 100 * UNIQUE;
526}
523527
524/// Used for the module nft in `./nft.rs`528/// Used for the module nft in `./nft.rs`
525impl pallet_nft::Config for Runtime {529impl pallet_nft::Config for Runtime {
526 type Event = Event;530 type Event = Event;
527 type WeightInfo = nft_weights::WeightInfo;531 type WeightInfo = nft_weights::WeightInfo;
532 type Currency = Balances;
528 type CollectionCreationPrice = CollectionCreationPrice;533 type CollectionCreationPrice = CollectionCreationPrice;
534 type TreasuryAccountId = TreasuryAccountId;
529}535}
530536
531construct_runtime!(537construct_runtime!(