-
Notifications
You must be signed in to change notification settings - Fork 3
/
asset.go
202 lines (165 loc) · 6.79 KB
/
asset.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
package atomicasset
import (
"github.com/eosswedenorg-go/unixtime"
)
// Types
type Asset struct {
ID string `json:"asset_id"`
Contract string `json:"contract"`
Owner string `json:"owner"`
Name string `json:"name"`
IsTransferable bool `json:"is_transferable"`
IsBurnable bool `json:"is_burnable"`
TemplateMint string `json:"template_mint"`
Collection Collection `json:"collection"`
Schema InlineSchema `json:"schema"`
Template Template `json:"template"`
BackedTokens []Token `json:"backed_tokens"`
Data map[string]interface{} `json:"data"`
ImmutableData map[string]interface{} `json:"immutable_data"`
MutableData map[string]interface{} `json:"mutable_data"`
BurnedByAccount string `json:"burned_by_account"`
BurnedAtBlock string `json:"burned_at_block"`
BurnedAtTime unixtime.Time `json:"burned_at_time"`
UpdatedAtBlock string `json:"updated_at_block"`
UpdatedAtTime unixtime.Time `json:"updated_at_time"`
TransferedAtBlock string `json:"transferred_at_block"`
TransferedAtTime unixtime.Time `json:"transferred_at_time"`
MintedAtBlock string `json:"minted_at_block"`
MintedAtTime unixtime.Time `json:"minted_at_time"`
}
type ListingAsset struct {
AssetID string `json:"asset_id"`
Contract string `json:"contract"`
Onwer string `json:"owner"`
Name string `json:"name"`
IsTransferable bool `json:"is_transferable"`
IsBurnable bool `json:"is_burnable"`
TemplateMint string `json:"template_mint"`
Collection Collection `json:"collection"`
Schema InlineSchema `json:"schema"`
Template Template `json:"template"`
BackedTokens []Token `json:"backed_tokens"`
ImmutableData map[string]interface{} `json:"immutable_data"`
MutableData map[string]interface{} `json:"mutable_data"`
Data map[string]interface{} `json:"data"`
BurnedByAccount string `json:"burned_by_account"`
BurnedAtBlock string `json:"burned_at_block"`
BurnedAtTime unixtime.Time `json:"burned_at_time"`
UpdatedAtBlock string `json:"updated_at_block"`
UpdatedAtTime unixtime.Time `json:"updated_at_time"`
TransferedAtBlock string `json:"transferred_at_block"`
TransferedAtTime unixtime.Time `json:"transferred_at_time"`
MintedAtBlock string `json:"minted_at_block"`
MintedAtTime unixtime.Time `json:"minted_at_time"`
Sales []Sale `json:"sales"`
Auctions []Auction `json:"actions"`
Prices []Price `json:"prices"`
}
type AssetSale struct {
ID string `json:"sale_id"`
MarketContract string `json:"market_contract"`
AuctionID string `json:"auction_id"`
BuyOfferID string `json:"buyoffer_id"`
Price string `json:"price"`
TokenSymbol string `json:"token_symbol"`
TokenPrecision int64 `json:"token_precision"`
TokenContract string `json:"token_contract"`
Seller string `json:"seller"`
Buyer string `json:"buyer"`
BlockTime unixtime.Time `json:"block_time"`
}
// Request Parameters
// AssetsRequestParams holds the parameters for an Asset request
type AssetsRequestParams struct {
CollectionName string `qs:"collection_name,omitempty"`
CollectionBlacklist ReqList[string] `qs:"collection_blacklist,omitempty"`
CollectionWhitelist ReqList[string] `qs:"collection_whitelist,omitempty"`
SchemaName string `qs:"schema_name,omitempty"`
TemplateID int `qs:"template_id,omitempty"`
TemplateWhitelist ReqList[int] `qs:"template_whitelist,omitempty"`
TemplateBlacklist ReqList[int] `qs:"template_blacklist,omitempty"`
Owner string `qs:"owner,omitempty"`
Match string `qs:"match,omitempty"`
MatchImmutableName string `qs:"match_immutable_name,omitempty"`
MatchMutableName string `qs:"match_mutable_name,omitempty"`
HideTemplatesByAccounts string `qs:"hide_templates_by_accounts,omitempty"`
IsTransferable bool `qs:"is_transferable,omitempty"`
IsBurnable bool `qs:"is_burnable,omitempty"`
Burned bool `qs:"burned,omitempty"`
OnlyDuplicatedTemplates bool `qs:"only_duplicated_templates,omitempty"`
HasBackedTokens bool `qs:"has_backend_tokens,omitempty"`
HideOffers bool `qs:"hide_offers,omitempty"`
LowerBound string `qs:"lower_bound,omitempty"`
UpperBound string `qs:"upper_bound,omitempty"`
Before int `qs:"before,omitempty"`
After int `qs:"after,omitempty"`
Limit int `qs:"limit,omitempty"`
Order SortOrder `qs:"order,omitempty"`
Sort string `qs:"sort,omitempty"`
}
// AssetSalesRequestParams holds the parameters for an AssetSales request
type AssetSalesRequestParams struct {
Buyer string `qs:"buyer,omitempty"`
Seller string `qs:"seller,omitempty"`
Symbol string `qs:"symbol,omitempty"`
Order SortOrder `qs:"order,omitempty"`
}
// Responses
type AssetResponse struct {
APIResponse
Data Asset
}
type AssetsResponse struct {
APIResponse
Data []Asset
}
type AssetSalesResponse struct {
APIResponse
Data []AssetSale
}
type AssetLogResponse struct {
APIResponse
Data []Log
}
// API Client functions
// GetAssets fetches "/atomicassets/v1/assets" from API
func (c *Client) GetAssets(params AssetsRequestParams) (AssetsResponse, error) {
var assets AssetsResponse
r, err := c.fetch("GET", "/atomicassets/v1/assets", params, &assets.APIResponse)
if err == nil {
// Parse json
err = r.Unmarshal(&assets)
}
return assets, err
}
// GetAsset fetches "/atomicassets/v1/assets/{asset_id}" from API
func (c *Client) GetAsset(assetID string) (AssetResponse, error) {
var asset AssetResponse
r, err := c.fetch("GET", "/atomicassets/v1/assets/"+assetID, nil, &asset.APIResponse)
if err == nil {
// Parse json
err = r.Unmarshal(&asset)
}
return asset, err
}
// GetAssetLog fetches "/atomicassets/v1/assets/{asset_id}/logs" from API
func (c *Client) GetAssetLog(assetID string, params LogRequestParams) (AssetLogResponse, error) {
var logs AssetLogResponse
r, err := c.fetch("GET", "/atomicassets/v1/assets/"+assetID+"/logs", params, &logs.APIResponse)
if err == nil {
// Parse json
err = r.Unmarshal(&logs)
}
return logs, err
}
// GetAssetSales fetches "/atomicmarket/v1/assets/{asset_id}/sales" from API
func (c *Client) GetAssetSales(assetID string, params AssetSalesRequestParams) (AssetSalesResponse, error) {
var sales AssetSalesResponse
r, err := c.fetch("GET", "/atomicmarket/v1/assets/"+assetID+"/sales", params, &sales.APIResponse)
if err == nil {
// Parse json
err = r.Unmarshal(&sales)
}
return sales, err
}