-
Notifications
You must be signed in to change notification settings - Fork 4
/
project.go
116 lines (102 loc) · 3.48 KB
/
project.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
package imx
import (
"context"
"github.com/immutable/imx-core-sdk-golang/imx/api"
)
/*
CreateProject Creates a new project
In order to create a collection of NFTs, you must first register a project as the creator of the collection.
A project is an administrative level entity that is associated with an owner address, i.e. the address of the Ethereum wallet used to register a user account.
Only the project owner will be authorized to perform administrative tasks such as creating and updating collections and metadata schema.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@param l1signer Ethereum signer used for ownership authentication.
@param projectName Project name
@param companyName Company name to whom this project belongs to.
@param contactEmail Contact email for this project.
@return CreateProjectResponse
*/
func (c *Client) CreateProject(
ctx context.Context,
l1signer L1Signer,
projectName, companyName, contactEmail string,
) (*api.CreateProjectResponse, error) {
timestamp, signature, err := generateIMXAuthorisationHeaders(l1signer)
if err != nil {
return nil, err
}
createProjectRequest := api.NewCreateProjectRequest(companyName, contactEmail, projectName)
createProjectResponse, httpResponse, err := c.ProjectsAPI.CreateProject(ctx).
CreateProjectRequest(*createProjectRequest).
IMXTimestamp(timestamp).
IMXSignature(signature).
Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return createProjectResponse, nil
}
/*
GetProject Gets a project detail
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param l1signer Ethereum signer used for ownership authentication.
@param id Project ID
@return Balance
*/
func (c *Client) GetProject(ctx context.Context, l1signer L1Signer, id string) (*api.Project, error) {
timestamp, signature, err := generateIMXAuthorisationHeaders(l1signer)
if err != nil {
return nil, err
}
response, httpResponse, err := c.ProjectsAPI.GetProject(ctx, id).
IMXTimestamp(timestamp).
IMXSignature(signature).
Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}
/*
GetProjects Gets projects owned by given user
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param l1signer Ethereum signer used for ownership authentication.
@param pageSize The page size of the result
@param cursor The cursor
@param orderBy The property to sort by
@param direction Direction to sort (asc/desc)
@return GetProjectsResponse
*/
func (c *Client) GetProjects(
ctx context.Context,
l1signer L1Signer,
pageSize *int32,
cursor, orderBy, direction *string,
) (*api.GetProjectsResponse, error) {
timestamp, signature, err := generateIMXAuthorisationHeaders(l1signer)
if err != nil {
return nil, err
}
getProjectsRequest := c.ProjectsAPI.GetProjects(ctx).
IMXTimestamp(timestamp).
IMXSignature(signature)
if pageSize != nil {
getProjectsRequest.PageSize(*pageSize)
}
if cursor != nil {
getProjectsRequest.Cursor(*cursor)
}
if orderBy != nil {
getProjectsRequest.OrderBy(*orderBy)
}
if direction != nil {
getProjectsRequest.Direction(*direction)
}
response, httpResponse, err := getProjectsRequest.Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}