-
Notifications
You must be signed in to change notification settings - Fork 28
/
onft.go
108 lines (85 loc) · 2.01 KB
/
onft.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package types
import (
"time"
"github.com/OmniFlix/omniflixhub/v3/x/onft/exported"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var _ exported.ONFTI = ONFT{}
func UnmarshalNFTMetadata(cdc codec.BinaryCodec, bz []byte) (ONFTMetadata, error) {
var nftMetadata ONFTMetadata
if len(bz) == 0 {
return nftMetadata, nil
}
if err := cdc.Unmarshal(bz, &nftMetadata); err != nil {
return nftMetadata, err
}
return nftMetadata, nil
}
func NewONFT(
id string, metadata Metadata, data string, transferable, extensible bool, owner sdk.AccAddress,
createdTime time.Time, nsfw bool, royaltyShare sdk.Dec,
) ONFT {
return ONFT{
Id: id,
Metadata: metadata,
Data: data,
Owner: owner.String(),
Transferable: transferable,
Extensible: extensible,
CreatedAt: createdTime,
Nsfw: nsfw,
RoyaltyShare: royaltyShare,
}
}
func (onft ONFT) GetID() string {
return onft.Id
}
func (onft ONFT) GetName() string {
return onft.Metadata.Name
}
func (onft ONFT) GetDescription() string {
return onft.Metadata.Description
}
func (onft ONFT) GetMediaURI() string {
return onft.Metadata.MediaURI
}
func (onft ONFT) GetURIHash() string {
return onft.Metadata.UriHash
}
func (onft ONFT) GetPreviewURI() string {
return onft.Metadata.PreviewURI
}
func (onft ONFT) GetOwner() sdk.AccAddress {
owner, _ := sdk.AccAddressFromBech32(onft.Owner)
return owner
}
func (onft ONFT) GetMetadata() string {
return onft.Metadata.String()
}
func (onft ONFT) GetData() string {
return onft.Data
}
func (onft ONFT) IsTransferable() bool {
return onft.Transferable
}
func (onft ONFT) IsExtensible() bool {
return onft.Extensible
}
func (onft ONFT) GetCreatedTime() time.Time {
return onft.CreatedAt
}
func (onft ONFT) IsNSFW() bool {
return onft.Nsfw
}
func (onft ONFT) GetRoyaltyShare() sdk.Dec {
return onft.RoyaltyShare
}
// ONFT
type ONFTs []exported.ONFTI
func NewONFTs(onfts ...exported.ONFTI) ONFTs {
if len(onfts) == 0 {
return ONFTs{}
}
return onfts
}