-
Notifications
You must be signed in to change notification settings - Fork 0
/
nft.go
76 lines (66 loc) · 1.75 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
70
71
72
73
74
75
76
package moralis
import (
"fmt"
"strconv"
"github.com/0xDeSchool/gap/errx"
)
type SyncStatus string
const (
StatusSyncing SyncStatus = "SYNCING"
StatusSynced SyncStatus = "SYNCED"
)
type NFTResult struct {
Total int64 `json:"total"`
Cursor string `json:"cursor"`
Result []NFTItem `json:"result"`
}
type NFTItem struct {
Address string `json:"token_address"`
TokenId string `json:"token_id"`
Amount string `json:"amount"`
Metadata NFTMetadata `json:"normalized_metadata"`
Name string `json:"name"`
OwnerOf string `json:"owner_of"`
}
type NFTMetadata struct {
Name string `json:"name"`
Description string `json:"description"`
Image string `json:"image"`
ExternalLink string `json:"external_link"`
}
func (mc *Client) GetNFTsByAddr(addr string) {
}
func (mc *Client) OwnersOfContract(contract string, limit int, cursor *string) (*NFTResult, error) {
path := "/nft/" + contract + "/owners"
var result = NFTResult{}
query := map[string]string{
"limit": strconv.Itoa(limit),
"normalizeMetadata": "true",
}
if cursor != nil {
query["cursor"] = *cursor
}
err := mc.get(path, query, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (mc *Client) GetOwnersByTokenId(contract string, tokenId string, limit int, cursor *string) (*NFTResult, error) {
errx.NotEmpty(tokenId, "tokenId")
errx.NotEmpty(contract, "contract")
path := fmt.Sprintf("/nft/%s/%s/owners", contract, tokenId)
var result = NFTResult{}
query := map[string]string{
"limit": strconv.Itoa(limit),
"normalizeMetadata": "true",
}
if cursor != nil {
query["cursor"] = *cursor
}
err := mc.get(path, query, &result)
if err != nil {
return nil, err
}
return &result, nil
}