-
Notifications
You must be signed in to change notification settings - Fork 4
/
collection.go
141 lines (122 loc) · 4.75 KB
/
collection.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
package imx
import (
"context"
"github.com/immutable/imx-core-sdk-golang/imx/api"
)
/*
CreateCollection Creates a new collection
A collection refers to a series of NFTs, minted under a project, and corresponds to a specific deployed smart contract.
All minted assets belong to a collection, and in order to mint assets on L2 you must first register your collection (smart contract) with Immutable X.
* Each collection belongs to a project.
* Each collection may contain many similar or different NFTs.
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param l1signer Ethereum signer used for ownership authentication.
@param createCollectionRequest The request struct with all the params.
@return Collection
*/
func (c *Client) CreateCollection(
ctx context.Context,
l1signer L1Signer,
createCollectionRequest *api.CreateCollectionRequest,
) (*api.Collection, error) {
timestamp, signature, err := generateIMXAuthorisationHeaders(l1signer)
if err != nil {
return nil, err
}
createCollectionResponse, httpResponse, err := c.CollectionsAPI.CreateCollection(ctx).
CreateCollectionRequest(*createCollectionRequest).
IMXTimestamp(timestamp).
IMXSignature(signature).
Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return createCollectionResponse, nil
}
/*
UpdateCollection Updates an existing collection
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param l1signer Ethereum signer used for ownership authentication.
@param contractAddress Collection contract address
@param updateCollectionRequest The request struct with all the params.
@return Collection
*/
func (c *Client) UpdateCollection(
ctx context.Context,
l1signer L1Signer,
contractAddress string,
updateCollectionRequest *api.UpdateCollectionRequest,
) (*api.Collection, error) {
timestamp, signature, err := generateIMXAuthorisationHeaders(l1signer)
if err != nil {
return nil, err
}
createCollectionResponse, httpResponse, err := c.CollectionsAPI.UpdateCollection(ctx, contractAddress).
UpdateCollectionRequest(*updateCollectionRequest).
IMXTimestamp(timestamp).
IMXSignature(signature).
Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return createCollectionResponse, nil
}
/*
GetCollection Get details of a collection at the given address
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param collectionContractAddress Collection contract address
@return Collection
*/
func (c *Client) GetCollection(ctx context.Context, collectionContractAddress string) (*api.Collection, error) {
response, httpResponse, err := c.CollectionsAPI.GetCollection(ctx, collectionContractAddress).Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}
/*
NewListCollectionsRequest Creates a new ApiListCollectionsRequest object with required params.
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@return ApiListCollectionsRequest
*/
func (c *Client) NewListCollectionsRequest(ctx context.Context) api.ApiListCollectionsRequest {
return c.CollectionsAPI.ListCollections(ctx)
}
/*
ListCollections Get a list of collections
@param req the api request struct with all params populated to make the request
@return ListCollectionsResponse
*/
func (c *Client) ListCollections(req *api.ApiListCollectionsRequest) (*api.ListCollectionsResponse, error) {
response, httpResponse, err := c.CollectionsAPI.ListCollectionsExecute(*req)
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}
/*
NewListCollectionFiltersRequest Creates a new ApiListCollectionFiltersRequest object with required params.
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param collectionContractAddress Collection contract address
@return ApiListCollectionFiltersRequest
*/
func (c *Client) NewListCollectionFiltersRequest(ctx context.Context, collectionContractAddress string) api.ApiListCollectionFiltersRequest {
return c.CollectionsAPI.ListCollectionFilters(ctx, collectionContractAddress)
}
/*
ListCollectionFilters Get a list of collection filters
@param req the api request struct with all params populated to make the request
@return CollectionFilter
*/
func (c *Client) ListCollectionFilters(req *api.ApiListCollectionFiltersRequest) (*api.CollectionFilter, error) {
response, httpResponse, err := c.CollectionsAPI.ListCollectionFiltersExecute(*req)
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}