-
Notifications
You must be signed in to change notification settings - Fork 6
/
opensea-model.go
348 lines (315 loc) · 15.2 KB
/
opensea-model.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package opensea
import (
"encoding/hex"
"encoding/json"
"errors"
"math/big"
"strconv"
"strings"
"time"
)
type Number string
func (n Number) Big() *big.Int {
s := strings.Split(string(n), ".")
r, _ := new(big.Int).SetString(s[0], 10)
return r
}
type Address string
const NullAddress Address = "0x0000000000000000000000000000000000000000"
func IsHexAddress(s string) bool {
if s == "0x0" {
return true
}
if s[0:2] != "0x" {
return false
}
addressLength := 2 + 40
if len(s) != addressLength {
return false
}
if !isHex(s[2:]) {
return false
}
return true
}
func ParseAddress(address string) (Address, error) {
if !IsHexAddress(address) {
return "", errors.New("Invalid address: " + address)
}
return Address(strings.ToLower(address)), nil
}
func (a Address) String() string {
return string(a)
}
func (a Address) IsNullAddress() bool {
if a.String() == NullAddress.String() {
return true
}
return false
}
func (a *Address) UnmarshalJSON(b []byte) error {
var s string
var err error
if string(b) == "null" {
s = NullAddress.String()
} else {
s, err = strconv.Unquote(string(b))
}
if err != nil {
return err
}
*a, err = ParseAddress(s)
return err
}
func (a Address) MarshalJSON() ([]byte, error) {
s := strconv.Quote(a.String())
return []byte(s), nil
}
type Bytes []byte
func (by Bytes) Bytes32() [32]byte {
var ret [32]byte
copy(ret[:], by[0:32])
return ret
}
func (by *Bytes) UnmarshalJSON(b []byte) error {
s, err := strconv.Unquote(string(b))
if err != nil {
return err
}
if len(s) == 0 {
*by = []byte{}
return nil
}
s = s[2:]
*by, err = hex.DecodeString(s)
return err
}
func (by Bytes) MarshalJSON() ([]byte, error) {
s := hex.EncodeToString([]byte(by))
s = "0x" + s
s = strconv.Quote(s)
return []byte(s), nil
}
type TimeNano time.Time
func (t TimeNano) Time() time.Time {
return time.Time(t)
}
func (t *TimeNano) UnmarshalJSON(b []byte) error {
s, err := strconv.Unquote(string(b))
if err != nil {
return err
}
tt := time.Time{}
tt, err = time.Parse("2006-01-02T15:04:05.999999", s)
// if strings.Contains(s, ".") {
// tt, err = time.Parse("2006-01-02T15:04:05.999999", s)
// } else {
// tt, err = time.Parse("2006-01-02T15:04:05", s)
// }
if err != nil {
return err
}
*t = TimeNano(tt)
return nil
}
func (t TimeNano) MarshalJSON() ([]byte, error) {
s := t.Time().Format("2006-01-02T15:04:05.999999")
s = strconv.Quote(s)
return []byte(s), nil
}
type Account struct {
User User `json:"user" bson:"user"`
ProfileImgURL string `json:"profile_img_url" bson:"profile_img_url"`
Address Address `json:"address" bson:"address"`
Config string `json:"config" bson:"config"`
DiscordID string `json:"discord_id" bson:"discord_id"`
}
type User struct {
Username string `json:"username" bson:"username"`
}
type Trait struct {
TraitType string `json:"trait_type" bson:"trait_type"`
Value json.RawMessage `json:"value" bson:"value"`
DisplayType interface{} `json:"display_type" bson:"display_type"`
MaxValue interface{} `json:"max_value" bson:"max_value"`
TraitCount int64 `json:"trait_count" bson:"trait_count"`
Order interface{} `json:"order" bson:"order"`
}
type Value struct {
Integer *int64
String *string
}
// isHexCharacter returns bool of c being a valid hexadecimal.
func isHexCharacter(c byte) bool {
return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
}
// isHex validates whether each byte is valid hexadecimal string.
func isHex(str string) bool {
if len(str)%2 != 0 {
return false
}
for _, c := range []byte(str) {
if !isHexCharacter(c) {
return false
}
}
return true
}
type AssetResponse struct {
Assets []Asset `json:"assets" bson:"assets"`
}
// Asset is the primary object in the OpenSea API, which represents a unique digital item whose ownership is managed by the blockchain.
type Asset struct {
// todo: Support commented fields in Asset struct
ID int64 `json:"id" bson:"id"`
TokenID string `json:"token_id" bson:"token_id"`
NumSales int64 `json:"num_sales" bson:"num_sales"`
BackgroundColor string `json:"background_color" bson:"background_color"`
ImageURL string `json:"image_url" bson:"image_url"`
ImagePreviewURL string `json:"image_preview_url" bson:"image_preview_url"`
ImageThumbnailURL string `json:"image_thumbnail_url" bson:"image_thumbnail_url"`
ImageOriginalURL string `json:"image_original_url" bson:"image_original_url"`
AnimationURL string `json:"animation_url" bson:"animation_url"`
AnimationOriginalURL string `json:"animation_original_url" bson:"animation_original_url"`
Name string `json:"name" bson:"name"`
Description string `json:"description" bson:"description"`
ExternalLink string `json:"external_link" bson:"external_link"`
AssetContract *AssetContract `json:"asset_contract" bson:"asset_contract"`
Permalink string `json:"permalink" bson:"permalink"`
Collection *Collection `json:"collection" bson:"collection"`
Decimals int64 `json:"decimals" bson:"decimals"`
TokenMetadata string `json:"token_metadata" bson:"token_metadata"`
//IsNSFW bool `json:"is_nsfw" bson:"is_nsfw"`
Owner *Account `json:"owner" bson:"owner"`
//SeaportSellOrders string `json:"seaport_sell_orders" bson:"seaport_sell_orders"`
//Creator *Creator `json:"creator" bson:"creator"`
Traits interface{} `json:"traits" bson:"traits"`
//LastSale string `json:"last_sale" bson:"last_sale"`
//TopBid int64 `json:"top_bid" bson:"top_bid"`
//ListingDate string `json:"listing_date" bson:"listing_date"`
//SupportsWyvern string `json:"supports_wyvern" bson:"supports_wyvern"`
//RarityData *RarityData `json:"rarity_data" bson:"rarity_data"`
//TransferFee int64 `json:"transfer_fee" bson:"transfer_fee"`
//TransferFeePaymentToken string `json:"transfer_fee_payment_token" bson:"transfer_fee_payment_token"`
}
// AssetContract contains data about the contract itself, such as the Bored Ape Yacht Club contract.
type AssetContract struct {
Address Address `json:"address" bson:"address"`
AssetContractType string `json:"asset_contract_type" bson:"asset_contract_type"`
CreatedDate string `json:"created_date" bson:"created_date"`
Name string `json:"name" bson:"name"`
NftVersion string `json:"nft_version" bson:"nft_version"`
OpenseaVersion interface{} `json:"opensea_version" bson:"opensea_version"`
Owner int64 `json:"owner" bson:"owner"`
SchemaName string `json:"schema_name" bson:"schema_name"`
Symbol string `json:"symbol" bson:"symbol"`
TotalSupply interface{} `json:"total_supply" bson:"total_supply"`
Description string `json:"description" bson:"description"`
ExternalLink string `json:"external_link" bson:"external_link"`
ImageURL string `json:"image_url" bson:"image_url"`
DefaultToFiat bool `json:"default_to_fiat" bson:"default_to_fiat"`
DevBuyerFeeBasisPoints int64 `json:"dev_buyer_fee_basis_points" bson:"dev_buyer_fee_basis_points"`
DevSellerFeeBasisPoints int64 `json:"dev_seller_fee_basis_points" bson:"dev_seller_fee_basis_points"`
OnlyProxiedTransfers bool `json:"only_proxied_transfers" bson:"only_proxied_transfers"`
OpenseaBuyerFeeBasisPoints int64 `json:"opensea_buyer_fee_basis_points" bson:"opensea_buyer_fee_basis_points"`
OpenseaSellerFeeBasisPoints int64 `json:"opensea_seller_fee_basis_points" bson:"opensea_seller_fee_basis_points"`
BuyerFeeBasisPoints int64 `json:"buyer_fee_basis_points" bson:"buyer_fee_basis_points"`
SellerFeeBasisPoints int64 `json:"seller_fee_basis_points" bson:"seller_fee_basis_points"`
PayoutAddress Address `json:"payout_address" bson:"payout_address"`
}
// Collection is used to represent all the assets in a single (or multiple) contract addresses and help users group items from the same
// creator. They have one or more owners and are typically associated with important metadata such as creator earnings configurations and
// descriptions.
type Collection struct {
// todo: Support commented fields in Collection struct for /collections GET request
//PrimaryAssetContracts
//Traits
//Stats
BannerImageUrl string `json:"banner_image_url" bson:"banner_image_url"`
ChatUrl string `json:"chat_url" bson:"chat_url"`
CreatedDate string `json:"created_date" bson:"created_date"`
DefaultToFiat bool `json:"default_to_fiat" bson:"default_to_fiat"`
Description string `json:"description" bson:"description"`
DevBuyerFeeBasisPoints string `json:"dev_buyer_fee_basis_points" bson:"dev_buyer_fee_basis_points"`
DevSellerFeeBasisPoints string `json:"dev_seller_fee_basis_points" bson:"dev_seller_fee_basis_points"`
DiscordUrl string `json:"discord_url" bson:"discord_url"`
DisplayData interface{} `json:"display_data" bson:"display_data"`
ExternalUrl string `json:"external_url" bson:"external_url"`
Featured bool `json:"featured" bson:"featured"`
FeaturedImageUrl string `json:"featured_image_url" bson:"featured_image_url"`
Hidden bool `json:"hidden" bson:"hidden"`
SafelistRequestStatus string `json:"safelist_request_status" bson:"safelist_request_status"`
ImageUrl string `json:"image_url" bson:"image_url"`
IsSubjectToWhitelist bool `json:"is_subject_to_whitelist" bson:"is_subject_to_whitelist"`
LargeImageUrl string `json:"large_image_url" bson:"large_image_url"`
MediumUsername string `json:"medium_username" bson:"medium_username"`
Name string `json:"name" bson:"name"`
OnlyProxiedTransfers bool `json:"only_proxied_transfers" bson:"only_proxied_transfers"`
OpenseaBuyerFeeBasisPoints string `json:"opensea_buyer_fee_basis_points" bson:"opensea_buyer_fee_basis_points"`
OpenseaSellerFeeBasisPoints string `json:"opensea_seller_fee_basis_points" bson:"opensea_seller_fee_basis_points"`
PayoutAddress string `json:"payout_address" bson:"payout_address"`
RequireEmail bool `json:"require_email" bson:"require_email"`
ShortDescription string `json:"short_description" bson:"short_description"`
Slug string `json:"slug" bson:"slug"`
TelegramUrl string `json:"telegram_url" bson:"telegram_url"`
TwitterUsername string `json:"twitter_username" bson:"twitter_username"`
InstagramUsername string `json:"instagram_username" bson:"instagram_username"`
WikiUrl string `json:"wiki_url" bson:"wiki_url"`
//IsNSFW bool `json:"is_nsfw" bson:"is_nsfw"`
//Fees interface{} `json:"fees" bson:"fees"`
//IsRarityEnabled bool `json:"is_rarity_enabled" bson:"is_rarity_enabled"`
//IsCreatorFeesEnforced bool `json:"is_creator_fees_enforced" bson:"is_creator_fees_enforced"`
}
type StatResponse struct {
Stats Stat `json:"stats" bson:"stats"`
}
type Stat struct {
// todo: Support commented fields in Stat struct for /collections GET request
//OneHourVolume float64 `json:"one_hour_volume" bson:"one_hour_volume"`
//OneHourChange float64 `json:"one_hour_change" bson:"one_hour_change"`
//OneHourSales float64 `json:"one_hour_sales" bson:"one_hour_sales"`
//OneHourSalesChange float64 `json:"one_hour_sales_change" bson:"one_hour_sales_change"`
//OneHourAveragePrice float64 `json:"one_hour_average_price" bson:"one_hour_average_price"`
//OneHourDifference float64 `json:"one_hour_difference" bson:"one_hour_difference"`
//SixHourVolume float64 `json:"six_hour_volume" bson:"six_hour_volume"`
//SixHourChange float64 `json:"six_hour_change" bson:"six_hour_change"`
//SixHourSales float64 `json:"six_hour_sales" bson:"six_hour_sales"`
//SixHourSalesChange float64 `json:"six_hour_sales_change" bson:"six_hour_sales_change"`
//SixHourAveragePrice float64 `json:"six_hour_avg_price" bson:"six_hour_avg_price"`
//SixHourDifference float64 `json:"six_hour_difference" bson:"six_hour_difference"`
OneDayVolume float64 `json:"one_day_volume" bson:"one_day_volume"`
OneDayChange float64 `json:"one_day_change" bson:"one_day_change"`
OneDaySales float64 `json:"one_day_sales" bson:"one_day_sales"`
//OneDaySalesChange float64 `json:"one_day_sales_change" bson:"one_day_sales_change"`
OneDayAveragePrice float64 `json:"one_day_average_price" bson:"one_day_average_price"`
//OneDayDifference float64 `json:"one_day_difference" bson:"one_day_difference"`
SevenDayVolume float64 `json:"seven_day_volume" bson:"seven_day_volume"`
SevenDayChange float64 `json:"seven_day_change" bson:"seven_day_change"`
SevenDaySales float64 `json:"seven_day_sales" bson:"seven_day_sales"`
SevenDayAveragePrice float64 `json:"seven_day_average_price" bson:"seven_day_average_price"`
//SevenDayDifference float64 `json:"seven_day_difference" bson:"seven_day_difference"`
ThirtyDayVolume float64 `json:"thirty_day_volume" bson:"thirty_day_volume"`
ThirtyDayChange float64 `json:"thirty_day_change" bson:"thirty_day_change"`
ThirtyDaySales float64 `json:"thirty_day_sales" bson:"thirty_day_sales"`
ThirtyDayAveragePrice float64 `json:"thirty_day_average_price" bson:"thirty_day_average_price"`
//ThirtyDayDifference float64 `json:"thirty_day_difference" bson:"thirty_day_difference"`
TotalVolume float64 `json:"total_volume" bson:"total_volume"`
TotalSales float64 `json:"total_sales" bson:"total_sales"`
TotalSupply float64 `json:"total_supply" bson:"total_supply"`
Count float64 `json:"count" bson:"count"`
NumOwners float64 `json:"num_owners" bson:"num_owners"`
AveragePrice float64 `json:"average_price" bson:"average_price"`
NumReports float64 `json:"num_reports" bson:"num_reports"`
MarketCap float64 `json:"market_cap" bson:"market_cap"`
FloorPrice float64 `json:"floor_price" bson:"floor_price"`
}
type CollectionSingleResponse struct {
Collection CollectionSingle `json:"collection" bson:"collection"`
}
type CollectionSingle struct {
Editors []Address `json:"editors" bson:"editors"`
PaymentTokens []PaymentToken `json:"payment_tokens" bson:"payment_tokens"`
PrimaryAssetContracts []Contract `json:"primary_asset_contracts" bson:"primary_asset_contracts"`
Traits interface{} `json:"traits" bson:"traits"`
Collection
}