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
63586615
Unverified
Commit
63586615
authored
4 years ago
by
Xiliang Chen
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
avoid CID (#306)
parent
bfb9a32d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nft/src/lib.rs
+8
-6
8 additions, 6 deletions
nft/src/lib.rs
with
8 additions
and
6 deletions
nft/src/lib.rs
+
8
−
6
View file @
63586615
...
@@ -31,13 +31,11 @@ use sp_std::vec::Vec;
...
@@ -31,13 +31,11 @@ use sp_std::vec::Vec;
mod
mock
;
mod
mock
;
mod
tests
;
mod
tests
;
pub
type
CID
=
Vec
<
u8
>
;
/// Class info
/// Class info
#[derive(Encode,
Decode,
Clone,
Eq,
PartialEq,
RuntimeDebug)]
#[derive(Encode,
Decode,
Clone,
Eq,
PartialEq,
RuntimeDebug)]
pub
struct
ClassInfo
<
TokenId
,
AccountId
,
Data
>
{
pub
struct
ClassInfo
<
TokenId
,
AccountId
,
Data
>
{
/// Class metadata
/// Class metadata
pub
metadata
:
CID
,
pub
metadata
:
Vec
<
u8
>
,
/// Total issuance for the class
/// Total issuance for the class
pub
total_issuance
:
TokenId
,
pub
total_issuance
:
TokenId
,
/// Class owner
/// Class owner
...
@@ -50,7 +48,7 @@ pub struct ClassInfo<TokenId, AccountId, Data> {
...
@@ -50,7 +48,7 @@ pub struct ClassInfo<TokenId, AccountId, Data> {
#[derive(Encode,
Decode,
Clone,
Eq,
PartialEq,
RuntimeDebug)]
#[derive(Encode,
Decode,
Clone,
Eq,
PartialEq,
RuntimeDebug)]
pub
struct
TokenInfo
<
AccountId
,
Data
>
{
pub
struct
TokenInfo
<
AccountId
,
Data
>
{
/// Token metadata
/// Token metadata
pub
metadata
:
CID
,
pub
metadata
:
Vec
<
u8
>
,
/// Token owner
/// Token owner
pub
owner
:
AccountId
,
pub
owner
:
AccountId
,
/// Token Properties
/// Token Properties
...
@@ -119,7 +117,11 @@ decl_module! {
...
@@ -119,7 +117,11 @@ decl_module! {
impl
<
T
:
Trait
>
Module
<
T
>
{
impl
<
T
:
Trait
>
Module
<
T
>
{
/// Create NFT(non fungible token) class
/// Create NFT(non fungible token) class
pub
fn
create_class
(
owner
:
&
T
::
AccountId
,
metadata
:
CID
,
data
:
T
::
ClassData
)
->
Result
<
T
::
ClassId
,
DispatchError
>
{
pub
fn
create_class
(
owner
:
&
T
::
AccountId
,
metadata
:
Vec
<
u8
>
,
data
:
T
::
ClassData
,
)
->
Result
<
T
::
ClassId
,
DispatchError
>
{
let
class_id
=
NextClassId
::
<
T
>
::
try_mutate
(|
id
|
->
Result
<
T
::
ClassId
,
DispatchError
>
{
let
class_id
=
NextClassId
::
<
T
>
::
try_mutate
(|
id
|
->
Result
<
T
::
ClassId
,
DispatchError
>
{
let
current_id
=
*
id
;
let
current_id
=
*
id
;
*
id
=
id
.checked_add
(
&
One
::
one
())
.ok_or
(
Error
::
<
T
>
::
NoAvailableClassId
)
?
;
*
id
=
id
.checked_add
(
&
One
::
one
())
.ok_or
(
Error
::
<
T
>
::
NoAvailableClassId
)
?
;
...
@@ -159,7 +161,7 @@ impl<T: Trait> Module<T> {
...
@@ -159,7 +161,7 @@ impl<T: Trait> Module<T> {
pub
fn
mint
(
pub
fn
mint
(
owner
:
&
T
::
AccountId
,
owner
:
&
T
::
AccountId
,
class_id
:
T
::
ClassId
,
class_id
:
T
::
ClassId
,
metadata
:
CID
,
metadata
:
Vec
<
u8
>
,
data
:
T
::
TokenData
,
data
:
T
::
TokenData
,
)
->
Result
<
T
::
TokenId
,
DispatchError
>
{
)
->
Result
<
T
::
TokenId
,
DispatchError
>
{
NextTokenId
::
<
T
>
::
try_mutate
(|
id
|
->
Result
<
T
::
TokenId
,
DispatchError
>
{
NextTokenId
::
<
T
>
::
try_mutate
(|
id
|
->
Result
<
T
::
TokenId
,
DispatchError
>
{
...
...
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