forked from block-vision/sui-go-sdk
/
read_object.go
256 lines (212 loc) · 6.89 KB
/
read_object.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
package models
import (
"encoding/json"
"github.com/tidwall/gjson"
)
type SuiObjectDataOptions struct {
ShowType bool `json:"showType"`
ShowContent bool `json:"showContent"`
ShowBcs bool `json:"showBcs"`
ShowOwner bool `json:"showOwner"`
ShowPreviousTransaction bool `json:"showPreviousTransaction"`
ShowStorageRebate bool `json:"showStorageRebate"`
ShowDisplay bool `json:"showDisplay"`
}
type SuiObjectDataFilter map[string]interface{}
type ObjectFilterByPackage struct {
Package string `json:"Package"`
}
type ObjectFilterByStructType struct {
StructType string `json:"StructType"`
}
type ObjectFilterByAddressOwner struct {
AddressOwner string `json:"AddressOwner"`
}
type ObjectFilterByObjectOwner struct {
ObjectOwner string `json:"ObjectOwner"`
}
type ObjectFilterByObjectId struct {
ObjectId string `json:"ObjectId"`
}
type ObjectFilterByObjectIds struct {
ObjectIds []string `json:"ObjectIds"`
}
type ObjectFilterByVersion struct {
Version string `json:"Version"`
}
type SuiObjectResponseQuery struct {
// If None, no filter will be applied
Filter interface{} `json:"filter"`
// config which fields to include in the response, by default only digest is included
Options SuiObjectDataOptions `json:"options"`
}
type SuiGetObjectRequest struct {
// the ID of the queried object
ObjectId string `json:"ObjectId"`
// config which fields to include in the response, by default only digest is included
Options SuiObjectDataOptions `json:"options"`
}
type SuiXGetOwnedObjectsRequest struct {
// the owner's Sui address
Address string `json:"address" validate:"checkAddress"`
// the objects query criteria
Query SuiObjectResponseQuery
// optional paging cursor
Cursor interface{} `json:"cursor"`
// maximum number of items per page
Limit uint64 `json:"limit" validate:"lte=50"`
}
type PaginatedObjectsResponse struct {
Data []SuiObjectResponse `json:"data"`
NextCursor string `json:"nextCursor"`
HasNextPage bool `json:"hasNextPage"`
}
type SuiObjectResponse struct {
Data *SuiObjectData `json:"data,omitempty"`
Error *SuiObjectResponseError `json:"error,omitempty"`
}
type SuiObjectResponseError struct {
Code string `json:"code"`
Error string `json:"error"`
ObjectId string `json:"object_id"`
Version int `json:"version"`
Digest string `json:"digest"`
}
type ObjectOwner struct {
// the owner's Sui address
AddressOwner string `json:"AddressOwner"`
ObjectOwner string `json:"ObjectOwner"`
Shared ObjectShare `json:"Shared"`
}
type ObjectShare struct {
InitialSharedVersion int `json:"initial_shared_version"`
}
type SuiRawMoveObject struct {
Type string `json:"type"`
HasPublicTransfer bool `json:"hasPublicTransfer"`
Version int `json:"version"`
BcsBytes string `json:"bcsBytes"`
}
type DisplayFieldsResponse struct {
Data any `json:"data"`
Error *SuiObjectResponseError `json:"error"`
}
type Display interface {
Name() string
Description() string
Link() string
ImageURL() string
ThumbnailURL() string
ProjectURL() string
Creator() string
}
func (display DisplayFieldsResponse) Description() string {
return display.value("description")
}
func (display DisplayFieldsResponse) Name() string {
return display.value("name")
}
func (display DisplayFieldsResponse) Link() string {
return display.value("link")
}
func (display DisplayFieldsResponse) ImageURL() string {
return display.value("image_url")
}
func (display DisplayFieldsResponse) ThumbnailURL() string {
return display.value("thumbnail_url")
}
func (display DisplayFieldsResponse) Creator() string {
return display.value("creator")
}
func (display DisplayFieldsResponse) ProjectURL() string {
return display.value("project_url")
}
func (display DisplayFieldsResponse) value(field string) string {
if display.Data == nil {
return ""
}
bys, _ := json.Marshal(display.Data)
return gjson.GetBytes(bys, field).String()
}
type SuiParsedData struct {
DataType string `json:"dataType"`
SuiMoveObject
SuiMovePackage
}
type SuiObjectData struct {
ObjectId string `json:"objectId"`
Version string `json:"version"`
Digest string `json:"digest"`
Type string `json:"type"`
Owner interface{} `json:"owner"`
PreviousTransaction string `json:"previousTransaction,omitempty"`
Display DisplayFieldsResponse `json:"display"`
Content *SuiParsedData `json:"content,omitempty"`
Bcs *SuiRawData `json:"bcs,omitempty"`
}
type SuiMultiGetObjectsRequest struct {
ObjectIds []string `json:"objectIds"`
Options SuiObjectDataOptions `json:"options"`
}
type SuiXGetDynamicFieldRequest struct {
ObjectId string `json:"objectId"`
// optional paging cursor
Cursor interface{} `json:"cursor"`
// maximum number of items per page
Limit uint64 `json:"limit" validate:"lte=50"`
}
type DynamicFieldInfo struct {
Name DynamicFieldName `json:"name"`
BcsName string `json:"bcsName"`
Type string `json:"type"`
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId"`
Version int `json:"version"`
Digest string `json:"digest"`
}
type PaginatedDynamicFieldInfoResponse struct {
Data []DynamicFieldInfo `json:"data"`
NextCursor string `json:"nextCursor"`
HasNextPage bool `json:"hasNextPage"`
}
type SuiXGetDynamicFieldObjectRequest struct {
ObjectId string `json:"objectId"`
DynamicFieldName DynamicFieldObjectName `json:"dynamicFieldName"`
}
type SuiTryGetPastObjectRequest struct {
// the ID of the queried object
ObjectId string `json:"objectId"`
// the version of the queried object
Version uint64 `json:"version"`
Options SuiObjectDataOptions `json:"options"`
}
type PastObjectResponse struct {
Status string `json:"status"`
Details interface{} `json:"details"`
}
type SuiGetLoadedChildObjectsRequest struct {
Digest string `json:"digest"`
}
type ChildObjectsResponse struct {
LoadedChildObjects []*SuiLoadedChildObject `json:"loadedChildObjects"`
}
type SuiLoadedChildObject struct {
ObjectID string `json:"objectId"`
SequenceNumber string `json:"sequenceNumber"`
}
type PastObject struct {
// the ID of the queried object
ObjectId string `json:"objectId"`
// the version of the queried object
Version string `json:"version"`
}
type SuiTryMultiGetPastObjectsRequest struct {
// a vector of object and versions to be queried
MultiGetPastObjects []*PastObject
// options for specifying the content to be returned
Options SuiObjectDataOptions
}
type DynamicFieldObjectName struct {
Type string `json:"type"`
Value interface{} `json:"value"`
}