Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into rework/rmrk-as-trait
  • Loading branch information
bmacer committed Dec 17, 2021
commit 3c8b113d9fa0d01ca3dc3d7d6e089c7f9f0ad89e
16 changes: 8 additions & 8 deletions pallets/rmrk-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use sp_std::{convert::TryInto, vec, vec::Vec};
use types::{ClassInfo, ResourceInfo};

use rmrk_traits::{AccountIdOrCollectionNftTuple, Collection, CollectionInfo, Nft, NftInfo};
use sp_std::result::Result;

mod functions;

Expand Down Expand Up @@ -257,8 +258,8 @@ pub mod pallet {
origin: OriginFor<T>,
owner: T::AccountId,
collection_id: T::CollectionId,
recipient: T::AccountId,
royalty: Permill,
recipient: Option<T::AccountId>,
royalty: Option<Permill>,
metadata: BoundedVec<u8, T::StringLimit>,
) -> DispatchResult {
let sender = match T::ProtocolOrigin::try_origin(origin) {
Expand Down Expand Up @@ -713,14 +714,13 @@ impl<T: Config> Collection<StringLimitOf<T>, T::AccountId> for Pallet<T> {
symbol: StringLimitOf<T>,
) -> Result<Self::CollectionId, DispatchError> {
let collection = CollectionInfo { issuer: issuer.clone(), metadata, max, symbol };
let collection_id = <CollectionIndex<T>>::try_mutate(
|n| -> Result<Self::CollectionId, DispatchError> {
let collection_id =
<CollectionIndex<T>>::try_mutate(|n| -> Result<Self::CollectionId, DispatchError> {
let id = *n;
ensure!(id != Self::CollectionId::max_value(), Error::<T>::NoAvailableCollectionId);
*n += One::one();
Ok(id)
},
)?;
})?;
Collections::<T>::insert(collection_id, collection);
Ok(collection_id)
}
Expand Down Expand Up @@ -793,8 +793,8 @@ impl<T: Config> Nft<T::AccountId, StringLimitOf<T>> for Pallet<T> {
Error::<T>::CollectionFullOrLocked
);

let recipient = recipient.ok_or(Error::<T>::RecipientNotSet)?;
let royalty = royalty.ok_or(Error::<T>::RoyaltyNotSet)?;
let recipient = recipient.unwrap_or(owner.clone());
let royalty = royalty.unwrap_or(Permill::from_float(0.0));

let rootowner = owner.clone();
let owner_as_maybe_account = AccountIdOrCollectionNftTuple::AccountId(owner.clone());
Expand Down
128 changes: 64 additions & 64 deletions pallets/rmrk-core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,33 @@ fn mint_nft_works() {
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(20.525),
Some(ALICE),
Some(Permill::from_float(20.525)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(20.525),
Some(ALICE),
Some(Permill::from_float(20.525)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::mint_nft(
Origin::signed(BOB),
BOB,
COLLECTION_ID_0,
CHARLIE,
Permill::from_float(20.525),
Some(CHARLIE),
Some(Permill::from_float(20.525)),
bvec![0u8; 20]
));
assert_noop!(
RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
NOT_EXISTING_CLASS_ID,
CHARLIE,
Permill::from_float(20.525),
Some(CHARLIE),
Some(Permill::from_float(20.525)),
bvec![0u8; 20]
),
Error::<Test>::CollectionUnknown
Expand All @@ -113,17 +113,17 @@ fn send_nft_to_minted_nft_works() {
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(1.525),
Some(ALICE),
Some(Permill::from_float(1.525)),
bvec![0u8; 20]
));
// Alice mints NFT (0, 1) [will be the child]
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(1.525),
Some(ALICE),
Some(Permill::from_float(1.525)),
nft_metadata
));
// Alice sends NFT (0, 0) [parent] to Bob
Expand Down Expand Up @@ -203,26 +203,26 @@ fn send_two_nfts_to_same_nft_creates_two_children() {
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints NFT (0, 1)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints NFT (0, 2)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
nft_metadata
));

Expand Down Expand Up @@ -255,35 +255,35 @@ fn send_nft_removes_existing_parent() {
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints NFT (0, 1)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints NFT (0, 2)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints NFT (0, 3)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
nft_metadata
));

Expand Down Expand Up @@ -339,8 +339,8 @@ fn burn_nft_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::burn_nft(Origin::signed(ALICE), COLLECTION_ID_0, NFT_ID_0));
Expand All @@ -357,35 +357,35 @@ fn burn_nft_with_great_grandchildren_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints (0, 1)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints (0, 2)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints (0, 3)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice sends NFT (0, 1) to NFT (0, 0)
Expand Down Expand Up @@ -427,26 +427,26 @@ fn send_to_grandchild_fails() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints (0, 1)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice mints (0, 2)
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Alice sends NFT (0, 1) to NFT (0, 0)
Expand Down Expand Up @@ -485,8 +485,8 @@ fn destroy_collection_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(1.525),
Some(ALICE),
Some(Permill::from_float(1.525)),
bvec![0u8; 20]
));
assert_noop!(
Expand All @@ -507,8 +507,8 @@ fn mint_beyond_collection_max_fails() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
}
Expand All @@ -517,8 +517,8 @@ fn mint_beyond_collection_max_fails() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
),
Error::<Test>::CollectionFullOrLocked
Expand All @@ -535,8 +535,8 @@ fn lock_collection_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
}
Expand All @@ -546,8 +546,8 @@ fn lock_collection_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
),
Error::<Test>::CollectionFullOrLocked
Expand Down Expand Up @@ -579,8 +579,8 @@ fn create_resource_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
// Add resource works
Expand Down Expand Up @@ -608,8 +608,8 @@ fn create_empty_resource_fails() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(1.525),
Some(ALICE),
Some(Permill::from_float(1.525)),
bvec![0u8; 20]
));
assert_noop!(
Expand Down Expand Up @@ -639,8 +639,8 @@ fn set_property_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(1.525),
Some(ALICE),
Some(Permill::from_float(1.525)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::set_property(
Expand All @@ -661,8 +661,8 @@ fn set_priority_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::set_priority(
Expand All @@ -686,8 +686,8 @@ fn add_resource_pending_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::add_resource(
Expand All @@ -713,8 +713,8 @@ fn accept_resource_works() {
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
ALICE,
Permill::from_float(0.0),
Some(ALICE),
Some(Permill::from_float(0.0)),
bvec![0u8; 20]
));
assert_ok!(RMRKCore::add_resource(
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.