Skip to content

Commit

Permalink
switch royalty to permill type
Browse files Browse the repository at this point in the history
  • Loading branch information
ilionic committed Dec 11, 2021
1 parent b39fd33 commit 757b451
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
16 changes: 8 additions & 8 deletions pallets/rmrk-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use frame_support::{
use frame_system::ensure_signed;

use sp_runtime::traits::{AtLeast32BitUnsigned, CheckedAdd, One, StaticLookup, Zero};
use sp_runtime::Permill;
use sp_std::{convert::TryInto, vec::Vec};

use types::{AccountIdOrCollectionNftTuple, ClassInfo, InstanceInfo};
Expand Down Expand Up @@ -173,7 +174,7 @@ pub mod pallet {
/// - `collection_id`: The class of the asset to be minted.
/// - `nft_id`: The nft value of the asset to be minted.
/// - `recipient`: Receiver of the royalty
/// - `royalty`: Percentage reward from each trade for the Recipient
/// - `royalty`: Permillage reward from each trade for the Recipient
/// - `metadata`: Arbitrary data about an nft, e.g. IPFS hash
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
#[transactional]
Expand All @@ -182,8 +183,8 @@ pub mod pallet {
owner: T::AccountId,
collection_id: T::CollectionId,
recipient: Option<T::AccountId>,
royalty: Option<u16>,
metadata: Option<Vec<u8>>,
royalty: Option<Permill>,
metadata: Vec<u8>,
) -> DispatchResult {
let sender = match T::ProtocolOrigin::try_origin(origin) {
Ok(_) => None,
Expand All @@ -192,9 +193,9 @@ pub mod pallet {

let _ = Self::collections(collection_id).ok_or(Error::<T>::CollectionUnknown)?;

if let Some(r) = royalty {
ensure!(r < 100, Error::<T>::NotInRange);
}
// if let Some(r) = royalty {
// ensure!(r < 100, Error::<T>::NotInRange);
// }

let nft_id: T::NftId = Self::get_next_nft_id(collection_id)?;

Expand All @@ -205,8 +206,7 @@ pub mod pallet {
|_details| Ok(()),
)?;

let metadata_bounded =
Self::to_bounded_string(metadata.ok_or(Error::<T>::MetadataNotSet)?)?;
let metadata_bounded = Self::to_bounded_string(metadata)?;
let recipient = recipient.ok_or(Error::<T>::RecipientNotSet)?;
let royalty = royalty.ok_or(Error::<T>::RoyaltyNotSet)?;

Expand Down
34 changes: 17 additions & 17 deletions pallets/rmrk-core/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
// use sp_runtime::AccountId32;

use sp_runtime::Permill;
// use crate::types::ClassType;

use super::*;
Expand Down Expand Up @@ -48,33 +48,33 @@ fn mint_nft_works() {
ALICE,
0,
Some(ALICE),
Some(0),
Some(b"metadata".to_vec())
Some(Permill::from_float(20.525)),
b"metadata".to_vec()
));
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
COLLECTION_ID_0,
Some(ALICE),
Some(20),
Some(b"metadata".to_vec())
Some(Permill::from_float(20.525)),
b"metadata".to_vec()
));
assert_ok!(RMRKCore::mint_nft(
Origin::signed(BOB),
BOB,
COLLECTION_ID_0,
Some(CHARLIE),
Some(20),
Some(b"metadata".to_vec())
Some(Permill::from_float(20.525)),
b"metadata".to_vec()
));
assert_noop!(
RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
NOT_EXISTING_CLASS_ID,
Some(CHARLIE),
Some(20),
Some(b"metadata".to_vec())
Some(Permill::from_float(20.525)),
b"metadata".to_vec()
),
Error::<Test>::CollectionUnknown
);
Expand All @@ -92,17 +92,17 @@ fn send_nft_to_minted_nft_works() {
ALICE,
0,
Some(ALICE),
Some(0),
Some(nft_metadata.clone())
Some(Permill::from_float(1.525)),
nft_metadata.clone()
));
// Alice mints NFT (0, 1) [will be the child]
assert_ok!(RMRKCore::mint_nft(
Origin::signed(ALICE),
ALICE,
0,
Some(ALICE),
Some(0),
Some(nft_metadata)
Some(Permill::from_float(1.525)),
nft_metadata
));
// Alice sends NFT (0, 0) [parent] to Bob
assert_ok!(RMRKCore::send(
Expand Down Expand Up @@ -191,8 +191,8 @@ fn burn_nft_works() {
ALICE,
COLLECTION_ID_0,
Some(ALICE),
Some(0),
Some(metadata.clone())
Some(Permill::from_float(1.525)),
metadata.clone()
));
assert_ok!(RMRKCore::burn_nft(Origin::signed(ALICE), COLLECTION_ID_0, NFT_ID_0));
assert_eq!(RMRKCore::nfts(COLLECTION_ID_0, NFT_ID_0), None);
Expand All @@ -209,8 +209,8 @@ fn destroy_collection_works() {
ALICE,
COLLECTION_ID_0,
Some(ALICE),
Some(0),
Some(metadata.clone())
Some(Permill::from_float(1.525)),
metadata.clone()
));
assert_noop!(
RMRKCore::destroy_collection(Origin::signed(ALICE), COLLECTION_ID_0),
Expand Down
3 changes: 2 additions & 1 deletion pallets/rmrk-core/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use frame_support::pallet_prelude::*;
use sp_runtime::Permill;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -30,7 +31,7 @@ pub struct InstanceInfo<AccountId, BoundedString, CollectionId, NftId> {
/// The user account which receives the royalty
pub recipient: AccountId,
/// Royalty in per mille (1/1000)
pub royalty: u16,
pub royalty: Permill,
/// Arbitrary data about an instance, e.g. IPFS hash
pub metadata: BoundedString,
}

0 comments on commit 757b451

Please sign in to comment.