wowok 1.5.36 → 1.5.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/reward.ts DELETED
@@ -1,317 +0,0 @@
1
- /*****************
2
- * depreacted
3
- ******************/
4
-
5
- import { TransactionArgument, Transaction as TransactionBlock, type TransactionResult, } from '@mysten/sui/transactions';
6
- import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
7
- import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidU64, parseObjectType} from './utils';
8
- import { ERROR, Errors } from './exception';
9
-
10
- export type CoinReward = TransactionResult;
11
- export type RewardGuardPortions = {
12
- guard:GuardObject;
13
- portions:number;
14
- }
15
-
16
- export class Reward {
17
- protected earnest_type;
18
- protected permission ;
19
- protected object:TxbObject;
20
- protected txb;
21
-
22
- get_earnest_type() { return this.earnest_type }
23
- get_object() { return this.object }
24
- private constructor(txb:TransactionBlock, earnest_type:string, permission:PermissionObject) {
25
- this.txb = txb
26
- this.earnest_type = earnest_type
27
- this.permission = permission
28
- this.object = ''
29
- }
30
- static From(txb:TransactionBlock, earnest_type:string, permission:PermissionObject, object:TxbObject) : Reward {
31
- let r = new Reward(txb, earnest_type, permission);
32
- r.object = Protocol.TXB_OBJECT(txb, object);
33
- return r
34
- }
35
- static New(txb:TransactionBlock, earnest_type:string, permission:PermissionObject, description:string,
36
- ms_expand:boolean, time:number, passport?:PassportObject) : Reward {
37
- if (!Protocol.IsValidObjects([permission])) {
38
- ERROR(Errors.IsValidObjects, 'permission')
39
- }
40
- if (!IsValidArgType(earnest_type)) {
41
- ERROR(Errors.IsValidArgType, 'earnest_type')
42
- }
43
- if (!IsValidDesription(description)) {
44
- ERROR(Errors.IsValidDesription)
45
- }
46
- if (!IsValidU64(time)) {
47
- ERROR(Errors.IsValidUint, 'time')
48
- }
49
-
50
- let r = new Reward(txb, earnest_type, permission);
51
- const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
52
- if (passport) {
53
- r.object = txb.moveCall({
54
- target:Protocol.Instance().RewardFn('new_with_passport') as FnCallType,
55
- arguments:[passport, txb.pure.string(description), txb.pure.bool(ms_expand), txb.pure.u64(time),
56
- txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
57
- typeArguments:[earnest_type]
58
- })
59
- } else {
60
- r.object = txb.moveCall({
61
- target:Protocol.Instance().RewardFn('new') as FnCallType,
62
- arguments:[txb.pure.string(description), txb.pure.bool(ms_expand), txb.pure.u64(time),
63
- txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
64
- typeArguments:[earnest_type]
65
- })
66
- }
67
- return r
68
- }
69
-
70
- launch(): RewardAddress {
71
- return this.txb.moveCall({
72
- target:Protocol.Instance().RewardFn('create') as FnCallType,
73
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
74
- typeArguments:[this.earnest_type]
75
- })
76
- }
77
-
78
- destroy() {
79
- this.txb.moveCall({
80
- target:Protocol.Instance().RewardFn('destroy') as FnCallType,
81
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
82
- })
83
- }
84
-
85
- refund(passport?:PassportObject) {
86
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
87
- if (passport) {
88
- this.txb.moveCall({
89
- target:Protocol.Instance().RewardFn('refund_with_passport') as FnCallType,
90
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
91
- typeArguments:[this.earnest_type]
92
- })
93
- } else {
94
- this.txb.moveCall({
95
- target:Protocol.Instance().RewardFn('refund') as FnCallType,
96
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
97
- typeArguments:[this.earnest_type]
98
- })
99
- }
100
- }
101
-
102
- expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
103
- if (!IsValidU64(time)) {
104
- ERROR(Errors.IsValidUint, 'minutes_expand')
105
- }
106
-
107
- if (passport) {
108
- this.txb.moveCall({
109
- target:Protocol.Instance().RewardFn('time_expand_with_passport') as FnCallType,
110
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(ms_expand),
111
- this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)],
112
- typeArguments:[this.earnest_type]
113
- })
114
- } else {
115
- this.txb.moveCall({
116
- target:Protocol.Instance().RewardFn('time_expand') as FnCallType,
117
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object),this.txb.pure.bool(ms_expand),
118
- this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)],
119
- typeArguments:[this.earnest_type]
120
- })
121
- }
122
- }
123
-
124
- add_guard(guards:RewardGuardPortions[], passport?:PassportObject) {
125
- if (guards.length === 0) return;
126
-
127
- let bValid = true;
128
- guards.forEach((v) => {
129
- if (!IsValidU64(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
130
- if (!Protocol.IsValidObjects([v.guard])) bValid = false;
131
- })
132
- if (!bValid) {
133
- ERROR(Errors.InvalidParam, 'guards')
134
- }
135
-
136
- if (passport) {
137
- guards.forEach((guard) =>
138
- this.txb.moveCall({
139
- target:Protocol.Instance().RewardFn('guard_add_with_passport') as FnCallType,
140
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
141
- Protocol.TXB_OBJECT(this.txb, guard.guard), this.txb.pure.u8(guard.portions),
142
- Protocol.TXB_OBJECT(this.txb, this.permission)],
143
- typeArguments:[this.earnest_type]
144
- })
145
- )
146
- } else {
147
- guards.forEach((guard) =>
148
- this.txb.moveCall({
149
- target:Protocol.Instance().RewardFn('guard_add') as FnCallType,
150
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard.guard),
151
- this.txb.pure.u8(guard.portions), Protocol.TXB_OBJECT(this.txb, this.permission)],
152
- typeArguments:[this.earnest_type]
153
- })
154
- )
155
- }
156
- }
157
-
158
- remove_guard(guards:string[], removeall?:boolean, passport?:PassportObject) {
159
- if (!removeall && guards.length===0) {
160
- return
161
- }
162
-
163
- if (!IsValidArray(guards, IsValidAddress)) {
164
- ERROR(Errors.IsValidArray, 'guards')
165
- }
166
-
167
- if (passport) {
168
- if (removeall) {
169
- this.txb.moveCall({
170
- target:Protocol.Instance().RewardFn('guard_remove_all_with_passport') as FnCallType,
171
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
172
- typeArguments:[this.earnest_type]
173
- })
174
- } else {
175
- this.txb.moveCall({
176
- target:Protocol.Instance().RewardFn('guard_remove_with_passport') as FnCallType,
177
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(guards)),
178
- Protocol.TXB_OBJECT(this.txb, this.permission)],
179
- typeArguments:[this.earnest_type]
180
- })
181
- }
182
- } else {
183
- if (removeall) {
184
- this.txb.moveCall({
185
- target:Protocol.Instance().RewardFn('guard_remove_all') as FnCallType,
186
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
187
- typeArguments:[this.earnest_type]
188
- })
189
- } else {
190
- this.txb.moveCall({
191
- target:Protocol.Instance().RewardFn('guard_remove') as FnCallType,
192
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(guards)),
193
- Protocol.TXB_OBJECT(this.txb, this.permission)],
194
- typeArguments:[this.earnest_type]
195
- })
196
- }
197
- }
198
-
199
- }
200
- allow_repeat_claim(allow_repeat_claim:boolean, passport?:PassportObject) {
201
- if (passport) {
202
- this.txb.moveCall({
203
- target:Protocol.Instance().RewardFn('allow_repeat_claim_with_passport') as FnCallType,
204
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission),
205
- this.txb.pure.bool(allow_repeat_claim)],
206
- typeArguments:[this.earnest_type]
207
- })
208
- } else {
209
- this.txb.moveCall({
210
- target:Protocol.Instance().RewardFn('allow_repeat_claim') as FnCallType,
211
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission),
212
- this.txb.pure.bool(allow_repeat_claim)],
213
- typeArguments:[this.earnest_type]
214
- })
215
- }
216
- }
217
-
218
- set_description(description:string, passport?:PassportObject) {
219
- if (!IsValidDesription(description)) {
220
- ERROR(Errors.IsValidDesription)
221
- }
222
-
223
- if (passport) {
224
- this.txb.moveCall({
225
- target:Protocol.Instance().RewardFn('description_set_with_passport') as FnCallType,
226
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
227
- typeArguments:[this.earnest_type]
228
- })
229
- } else {
230
- this.txb.moveCall({
231
- target:Protocol.Instance().RewardFn('description_set') as FnCallType,
232
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
233
- typeArguments:[this.earnest_type]
234
- })
235
- }
236
- }
237
-
238
- lock_guards(passport?:PassportObject) {
239
- if (passport) {
240
- this.txb.moveCall({
241
- target:Protocol.Instance().RewardFn('guard_lock_with_passport') as FnCallType,
242
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
243
- typeArguments:[this.earnest_type]
244
- })
245
- } else {
246
- this.txb.moveCall({
247
- target:Protocol.Instance().RewardFn('guard_lock') as FnCallType,
248
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
249
- typeArguments:[this.earnest_type]
250
- })
251
- }
252
- }
253
-
254
- claim(passport?:PassportObject) {
255
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
256
- if (passport) {
257
- this.txb.moveCall({
258
- target:Protocol.Instance().RewardFn('claim_with_passport') as FnCallType,
259
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock)],
260
- typeArguments:[this.earnest_type]
261
- })
262
- } else {
263
- this.txb.moveCall({
264
- target:Protocol.Instance().RewardFn('claim') as FnCallType,
265
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock)],
266
- typeArguments:[this.earnest_type]
267
- })
268
- }
269
- }
270
-
271
- deposit(objects:(TransactionResult | TransactionArgument)[]) {
272
- if (!objects || !Protocol.IsValidObjects(objects)) {
273
- ERROR(Errors.IsValidArray)
274
- }
275
-
276
- this.txb.moveCall({
277
- target:Protocol.Instance().RewardFn('deposit') as FnCallType,
278
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:array_unique(objects)})], //@
279
- typeArguments:[this.earnest_type]
280
- })
281
- }
282
-
283
- allow_claim(bAllowClaim: boolean, passport?:PassportObject) {
284
- if (passport) {
285
- this.txb.moveCall({
286
- target:Protocol.Instance().RewardFn('allow_claim_with_passport') as FnCallType,
287
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission),
288
- this.txb.pure.bool(bAllowClaim)],
289
- typeArguments:[this.earnest_type]
290
- })
291
- } else {
292
- this.txb.moveCall({
293
- target:Protocol.Instance().RewardFn('allow_claim') as FnCallType,
294
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.pure.bool(bAllowClaim)],
295
- typeArguments:[this.earnest_type]
296
- })
297
- }
298
- }
299
-
300
- change_permission(new_permission:PermissionObject) {
301
- if (!Protocol.IsValidObjects([new_permission])) {
302
- ERROR(Errors.IsValidObjects)
303
- }
304
-
305
- this.txb.moveCall({
306
- target:Protocol.Instance().RewardFn('permission_set') as FnCallType,
307
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
308
- typeArguments:[this.earnest_type]
309
- })
310
- this.permission = new_permission
311
- }
312
- static parseObjectType = (chain_type:string) : string => {
313
- return parseObjectType(chain_type, 'reward::Reward<')
314
- }
315
- static MAX_PORTIONS_COUNT = 600;
316
- static MAX_GUARD_COUNT = 16;
317
- }