wowok 1.2.11 → 1.2.12

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