-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathobjects.go
228 lines (197 loc) · 7.63 KB
/
objects.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
package types
import (
"github.com/coming-chat/go-sui/v2/lib"
"github.com/coming-chat/go-sui/v2/sui_types"
)
type SuiObjectRef struct {
/** Base64 string representing the object digest */
Digest sui_types.TransactionDigest `json:"digest"`
/** Hex code as string representing the object id */
ObjectId string `json:"objectId"`
/** Object version */
Version sui_types.SequenceNumber `json:"version"`
}
type SuiGasData struct {
Payment []SuiObjectRef `json:"payment"`
/** Gas Object's owner */
Owner string `json:"owner"`
Price SafeSuiBigInt[uint64] `json:"price"`
Budget SafeSuiBigInt[uint64] `json:"budget"`
}
type SuiParsedData struct {
MoveObject *SuiParsedMoveObject `json:"moveObject,omitempty"`
Package *SuiMovePackage `json:"package,omitempty"`
}
func (p SuiParsedData) Tag() string {
return "dataType"
}
func (p SuiParsedData) Content() string {
return ""
}
type SuiMovePackage struct {
Disassembled map[string]interface{} `json:"disassembled"`
}
type SuiParsedMoveObject struct {
Type string `json:"type"`
HasPublicTransfer bool `json:"hasPublicTransfer"`
Fields any `json:"fields"`
}
type SuiRawData struct {
MoveObject *SuiRawMoveObject `json:"moveObject,omitempty"`
Package *SuiRawMovePackage `json:"package,omitempty"`
}
func (r SuiRawData) Tag() string {
return "dataType"
}
func (r SuiRawData) Content() string {
return ""
}
type SuiRawMoveObject struct {
Type string `json:"type"`
HasPublicTransfer bool `json:"hasPublicTransfer"`
Version sui_types.SequenceNumber `json:"version"`
BcsBytes lib.Base64Data `json:"bcsBytes"`
}
type SuiRawMovePackage struct {
Id sui_types.ObjectID `json:"id"`
Version sui_types.SequenceNumber `json:"version"`
ModuleMap map[string]lib.Base64Data `json:"moduleMap"`
TypeOriginTable []TypeOrigin `json:"typeOriginTable"`
LinkageTable map[string]UpgradeInfo
}
type UpgradeInfo struct {
UpgradedId sui_types.ObjectID
UpgradedVersion sui_types.SequenceNumber
}
type TypeOrigin struct {
ModuleName string `json:"moduleName"`
StructName string `json:"structName"`
Package sui_types.ObjectID `json:"package"`
}
type SuiObjectData struct {
ObjectId sui_types.ObjectID `json:"objectId"`
Version SafeSuiBigInt[sui_types.SequenceNumber] `json:"version"`
Digest sui_types.ObjectDigest `json:"digest"`
/**
* Type of the object, default to be undefined unless SuiObjectDataOptions.showType is set to true
*/
Type *string `json:"type,omitempty"`
/**
* Move object content or package content, default to be undefined unless SuiObjectDataOptions.showContent is set to true
*/
Content *lib.TagJson[SuiParsedData] `json:"content,omitempty"`
/**
* Move object content or package content in BCS bytes, default to be undefined unless SuiObjectDataOptions.showBcs is set to true
*/
Bcs *lib.TagJson[SuiRawData] `json:"bcs,omitempty"`
/**
* The owner of this object. Default to be undefined unless SuiObjectDataOptions.showOwner is set to true
*/
Owner *ObjectOwner `json:"owner,omitempty"`
/**
* The digest of the transaction that created or last mutated this object.
* Default to be undefined unless SuiObjectDataOptions.showPreviousTransaction is set to true
*/
PreviousTransaction *sui_types.TransactionDigest `json:"previousTransaction,omitempty"`
/**
* The amount of SUI we would rebate if this object gets deleted.
* This number is re-calculated each time the object is mutated based on
* the present storage gas price.
* Default to be undefined unless SuiObjectDataOptions.showStorageRebate is set to true
*/
StorageRebate *SafeSuiBigInt[uint64] `json:"storageRebate,omitempty"`
/**
* Display metadata for this object, default to be undefined unless SuiObjectDataOptions.showDisplay is set to true
* This can also be None if the struct type does not have Display defined
* See more details in https://forums.sui.io/t/nft-object-display-proposal/4872
*/
Display interface{} `json:"display,omitempty"`
}
func (data *SuiObjectData) Reference() sui_types.ObjectRef {
return sui_types.ObjectRef{
ObjectId: data.ObjectId,
Version: data.Version.data,
Digest: data.Digest.Data(),
}
}
type SuiObjectDataOptions struct {
/* Whether to fetch the object type, default to be false */
ShowType bool `json:"showType,omitempty"`
/* Whether to fetch the object content, default to be false */
ShowContent bool `json:"showContent,omitempty"`
/* Whether to fetch the object content in BCS bytes, default to be false */
ShowBcs bool `json:"showBcs,omitempty"`
/* Whether to fetch the object owner, default to be false */
ShowOwner bool `json:"showOwner,omitempty"`
/* Whether to fetch the previous transaction digest, default to be false */
ShowPreviousTransaction bool `json:"showPreviousTransaction,omitempty"`
/* Whether to fetch the storage rebate, default to be false */
ShowStorageRebate bool `json:"showStorageRebate,omitempty"`
/* Whether to fetch the display metadata, default to be false */
ShowDisplay bool `json:"showDisplay,omitempty"`
}
type SuiObjectResponseError struct {
NotExists *struct {
ObjectId sui_types.ObjectID `json:"object_id"`
} `json:"notExists,omitempty"`
Deleted *struct {
ObjectId sui_types.ObjectID `json:"object_id"`
Version sui_types.SequenceNumber `json:"version"`
Digest sui_types.ObjectDigest `json:"digest"`
} `json:"deleted,omitempty"`
UnKnown *struct{} `json:"unKnown"`
DisplayError *struct {
Error string `json:"error"`
} `json:"displayError"`
}
func (e SuiObjectResponseError) Tag() string {
return "code"
}
func (e SuiObjectResponseError) Content() string {
return ""
}
type SuiObjectResponse struct {
Data *SuiObjectData `json:"data,omitempty"`
Error *lib.TagJson[SuiObjectResponseError] `json:"error,omitempty"`
}
type CheckpointSequenceNumber = uint64
type CheckpointedObjectId struct {
ObjectId sui_types.ObjectID `json:"objectId"`
AtCheckpoint *SafeSuiBigInt[CheckpointSequenceNumber] `json:"atCheckpoint"`
}
type ObjectsPage = Page[SuiObjectResponse, sui_types.ObjectID]
// TODO need use Enum
type SuiObjectDataFilter struct {
Package *sui_types.ObjectID `json:"Package,omitempty"`
MoveModule *MoveModule `json:"MoveModule,omitempty"`
StructType string `json:"StructType,omitempty"`
}
type SuiObjectResponseQuery struct {
Filter *SuiObjectDataFilter `json:"filter,omitempty"`
Options *SuiObjectDataOptions `json:"options,omitempty"`
}
type SuiPastObjectResponse = lib.TagJson[SuiPastObject]
// TODO need test VersionNotFound
type SuiPastObject struct {
/// The object exists and is found with this version
VersionFound *SuiObjectData `json:"VersionFound,omitempty"`
/// The object does not exist
ObjectNotExists *sui_types.ObjectID `json:"ObjectNotExists,omitempty"`
/// The object is found to be deleted with this version
ObjectDeleted *SuiObjectRef `json:"ObjectDeleted,omitempty"`
/// The object exists but not found with this version
VersionNotFound *struct{ ObjectId sui_types.SequenceNumber } `json:"VersionNotFound,omitempty"`
/// The asked object version is higher than the latest
VersionTooHigh *struct {
ObjectId sui_types.ObjectID `json:"object_id"`
AskedVersion sui_types.SequenceNumber `json:"asked_version"`
LatestVersion sui_types.SequenceNumber `json:"latest_version"`
} `json:"VersionTooHigh,omitempty"`
}
func (s SuiPastObject) Tag() string {
return "status"
}
func (s SuiPastObject) Content() string {
return "details"
}
type SuiNamePage = Page[string, sui_types.ObjectID]