-
Notifications
You must be signed in to change notification settings - Fork 13
/
erc721.go
51 lines (45 loc) · 1.5 KB
/
erc721.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
package resolution
import (
"encoding/json"
)
type TokenMetadataAttribute struct {
DisplayType string `json:"display_type"`
TraitType string `json:"trait_type"`
Value interface{} `json:"value"`
}
type TokenMetadataProperties struct {
Records map[string]string `json:"records"`
}
type TokenMetadata struct {
Name string `json:"name"`
Description string `json:"description"`
Image string `json:"image"`
ExternalUrl string `json:"-"`
ExternalLink string `json:"external_link"`
ImageData string `json:"image_data"`
BackgroundColor string `json:"background_color"`
AnimationUrl string `json:"animation_url"`
YoutubeUrl string `json:"youtube_url"`
Properties TokenMetadataProperties `json:"properties"`
Attributes []TokenMetadataAttribute `json:"attributes"`
}
func (tm *TokenMetadata) UnmarshalJSON(data []byte) error {
// Use a helper struct to aid the unmarshalling
type Alias TokenMetadata
aux := &struct {
ExternalLink1 string `json:"external_link"`
ExternalLink2 string `json:"url"`
*Alias
}{
Alias: (*Alias)(tm),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
// Logic to set ExternalUrl based on which one is present
tm.ExternalUrl = aux.ExternalLink1
if tm.ExternalLink == "" {
tm.ExternalLink = aux.ExternalLink2
}
return nil
}