Skip to content

Commit 17b6c32

Browse files
authored
Merge pull request #171 from rmrk-team/mint-optional-owner
make owner during minting optional
2 parents e6a42c9 + 655b46b commit 17b6c32

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

pallets/rmrk-core/src/lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ pub type ValueLimitOf<T> = BoundedVec<u8, <T as pallet_uniques::Config>::ValueLi
4949
pub type BoundedResourceTypeOf<T> = BoundedVec<
5050
ResourceTypes<
5151
BoundedVec<u8, <T as pallet_uniques::Config>::StringLimit>,
52-
BoundedVec<PartId, <T as Config>::PartsLimit>>,
53-
<T as Config>::MaxResourcesOnMint
54-
>;
52+
BoundedVec<PartId, <T as Config>::PartsLimit>,
53+
>,
54+
<T as Config>::MaxResourcesOnMint,
55+
>;
5556

5657
pub mod types;
5758

@@ -346,25 +347,32 @@ pub mod pallet {
346347
#[transactional]
347348
pub fn mint_nft(
348349
origin: OriginFor<T>,
349-
owner: T::AccountId,
350+
owner: Option<T::AccountId>,
350351
collection_id: CollectionId,
351352
royalty_recipient: Option<T::AccountId>,
352353
royalty: Option<Permill>,
353354
metadata: BoundedVec<u8, T::StringLimit>,
354355
transferable: bool,
355-
resources: Option<BoundedResourceTypeOf<T>>
356+
resources: Option<BoundedResourceTypeOf<T>>,
356357
) -> DispatchResult {
357358
let sender = ensure_signed(origin.clone())?;
358-
if let Some(collection_issuer) = pallet_uniques::Pallet::<T>::collection_owner(collection_id)
359+
if let Some(collection_issuer) =
360+
pallet_uniques::Pallet::<T>::collection_owner(collection_id)
359361
{
360362
ensure!(collection_issuer == sender, Error::<T>::NoPermission);
361363
} else {
362364
return Err(Error::<T>::CollectionUnknown.into())
363365
}
364366

367+
// Default owner to minter
368+
let nft_owner = match owner {
369+
Some(owner) => owner,
370+
None => sender.clone(),
371+
};
372+
365373
let (collection_id, nft_id) = Self::nft_mint(
366-
sender.clone(),
367-
owner.clone(),
374+
sender,
375+
nft_owner.clone(),
368376
collection_id,
369377
royalty_recipient,
370378
royalty,
@@ -375,17 +383,17 @@ pub mod pallet {
375383
pallet_uniques::Pallet::<T>::do_mint(
376384
collection_id,
377385
nft_id,
378-
owner.clone(),
386+
nft_owner.clone(),
379387
|_details| Ok(()),
380388
)?;
381389

382390
if let Some(resources) = resources {
383391
for res in resources {
384-
Self::resource_add(owner.clone(), collection_id, nft_id, res)?;
392+
Self::resource_add(nft_owner.clone(), collection_id, nft_id, res)?;
385393
}
386394
}
387-
388-
Self::deposit_event(Event::NftMinted { owner, collection_id, nft_id });
395+
396+
Self::deposit_event(Event::NftMinted { owner: nft_owner, collection_id, nft_id });
389397

390398
Ok(())
391399
}

pallets/rmrk-core/src/tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn basic_collection() -> DispatchResult {
5454
fn basic_mint() -> DispatchResult {
5555
RMRKCore::mint_nft(
5656
Origin::signed(ALICE),
57-
ALICE,
57+
None, // if not specified defaults to minter
5858
COLLECTION_ID_0,
5959
Some(ALICE),
6060
Some(Permill::from_float(1.525)),
@@ -235,7 +235,7 @@ fn mint_nft_works() {
235235
assert_eq!(RMRKCore::collections(COLLECTION_ID_0).unwrap().nfts_count, 1);
236236
assert_ok!(RMRKCore::mint_nft(
237237
Origin::signed(ALICE),
238-
ALICE,
238+
None,
239239
COLLECTION_ID_0,
240240
Some(ALICE),
241241
Some(Permill::from_float(20.525)),
@@ -247,7 +247,7 @@ fn mint_nft_works() {
247247
assert_noop!(
248248
RMRKCore::mint_nft(
249249
Origin::signed(BOB),
250-
BOB,
250+
Some(BOB),
251251
COLLECTION_ID_0,
252252
Some(CHARLIE),
253253
Some(Permill::from_float(20.525)),
@@ -261,7 +261,7 @@ fn mint_nft_works() {
261261
assert_noop!(
262262
RMRKCore::mint_nft(
263263
Origin::signed(ALICE),
264-
ALICE,
264+
Some(ALICE),
265265
NOT_EXISTING_CLASS_ID,
266266
Some(CHARLIE),
267267
Some(Permill::from_float(20.525)),
@@ -302,7 +302,7 @@ fn royalty_recipient_default_works() {
302302
// Mint an NFT
303303
assert_ok!(RMRKCore::mint_nft(
304304
Origin::signed(ALICE),
305-
ALICE,
305+
None,
306306
COLLECTION_ID_0,
307307
None, // No royalty recipient
308308
Some(Permill::from_float(20.525)),
@@ -315,7 +315,7 @@ fn royalty_recipient_default_works() {
315315
// Mint another NFT
316316
assert_ok!(RMRKCore::mint_nft(
317317
Origin::signed(ALICE),
318-
ALICE,
318+
None,
319319
COLLECTION_ID_0,
320320
Some(BOB), // Royalty recipient is BOB
321321
Some(Permill::from_float(20.525)),
@@ -328,7 +328,7 @@ fn royalty_recipient_default_works() {
328328
// Mint another NFT
329329
assert_ok!(RMRKCore::mint_nft(
330330
Origin::signed(ALICE),
331-
ALICE,
331+
None,
332332
COLLECTION_ID_0,
333333
None, // No royalty recipient is BOB
334334
None, // No royalty amount
@@ -341,7 +341,7 @@ fn royalty_recipient_default_works() {
341341
// Mint another NFT
342342
assert_ok!(RMRKCore::mint_nft(
343343
Origin::signed(ALICE),
344-
ALICE,
344+
None,
345345
COLLECTION_ID_0,
346346
Some(ALICE), // Royalty recipient is ALICE
347347
None, // No royalty amount
@@ -513,7 +513,7 @@ fn send_non_transferable_fail() {
513513
// Mint non-transferable NFT
514514
assert_ok!(RMRKCore::mint_nft(
515515
Origin::signed(ALICE),
516-
ALICE,
516+
None,
517517
COLLECTION_ID_0,
518518
Some(ALICE),
519519
Some(Permill::from_float(1.525)),
@@ -584,7 +584,7 @@ fn reject_nft_removes_self_from_parents_children() {
584584
// Alice mints (0, 1) for Bob
585585
assert_ok!(RMRKCore::mint_nft(
586586
Origin::signed(ALICE),
587-
BOB,
587+
Some(BOB),
588588
COLLECTION_ID_0,
589589
Some(ALICE),
590590
Some(Permill::from_float(1.525)),
@@ -1018,7 +1018,7 @@ fn add_resource_on_mint_works() {
10181018
// Mint NFT
10191019
assert_ok!(RMRKCore::mint_nft(
10201020
Origin::signed(ALICE),
1021-
ALICE,
1021+
None,
10221022
COLLECTION_ID_0,
10231023
Some(ALICE),
10241024
Some(Permill::from_float(1.525)),
@@ -1057,7 +1057,7 @@ fn add_resource_on_mint_beyond_max_fails() {
10571057
// Mint NFT
10581058
RMRKCore::mint_nft(
10591059
Origin::signed(ALICE),
1060-
ALICE,
1060+
None,
10611061
COLLECTION_ID_0,
10621062
Some(ALICE),
10631063
Some(Permill::from_float(1.525)),
@@ -1077,7 +1077,7 @@ fn add_resource_pending_works() {
10771077
// Mint NFT
10781078
assert_ok!(RMRKCore::mint_nft(
10791079
Origin::signed(ALICE),
1080-
BOB,
1080+
Some(BOB),
10811081
COLLECTION_ID_0,
10821082
Some(BOB),
10831083
Some(Permill::from_float(1.525)),
@@ -1200,7 +1200,7 @@ fn resource_removal_pending_works() {
12001200
// Mint NFT
12011201
assert_ok!(RMRKCore::mint_nft(
12021202
Origin::signed(ALICE),
1203-
BOB,
1203+
Some(BOB),
12041204
COLLECTION_ID_0,
12051205
Some(BOB),
12061206
Some(Permill::from_float(1.525)),

pallets/rmrk-equip/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn equip_works() {
174174
// Mint NFT 0 from collection 0 (character-0)
175175
assert_ok!(RmrkCore::mint_nft(
176176
Origin::signed(ALICE),
177-
ALICE, // owner
177+
None, // owner
178178
0, // collection ID
179179
Some(ALICE), // recipient
180180
Some(Permill::from_float(1.525)), // royalties
@@ -186,7 +186,7 @@ fn equip_works() {
186186
// Mint NFT 1 from collection 0 (character-1)
187187
assert_ok!(RmrkCore::mint_nft(
188188
Origin::signed(ALICE),
189-
ALICE, // owner
189+
None, // owner
190190
0, // collection ID
191191
Some(ALICE), // recipient
192192
Some(Permill::from_float(1.525)), // royalties
@@ -198,7 +198,7 @@ fn equip_works() {
198198
// Mint NFT 0 from collection 1 (sword)
199199
assert_ok!(RmrkCore::mint_nft(
200200
Origin::signed(ALICE),
201-
ALICE, // owner
201+
None, // owner
202202
1, // collection ID
203203
Some(ALICE), // recipient
204204
Some(Permill::from_float(1.525)), // royalties
@@ -210,7 +210,7 @@ fn equip_works() {
210210
// Mint NFT 1 from collection 1 (flashlight)
211211
assert_ok!(RmrkCore::mint_nft(
212212
Origin::signed(ALICE),
213-
ALICE, // owner
213+
None, // owner
214214
1, // collection ID
215215
Some(ALICE), // recipient
216216
Some(Permill::from_float(1.525)), // royalties

pallets/rmrk-market/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn basic_collection() -> DispatchResult {
4040
fn basic_mint() -> DispatchResult {
4141
RmrkCore::mint_nft(
4242
Origin::signed(ALICE),
43-
ALICE,
43+
None,
4444
COLLECTION_ID_0,
4545
Some(ALICE),
4646
Some(Permill::from_float(1.525)),
@@ -128,7 +128,7 @@ fn list_non_transferable_fail() {
128128
// Mint non-transferable NFT
129129
assert_ok!(RmrkCore::mint_nft(
130130
Origin::signed(ALICE),
131-
ALICE,
131+
Some(ALICE),
132132
COLLECTION_ID_0,
133133
Some(ALICE),
134134
Some(Permill::from_float(1.525)),

0 commit comments

Comments
 (0)