Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
open-runtime-module-library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noxim
open-runtime-module-library
Commits
4e054a59
Unverified
Commit
4e054a59
authored
4 years ago
by
Xiliang Chen
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update nft (#308)
* bumo orml-nft * avoid share token id between classes
parent
da6ca884
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
nft/Cargo.toml
+1
-1
1 addition, 1 deletion
nft/Cargo.toml
nft/src/lib.rs
+5
-2
5 additions, 2 deletions
nft/src/lib.rs
nft/src/mock.rs
+2
-2
2 additions, 2 deletions
nft/src/mock.rs
nft/src/tests.rs
+17
-1
17 additions, 1 deletion
nft/src/tests.rs
with
25 additions
and
6 deletions
nft/Cargo.toml
+
1
−
1
View file @
4e054a59
...
...
@@ -3,7 +3,7 @@ name = "orml-nft"
description
=
"Non-fungible token pallet provides basic functions to create and manager NFT"
repository
=
"https://github.com/open-web3-stack/open-runtime-module-library/tree/master/nft"
license
=
"Apache-2.0"
version
=
"0.3.
3
-dev"
version
=
"0.3.
4
-dev"
authors
=
[
"Acala Developers"
]
edition
=
"2018"
...
...
This diff is collapsed.
Click to expand it.
nft/src/lib.rs
+
5
−
2
View file @
4e054a59
...
...
@@ -96,7 +96,7 @@ decl_storage! {
/// Next available class ID.
pub
NextClassId
get
(
fn
next_class_id
):
T
::
ClassId
;
/// Next available token ID.
pub
NextTokenId
get
(
fn
next_token_id
):
T
::
TokenId
;
pub
NextTokenId
get
(
fn
next_token_id
):
map
hasher
(
twox_64_concat
)
T
::
ClassId
=>
T
::
TokenId
;
/// Store class info.
///
/// Returns `None` if class info not set or removed.
...
...
@@ -166,7 +166,7 @@ impl<T: Trait> Module<T> {
metadata
:
Vec
<
u8
>
,
data
:
T
::
TokenData
,
)
->
Result
<
T
::
TokenId
,
DispatchError
>
{
NextTokenId
::
<
T
>
::
try_mutate
(|
id
|
->
Result
<
T
::
TokenId
,
DispatchError
>
{
NextTokenId
::
<
T
>
::
try_mutate
(
class_id
,
|
id
|
->
Result
<
T
::
TokenId
,
DispatchError
>
{
let
token_id
=
*
id
;
*
id
=
id
.checked_add
(
&
One
::
one
())
.ok_or
(
Error
::
<
T
>
::
NoAvailableTokenId
)
?
;
...
...
@@ -217,6 +217,9 @@ impl<T: Trait> Module<T> {
let
info
=
class_info
.take
()
.ok_or
(
Error
::
<
T
>
::
ClassNotFound
)
?
;
ensure!
(
info
.owner
==
*
owner
,
Error
::
<
T
>
::
NoPermission
);
ensure!
(
info
.total_issuance
==
Zero
::
zero
(),
Error
::
<
T
>
::
CannotDestroyClass
);
NextTokenId
::
<
T
>
::
remove
(
class_id
);
Ok
(())
})
}
...
...
This diff is collapsed.
Click to expand it.
nft/src/mock.rs
+
2
−
2
View file @
4e054a59
...
...
@@ -65,9 +65,9 @@ pub type NonFungibleTokenModule = Module<Runtime>;
pub
const
ALICE
:
AccountId
=
1
;
pub
const
BOB
:
AccountId
=
2
;
pub
const
CLASS_ID
:
<
Runtime
as
Trait
>
::
ClassId
=
0
;
pub
const
CLASS_ID_NOT_EXIST
:
<
Runtime
as
Trait
>
::
ClassId
=
1
;
pub
const
CLASS_ID_NOT_EXIST
:
<
Runtime
as
Trait
>
::
ClassId
=
1
00
;
pub
const
TOKEN_ID
:
<
Runtime
as
Trait
>
::
TokenId
=
0
;
pub
const
TOKEN_ID_NOT_EXIST
:
<
Runtime
as
Trait
>
::
TokenId
=
1
;
pub
const
TOKEN_ID_NOT_EXIST
:
<
Runtime
as
Trait
>
::
TokenId
=
1
00
;
pub
struct
ExtBuilder
;
...
...
This diff is collapsed.
Click to expand it.
nft/src/tests.rs
+
17
−
1
View file @
4e054a59
...
...
@@ -29,8 +29,22 @@ fn create_class_should_fail() {
#[test]
fn
mint_should_work
()
{
ExtBuilder
::
default
()
.build
()
.execute_with
(||
{
let
next_class_id
=
NonFungibleTokenModule
::
next_class_id
();
assert_eq!
(
next_class_id
,
CLASS_ID
);
assert_ok!
(
NonFungibleTokenModule
::
create_class
(
&
ALICE
,
vec!
[
1
],
()));
assert_eq!
(
NonFungibleTokenModule
::
next_token_id
(
CLASS_ID
),
0
);
assert_ok!
(
NonFungibleTokenModule
::
mint
(
&
BOB
,
CLASS_ID
,
vec!
[
1
],
()));
assert_eq!
(
NonFungibleTokenModule
::
next_token_id
(
CLASS_ID
),
1
);
assert_ok!
(
NonFungibleTokenModule
::
mint
(
&
BOB
,
CLASS_ID
,
vec!
[
1
],
()));
assert_eq!
(
NonFungibleTokenModule
::
next_token_id
(
CLASS_ID
),
2
);
let
next_class_id
=
NonFungibleTokenModule
::
next_class_id
();
assert_ok!
(
NonFungibleTokenModule
::
create_class
(
&
ALICE
,
vec!
[
1
],
()));
assert_eq!
(
NonFungibleTokenModule
::
next_token_id
(
next_class_id
),
0
);
assert_ok!
(
NonFungibleTokenModule
::
mint
(
&
BOB
,
next_class_id
,
vec!
[
1
],
()));
assert_eq!
(
NonFungibleTokenModule
::
next_token_id
(
next_class_id
),
1
);
assert_eq!
(
NonFungibleTokenModule
::
next_token_id
(
CLASS_ID
),
2
);
});
}
...
...
@@ -46,7 +60,7 @@ fn mint_should_fail() {
Error
::
<
Runtime
>
::
NumOverflow
);
NextTokenId
::
<
Runtime
>
::
mutate
(|
id
|
*
id
=
<
Runtime
as
Trait
>
::
TokenId
::
max_value
());
NextTokenId
::
<
Runtime
>
::
mutate
(
CLASS_ID
,
|
id
|
*
id
=
<
Runtime
as
Trait
>
::
TokenId
::
max_value
());
assert_noop!
(
NonFungibleTokenModule
::
mint
(
&
BOB
,
CLASS_ID
,
vec!
[
1
],
()),
Error
::
<
Runtime
>
::
NoAvailableTokenId
...
...
@@ -136,6 +150,8 @@ fn destroy_class_should_work() {
assert_ok!
(
NonFungibleTokenModule
::
mint
(
&
BOB
,
CLASS_ID
,
vec!
[
1
],
()));
assert_ok!
(
NonFungibleTokenModule
::
burn
(
&
BOB
,
(
CLASS_ID
,
TOKEN_ID
)));
assert_ok!
(
NonFungibleTokenModule
::
destroy_class
(
&
ALICE
,
CLASS_ID
));
assert_eq!
(
Classes
::
<
Runtime
>
::
contains_key
(
CLASS_ID
),
false
);
assert_eq!
(
NextTokenId
::
<
Runtime
>
::
contains_key
(
CLASS_ID
),
false
);
});
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment