wowok 1.2.11 → 1.3.3

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