git.delta.rocks / unique-network / refs/commits / 7ff84981c059

difftreelog

Merge branch 'develop' into feature/NFTPAR-142

sotmorskiy2020-12-03parents: #d4ad9e6 #82ca9c1.patch.diff
in: master
# Conflicts:
#	pallets/nft/src/lib.rs

5 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3737,7 +3737,10 @@
  "frame-support",
  "frame-system",
  "log",
+ "pallet-balances",
  "pallet-contracts",
+ "pallet-randomness-collective-flip",
+ "pallet-timestamp",
  "pallet-transaction-payment",
  "parity-scale-codec",
  "serde",
modifiedpallets/nft/src/default_weights.rsdiffbeforeafterboth
--- a/pallets/nft/src/default_weights.rs
+++ b/pallets/nft/src/default_weights.rs
@@ -107,9 +107,19 @@
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
+    // fn set_chain_limits() -> Weight {
+    //     (0 as Weight)
+    //         .saturating_add(DbWeight::get().reads(1 as Weight))
+    //         .saturating_add(DbWeight::get().writes(1 as Weight))
+    // }
     // fn enable_contract_sponsoring() -> Weight {
     //     (0 as Weight)
     //         .saturating_add(DbWeight::get().reads(1 as Weight))
     //         .saturating_add(DbWeight::get().writes(1 as Weight))
     // }
+    // fn set_contract_sponsoring_rate_limit() -> Weight {
+    //     (0 as Weight)
+    //         .saturating_add(DbWeight::get().reads(1 as Weight))
+    //         .saturating_add(DbWeight::get().writes(1 as Weight))
+    // }
 }
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
378 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;378 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): double_map hasher(blake2_128_concat) u64, hasher(blake2_128_concat) u64 => T::BlockNumber;
379379
380 // Contract Sponsorship and Ownership380 // Contract Sponsorship and Ownership
381 pub ContractOwner get(fn contract_owner): map hasher(identity) T::AccountId => T::AccountId;381 pub ContractOwner get(fn contract_owner): map hasher(twox_64_concat) T::AccountId => T::AccountId;
382 pub ContractSelfSponsoring get(fn contract_self_sponsoring): map hasher(identity) T::AccountId => bool;382 pub ContractSelfSponsoring get(fn contract_self_sponsoring): map hasher(twox_64_concat) T::AccountId => bool;
383 pub ContractSponsorBasket get(fn contract_sponsor_basket): map hasher(twox_64_concat) T::AccountId => T::BlockNumber;
384 pub ContractSponsoringRateLimit get(fn contract_sponsoring_rate_limit): map hasher(twox_64_concat) T::AccountId => T::BlockNumber;
383 }385 }
384 add_extra_genesis {386 add_extra_genesis {
385 build(|config: &GenesisConfig<T>| {387 build(|config: &GenesisConfig<T>| {
1336 Ok(())1338 Ok(())
1337 }1339 }
1340
1341 /// Set the rate limit for contract sponsoring to specified number of blocks.
1342 ///
1343 /// If not set (has the default value of 0 blocks), the sponsoring will be disabled.
1344 /// If set to the number B (for blocks), the transactions will be sponsored with a rate
1345 /// limit of B, i.e. fees for every transaction sent to this smart contract will be paid
1346 /// from contract endowment if there are at least B blocks between such transactions.
1347 /// Nonetheless, if transactions are sent more frequently, the fees are paid by the sender.
1348 ///
1349 /// # Permissions
1350 ///
1351 /// * Contract Owner
1352 ///
1353 /// # Arguments
1354 ///
1355 /// -`contract_address`: Address of the contract to sponsor
1356 /// -`rate_limit`: Number of blocks to wait until the next sponsored transaction is allowed
1357 ///
1358 #[weight = 0]
1359 pub fn set_contract_sponsoring_rate_limit(
1360 origin,
1361 contract_address: T::AccountId,
1362 rate_limit: T::BlockNumber
1363 ) -> DispatchResult {
1364 let sender = ensure_signed(origin)?;
1365 let mut is_owner = false;
1366 if <ContractOwner<T>>::contains_key(contract_address.clone()) {
1367 let owner = <ContractOwner<T>>::get(&contract_address);
1368 is_owner = sender == owner;
1369 }
1370 ensure!(is_owner, Error::<T>::NoPermission);
1371
1372 <ContractSponsoringRateLimit<T>>::insert(contract_address, rate_limit);
1373 Ok(())
1374 }
1375
1338 }1376 }
1339}1377}
2242 // When the contract is called, check if the sponsoring is enabled and pay fees from contract endowment if it is2280 // When the contract is called, check if the sponsoring is enabled and pay fees from contract endowment if it is
2243 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {2281 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {
22442282
2283 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());
2284
2285 let mut sponsor_transfer = false;
2286 if <ContractSponsoringRateLimit<T>>::contains_key(called_contract.clone()) {
2287 let last_tx_block = <ContractSponsorBasket<T>>::get(&called_contract);
2288 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;
2289 let rate_limit = <ContractSponsoringRateLimit<T>>::get(&called_contract);
2290 let limit_time = last_tx_block + rate_limit;
2291
2292 if block_number >= limit_time {
2293 <ContractSponsorBasket<T>>::insert(called_contract.clone(), block_number);
2294 sponsor_transfer = true;
2295 }
2296 } else {
2297 sponsor_transfer = false;
2298 }
2299
2300
2245 let mut sp = T::AccountId::default();2301 let mut sp = T::AccountId::default();
2246 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());2302 if sponsor_transfer {
2247 if <ContractSelfSponsoring<T>>::contains_key(called_contract.clone()) {2303 if <ContractSelfSponsoring<T>>::contains_key(called_contract.clone()) {
2248 if <ContractSelfSponsoring<T>>::get(called_contract.clone()) {2304 if <ContractSelfSponsoring<T>>::get(called_contract.clone()) {
2249 sp = called_contract;2305 sp = called_contract;
2250 }2306 }
2251 }2307 }
2308 }
22522309
2253 sp2310 sp
2254 },2311 },
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -1,6 +1,8 @@
 // Tests to be written here
+use super::*;
 use crate::mock::*;
-use crate::{AccessMode, ApprovePermissions, CollectionMode, Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData};
+use crate::{AccessMode, ApprovePermissions, CollectionMode,
+     Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData}; //Err
 use frame_support::{assert_noop, assert_ok};
 use frame_system::{ RawOrigin };
 
@@ -392,7 +394,7 @@
             2,
             1,
             1,
-            1), "Only item owner, collection owner and admins can modify items");
+            1), Error::<Test>::NoPermission);
 
         // do approve
         assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));
@@ -672,7 +674,7 @@
         assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
         assert_noop!(
             TemplateModule::burn_item(origin1.clone(), 1, 1),
-            "Item does not exists"
+            Error::<Test>::TokenNotFound
         );
 
         assert_eq!(TemplateModule::balance_count(1, 1), 0);
@@ -699,7 +701,7 @@
         assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
         assert_noop!(
             TemplateModule::burn_item(origin1.clone(), 1, 1),
-            "Item does not exists"
+            Error::<Test>::TokenNotFound
         );
 
         assert_eq!(TemplateModule::balance_count(1, 1), 0);
@@ -738,7 +740,7 @@
         assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));
         assert_noop!(
             TemplateModule::burn_item(origin1.clone(), 1, 1),
-            "Item does not exists"
+            Error::<Test>::TokenNotFound
         );
 
         assert_eq!(TemplateModule::balance_count(1, 1), 0);
@@ -933,7 +935,7 @@
         let origin2 = Origin::signed(2);
         assert_noop!(
             TemplateModule::add_to_white_list(origin2.clone(), collection_id, 3),
-            "You do not have permissions to modify this collection"
+            Error::<Test>::NoPermission
         );
     });
 }
@@ -947,7 +949,7 @@
 
         assert_noop!(
             TemplateModule::add_to_white_list(origin1.clone(), 1, 2),
-            "This collection does not exist"
+            Error::<Test>::CollectionNotFound
         );
     });
 }
@@ -963,7 +965,7 @@
         assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));
         assert_noop!(
             TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2),
-            "This collection does not exist"
+            Error::<Test>::CollectionNotFound
         );
     });
 }
@@ -1035,7 +1037,7 @@
         assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));
         assert_noop!(
             TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 2),
-            "You do not have permissions to modify this collection"
+            Error::<Test>::NoPermission
         );
         assert_eq!(TemplateModule::white_list(collection_id)[0], 2);
     });
@@ -1049,7 +1051,7 @@
 
         assert_noop!(
             TemplateModule::remove_from_white_list(origin1.clone(), 1, 2),
-            "This collection does not exist"
+            Error::<Test>::CollectionNotFound
         );
     });
 }
@@ -1067,7 +1069,7 @@
         assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));
         assert_noop!(
             TemplateModule::remove_from_white_list(origin2.clone(), collection_id, 2),
-            "This collection does not exist"
+            Error::<Test>::CollectionNotFound
         );
         assert_eq!(TemplateModule::white_list(collection_id).len(), 0);
     });
@@ -1119,7 +1121,7 @@
 
         assert_noop!(
             TemplateModule::transfer(origin1.clone(), 3, 1, 1, 1),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1155,7 +1157,7 @@
 
         assert_noop!(
             TemplateModule::transfer_from(origin1.clone(), 1, 3, 1, 1, 1),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1182,7 +1184,7 @@
 
         assert_noop!(
             TemplateModule::transfer(origin1.clone(), 3, 1, 1, 1),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1219,7 +1221,7 @@
 
         assert_noop!(
             TemplateModule::transfer_from(origin1.clone(), 1, 3, 1, 1, 1),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1244,7 +1246,7 @@
         ));
         assert_noop!(
             TemplateModule::burn_item(origin1.clone(), 1, 1),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1267,7 +1269,7 @@
         // do approve
         assert_noop!(
             TemplateModule::approve(origin1.clone(), 1, 1, 1),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1416,7 +1418,7 @@
 
         assert_noop!(
             TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),
-            "Public minting is not allowed for this collection"
+            Error::<Test>::PublicMintingNotAllowed
         );
     });
 }
@@ -1445,7 +1447,7 @@
 
         assert_noop!(
             TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),
-            "Public minting is not allowed for this collection"
+            Error::<Test>::PublicMintingNotAllowed
         );
     });
 }
@@ -1533,7 +1535,7 @@
 
         assert_noop!(
             TemplateModule::create_item(origin2.clone(), 1, 2, default_nft_data().into()),
-            "Address is not in white list"
+            Error::<Test>::AddresNotInWhiteList
         );
     });
 }
@@ -1603,7 +1605,7 @@
             col_desc1.clone(),
             token_prefix1.clone(),
             CollectionMode::NFT
-        ), "Total collections bound exceeded");
+        ), Error::<Test>::TotalCollectionsLimitExceeded);
     });
 }
 
@@ -1646,7 +1648,7 @@
             1,
             1,
             data.into()
-        ), "Owned tokens by a single address bound exceeded");
+        ),  Error::<Test>::AddressOwnershipLimitExceeded);
     });
 }
 
@@ -1692,7 +1694,7 @@
         let origin1 = Origin::signed(1);
 
         assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 2));
-        assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3), "Number of collection admins bound exceeded");
+        assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, 3), Error::<Test>::CollectionAdminsLimitExceeded);
     });
 }
 
modifiedruntime/src/nft_weights.rsdiffbeforeafterboth
--- a/runtime/src/nft_weights.rs
+++ b/runtime/src/nft_weights.rs
@@ -108,4 +108,19 @@
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
+    // fn set_chain_limits() -> Weight {
+    //     (0 as Weight)
+    //         .saturating_add(DbWeight::get().reads(1 as Weight))
+    //         .saturating_add(DbWeight::get().writes(1 as Weight))
+    // }
+    // fn enable_contract_sponsoring() -> Weight {
+    //     (0 as Weight)
+    //         .saturating_add(DbWeight::get().reads(1 as Weight))
+    //         .saturating_add(DbWeight::get().writes(1 as Weight))
+    // }
+    // fn set_contract_sponsoring_rate_limit() -> Weight {
+    //     (0 as Weight)
+    //         .saturating_add(DbWeight::get().reads(1 as Weight))
+    //         .saturating_add(DbWeight::get().writes(1 as Weight))
+    // }
 }