-
Notifications
You must be signed in to change notification settings - Fork 349
/
nft.go
69 lines (54 loc) · 1.51 KB
/
nft.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2016-2021 Shanghai Bianjie AI Technology Inc. (licensed under the Apache License, Version 2.0)
// Modifications Copyright (c) 2021-present Crypto.org (licensed under the Apache License, Version 2.0)
package types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crypto-org-chain/chain-main/v4/x/nft/exported"
)
var _ exported.NFT = BaseNFT{}
// NewBaseNFT creates a new NFT instance
func NewBaseNFT(id, name string, owner sdk.AccAddress, uri, data string) BaseNFT {
return BaseNFT{
Id: id,
Name: name,
Owner: owner.String(),
URI: uri,
Data: data,
}
}
// GetID return the id of BaseNFT
func (bnft BaseNFT) GetID() string {
return bnft.Id
}
// GetName return the name of BaseNFT
func (bnft BaseNFT) GetName() string {
return bnft.Name
}
// GetOwner return the owner of BaseNFT
func (bnft BaseNFT) GetOwner() sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(bnft.Owner)
if err != nil {
panic(fmt.Errorf("couldn't convert %q to account address: %v", bnft.Owner, err))
}
return owner
}
// GetURI return the URI of BaseNFT
func (bnft BaseNFT) GetURI() string {
return bnft.URI
}
// GetData return the Data of BaseNFT
func (bnft BaseNFT) GetData() string {
return bnft.Data
}
// ----------------------------------------------------------------------------
// NFT
// NFTs define a list of NFT
type NFTs []exported.NFT
// NewNFTs creates a new set of NFTs
func NewNFTs(nfts ...exported.NFT) NFTs {
if len(nfts) == 0 {
return NFTs{}
}
return NFTs(nfts)
}