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/utils.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, BcsReader } from '@mysten/bcs';
2
- import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
3
- import { SuiObjectResponse, DynamicFieldPage } from '@mysten/sui.js/client';
2
+ import { Transaction as TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui/transactions';
3
+ import { SuiObjectResponse, DynamicFieldPage } from '@mysten/sui/client';
4
4
  import { ERROR, Errors } from './exception';
5
- import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui.js/utils'
5
+ import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils'
6
6
  import { RepositoryValueType, ValueType, Protocol } from './protocol'
7
7
 
8
8
  export const MAX_U8 = BigInt('255');
@@ -314,7 +314,8 @@ export class Bcs {
314
314
  const dislike = reader.read32();
315
315
  return {avatar:avatar, resource:resource, like:like, dislike:dislike}*/
316
316
  }
317
- de_entInfo(data:Uint8Array) : any {
317
+ de_entInfo(data:Uint8Array | undefined) : any {
318
+ if (!data || data.length === 0) return ''
318
319
  let r = this.bcs.de('PersonalInfo', data);
319
320
  r.name = new TextDecoder().decode(Uint8Array.from(r.name));
320
321
  r.description = new TextDecoder().decode(Uint8Array.from(r.description));
@@ -473,8 +474,6 @@ export const ResolveBalance = (balance:string, decimals:number) : string => {
473
474
  }
474
475
  }
475
476
 
476
- export const OptionNone = (txb:TransactionBlock) : TransactionArgument => { return txb.pure([], BCS.U8) };
477
-
478
477
  export type ArgType = {
479
478
  isCoin: boolean;
480
479
  coin: string;
package/src/vote.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { FnCallType, PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject} from './protocol';
3
- import { IsValidDesription, IsValidUintLarge, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
2
+ import { IsValidDesription, IsValidUintLarge, IsValidAddress, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
4
3
  import { ERROR, Errors } from './exception';
5
4
  import { ValueType } from './protocol';
5
+ import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
6
6
 
7
7
  export const MAX_AGREES_COUNT = 200;
8
8
  export const MAX_CHOICE_COUNT = 200;
@@ -15,20 +15,20 @@ export type VoteOption = {
15
15
  export class Vote {
16
16
  protected permission;
17
17
  protected object : TxbObject;
18
- protected protocol;
18
+ protected txb;
19
19
 
20
20
  get_object() { return this.object }
21
- private constructor(protocol:Protocol, permission:PermissionObject) {
21
+ private constructor(txb:TransactionBlock, permission:PermissionObject) {
22
22
  this.object = '';
23
- this.protocol = protocol;
23
+ this.txb = txb;
24
24
  this.permission = permission;
25
25
  }
26
- static From(protocol:Protocol, permission:PermissionObject, object:TxbObject) : Vote {
27
- let v = new Vote(protocol, permission);
28
- v.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object)
26
+ static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Vote {
27
+ let v = new Vote(txb, permission);
28
+ v.object = Protocol.TXB_OBJECT(txb, object)
29
29
  return v
30
30
  }
31
- static New(protocol:Protocol, permission:PermissionObject, description:string, minutes_duration:boolean, time:number,
31
+ static New(txb:TransactionBlock, permission:PermissionObject, description:string, minutes_duration:boolean, time:number,
32
32
  max_choice_count?:number, reference_address?:string, passport?:PassportObject) : Vote {
33
33
  if (!Protocol.IsValidObjects([permission])) {
34
34
  ERROR(Errors.IsValidObjects, 'permission')
@@ -49,40 +49,38 @@ export class Vote {
49
49
  ERROR(Errors.IsValidAddress, 'reference_address')
50
50
  }
51
51
 
52
- let v = new Vote(protocol, permission);
53
- let txb = protocol.CurrentSession();
54
- let reference = reference_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
52
+ let v = new Vote(txb, permission);
53
+
54
+ let reference = txb.pure.option('address', reference_address ? reference_address : undefined);
55
55
  let choice_count = max_choice_count ? max_choice_count : 1;
56
-
56
+ const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
57
57
  if (passport) {
58
58
  v.object = txb.moveCall({
59
- target:protocol.VoteFn('new_with_passport') as FnCallType,
60
- arguments:[passport, txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT), txb.pure(minutes_duration, BCS.BOOL),
61
- txb.pure(time, BCS.U64), txb.pure(choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, permission)]
59
+ target:Protocol.Instance().VoteFn('new_with_passport') as FnCallType,
60
+ arguments:[passport, txb.pure.string(description), reference, txb.object(clock), txb.pure.bool(minutes_duration),
61
+ txb.pure.u64(time), txb.pure.u8(choice_count), Protocol.TXB_OBJECT(txb, permission)]
62
62
  })
63
63
  } else {
64
64
  v.object = txb.moveCall({
65
- target:protocol.VoteFn('new') as FnCallType,
66
- arguments:[txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT), txb.pure(minutes_duration, BCS.BOOL),
67
- txb.pure(time, BCS.U64), txb.pure(choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, permission)]
65
+ target:Protocol.Instance().VoteFn('new') as FnCallType,
66
+ arguments:[txb.pure.string(description), reference, txb.object(clock), txb.pure.bool(minutes_duration),
67
+ txb.pure.u64(time), txb.pure.u8(choice_count), Protocol.TXB_OBJECT(txb, permission)]
68
68
  })
69
69
  }
70
70
  return v
71
71
  }
72
72
 
73
73
  launch() : VoteAddress {
74
- let txb = this.protocol.CurrentSession();
75
- return txb.moveCall({
76
- target:this.protocol.VoteFn('create') as FnCallType,
77
- arguments:[Protocol.TXB_OBJECT(txb, this.object)]
74
+ return this.txb.moveCall({
75
+ target:Protocol.Instance().VoteFn('create') as FnCallType,
76
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
78
77
  })
79
78
  }
80
79
 
81
80
  destroy() {
82
- let txb = this.protocol.CurrentSession();
83
- txb.moveCall({
84
- target:this.protocol.VoteFn('destroy') as FnCallType,
85
- arguments:[Protocol.TXB_OBJECT(txb, this.object)]
81
+ this.txb.moveCall({
82
+ target:Protocol.Instance().VoteFn('destroy') as FnCallType,
83
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
86
84
  })
87
85
  }
88
86
 
@@ -90,38 +88,35 @@ export class Vote {
90
88
  if (!IsValidDesription(description)) {
91
89
  ERROR(Errors.IsValidDesription)
92
90
  }
93
-
94
- let txb = this.protocol.CurrentSession();
91
+
95
92
  if (passport) {
96
- txb.moveCall({
97
- target:this.protocol.VoteFn('description_set_with_passport') as FnCallType,
98
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
93
+ this.txb.moveCall({
94
+ target:Protocol.Instance().VoteFn('description_set_with_passport') as FnCallType,
95
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
99
96
  })
100
97
  } else {
101
- txb.moveCall({
102
- target:this.protocol.VoteFn('description_set') as FnCallType,
103
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
98
+ this.txb.moveCall({
99
+ target:Protocol.Instance().VoteFn('description_set') as FnCallType,
100
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
104
101
  })
105
102
  }
106
-
107
103
  }
108
104
 
109
- set_reference(reference_address?:string, passport?:PassportObject) {
105
+ set_reference(reference_address?:string|null, passport?:PassportObject) {
110
106
  if (reference_address && !IsValidAddress(reference_address)) {
111
107
  ERROR(Errors.IsValidAddress)
112
108
  }
113
-
114
- let txb = this.protocol.CurrentSession();
115
- let reference = reference_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
109
+
110
+ let reference = this.txb.pure.option('address', reference_address ? reference_address : undefined);
116
111
  if (passport) {
117
- txb.moveCall({
118
- target:this.protocol.VoteFn('reference_set_with_passport') as FnCallType,
119
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), reference, Protocol.TXB_OBJECT(txb, this.permission)]
112
+ this.txb.moveCall({
113
+ target:Protocol.Instance().VoteFn('reference_set_with_passport') as FnCallType,
114
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
120
115
  })
121
116
  } else {
122
- txb.moveCall({
123
- target:this.protocol.VoteFn('reference_set') as FnCallType,
124
- arguments:[Protocol.TXB_OBJECT(txb, this.object), reference, Protocol.TXB_OBJECT(txb, this.permission)]
117
+ this.txb.moveCall({
118
+ target:Protocol.Instance().VoteFn('reference_set') as FnCallType,
119
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
125
120
  })
126
121
  }
127
122
 
@@ -134,18 +129,17 @@ export class Vote {
134
129
  ERROR(Errors.IsValidUint, 'add_guard')
135
130
  }
136
131
 
137
- let txb = this.protocol.CurrentSession();
138
132
  if (passport) {
139
- txb.moveCall({
140
- target:this.protocol.VoteFn('guard_add_with_passport') as FnCallType,
141
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard),
142
- txb.pure(weight, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
133
+ this.txb.moveCall({
134
+ target:Protocol.Instance().VoteFn('guard_add_with_passport') as FnCallType,
135
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
136
+ this.txb.pure.u64(weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
143
137
  })
144
138
  } else {
145
- txb.moveCall({
146
- target:this.protocol.VoteFn('guard_add') as FnCallType,
147
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard),
148
- txb.pure(weight, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
139
+ this.txb.moveCall({
140
+ target:Protocol.Instance().VoteFn('guard_add') as FnCallType,
141
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
142
+ this.txb.pure.u64(weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
149
143
  })
150
144
  }
151
145
  }
@@ -156,33 +150,32 @@ export class Vote {
156
150
  if (!IsValidArray(guard_address, IsValidAddress)) {
157
151
  ERROR(Errors.IsValidArray, 'remove_guard')
158
152
  }
159
-
160
- let txb = this.protocol.CurrentSession();
153
+
161
154
  if (passport) {
162
155
  if (removeall) {
163
- txb.moveCall({
164
- target:this.protocol.VoteFn('guard_remove_all_with_passport') as FnCallType,
165
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
156
+ this.txb.moveCall({
157
+ target:Protocol.Instance().VoteFn('guard_remove_all_with_passport') as FnCallType,
158
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
166
159
  })
167
160
  } else {
168
- txb.moveCall({
169
- target:this.protocol.VoteFn('guard_remove_with_passport') as FnCallType,
170
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
171
- txb.pure(array_unique(guard_address), 'vector<address>'), Protocol.TXB_OBJECT(txb, this.permission)]
161
+ this.txb.moveCall({
162
+ target:Protocol.Instance().VoteFn('guard_remove_with_passport') as FnCallType,
163
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
164
+ this.txb.pure.vector('address', array_unique(guard_address)), Protocol.TXB_OBJECT(this.txb, this.permission)]
172
165
  })
173
166
  }
174
167
  } else {
175
168
  if (removeall) {
176
- txb.moveCall({
177
- target:this.protocol.VoteFn('guard_remove_all') as FnCallType,
178
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
169
+ this.txb.moveCall({
170
+ target:Protocol.Instance().VoteFn('guard_remove_all') as FnCallType,
171
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
179
172
  })
180
173
  } else {
181
- txb.moveCall({
182
- target:this.protocol.VoteFn('guard_remove') as FnCallType,
183
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
184
- txb.pure(array_unique(guard_address), 'vector<address>'),
185
- Protocol.TXB_OBJECT(txb, this.permission)]
174
+ this.txb.moveCall({
175
+ target:Protocol.Instance().VoteFn('guard_remove') as FnCallType,
176
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
177
+ this.txb.pure.vector('address', array_unique(guard_address)),
178
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
186
179
  })
187
180
  }
188
181
  }
@@ -200,23 +193,20 @@ export class Vote {
200
193
  ERROR(Errors.InvalidParam, 'options')
201
194
  }
202
195
 
203
- let txb = this.protocol.CurrentSession();
204
196
  options.forEach((option) => {
205
- let reference = option?.reference_address ?
206
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, option.reference_address)) :
207
- OptionNone(txb);
197
+ let reference = this.txb.pure.option('address', option?.reference_address) ;
208
198
 
209
199
  if (passport) {
210
- txb.moveCall({
211
- target:this.protocol.VoteFn('agrees_add_with_passport') as FnCallType,
212
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(option.name),
213
- reference, Protocol.TXB_OBJECT(txb, this.permission)]
200
+ this.txb.moveCall({
201
+ target:Protocol.Instance().VoteFn('agrees_add_with_passport') as FnCallType,
202
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(option.name),
203
+ reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
214
204
  })
215
205
  } else {
216
- txb.moveCall({
217
- target:this.protocol.VoteFn('agrees_add') as FnCallType,
218
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(option.name),
219
- reference, Protocol.TXB_OBJECT(txb, this.permission)]
206
+ this.txb.moveCall({
207
+ target:Protocol.Instance().VoteFn('agrees_add') as FnCallType,
208
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(option.name),
209
+ reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
220
210
  })
221
211
  }
222
212
  })
@@ -228,34 +218,33 @@ export class Vote {
228
218
  if (options && !IsValidArray(options, IsValidAddress)) {
229
219
  ERROR(Errors.IsValidArray, 'remove_option')
230
220
  }
231
-
232
- let txb = this.protocol.CurrentSession();
221
+
233
222
  if (passport) {
234
223
  if (removeall) {
235
- txb.moveCall({
236
- target:this.protocol.VoteFn('agrees_remove_all_with_passport') as FnCallType,
237
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
224
+ this.txb.moveCall({
225
+ target:Protocol.Instance().VoteFn('agrees_remove_all_with_passport') as FnCallType,
226
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
238
227
  })
239
228
  } else {
240
- txb.moveCall({
241
- target:this.protocol.VoteFn('agrees_remove_with_passport') as FnCallType,
242
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
243
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
244
- Protocol.TXB_OBJECT(txb, this.permission)]
229
+ this.txb.moveCall({
230
+ target:Protocol.Instance().VoteFn('agrees_remove_with_passport') as FnCallType,
231
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
232
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
233
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
245
234
  })
246
235
  }
247
236
  } else {
248
237
  if (removeall) {
249
- txb.moveCall({
250
- target:this.protocol.VoteFn('agrees_remove_all') as FnCallType,
251
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
238
+ this.txb.moveCall({
239
+ target:Protocol.Instance().VoteFn('agrees_remove_all') as FnCallType,
240
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
252
241
  })
253
242
  } else {
254
- txb.moveCall({
255
- target:this.protocol.VoteFn('agrees_remove') as FnCallType,
256
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
257
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
258
- Protocol.TXB_OBJECT(txb, this.permission)]
243
+ this.txb.moveCall({
244
+ target:Protocol.Instance().VoteFn('agrees_remove') as FnCallType,
245
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
246
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
247
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
259
248
  })
260
249
  }
261
250
  }
@@ -265,47 +254,45 @@ export class Vote {
265
254
  ERROR(Errors.InvalidParam, 'max_choice_count')
266
255
  }
267
256
 
268
- let txb = this.protocol.CurrentSession();
269
257
  if (passport) {
270
- txb.moveCall({
271
- target:this.protocol.VoteFn('max_choice_count_set_with_passport') as FnCallType,
272
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
273
- txb.pure(max_choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, this.permission)]
258
+ this.txb.moveCall({
259
+ target:Protocol.Instance().VoteFn('max_choice_count_set_with_passport') as FnCallType,
260
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
261
+ this.txb.pure.u8(max_choice_count), Protocol.TXB_OBJECT(this.txb, this.permission)]
274
262
  })
275
263
  } else {
276
- txb.moveCall({
277
- target:this.protocol.VoteFn('max_choice_count_set') as FnCallType,
278
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(max_choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, this.permission)]
264
+ this.txb.moveCall({
265
+ target:Protocol.Instance().VoteFn('max_choice_count_set') as FnCallType,
266
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(max_choice_count), Protocol.TXB_OBJECT(this.txb, this.permission)]
279
267
  })
280
268
  }
281
269
  }
282
270
 
283
271
  open_voting(passport?:PassportObject) {
284
- let txb = this.protocol.CurrentSession();
285
272
  if (passport) {
286
- txb.moveCall({
287
- target:this.protocol.VoteFn('options_locked_for_voting_with_passport') as FnCallType,
288
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
273
+ this.txb.moveCall({
274
+ target:Protocol.Instance().VoteFn('options_locked_for_voting_with_passport') as FnCallType,
275
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
289
276
  })
290
277
  } else {
291
- txb.moveCall({
292
- target:this.protocol.VoteFn('options_locked_for_voting') as FnCallType,
293
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
278
+ this.txb.moveCall({
279
+ target:Protocol.Instance().VoteFn('options_locked_for_voting') as FnCallType,
280
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
294
281
  })
295
282
  }
296
283
  }
297
284
 
298
285
  lock_deadline(passport?:PassportObject) {
299
- let txb = this.protocol.CurrentSession();
286
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
300
287
  if (passport) {
301
- txb.moveCall({
302
- target:this.protocol.VoteFn('deadline_locked_with_passport') as FnCallType,
303
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)]
288
+ this.txb.moveCall({
289
+ target:Protocol.Instance().VoteFn('deadline_locked_with_passport') as FnCallType,
290
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)]
304
291
  })
305
292
  } else {
306
- txb.moveCall({
307
- target:this.protocol.VoteFn('deadline_locked') as FnCallType,
308
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)]
293
+ this.txb.moveCall({
294
+ target:Protocol.Instance().VoteFn('deadline_locked') as FnCallType,
295
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)]
309
296
  })
310
297
  }
311
298
  }
@@ -314,34 +301,32 @@ export class Vote {
314
301
  if (!IsValidUintLarge(time)) {
315
302
  ERROR(Errors.IsValidUint, 'time')
316
303
  }
317
-
318
- let txb = this.protocol.CurrentSession();
304
+
319
305
  if (passport) {
320
- txb.moveCall({
321
- target:this.protocol.VoteFn('deadline_expand_with_passport') as FnCallType,
322
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
323
- txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
306
+ this.txb.moveCall({
307
+ target:Protocol.Instance().VoteFn('deadline_expand_with_passport') as FnCallType,
308
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(ms_expand),
309
+ this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)]
324
310
  })
325
311
  } else {
326
- txb.moveCall({
327
- target:this.protocol.VoteFn('deadline_expand') as FnCallType,
328
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
329
- txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
312
+ this.txb.moveCall({
313
+ target:Protocol.Instance().VoteFn('deadline_expand') as FnCallType,
314
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(ms_expand),
315
+ this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)]
330
316
  })
331
317
  }
332
-
333
318
  }
319
+
334
320
  lock_guard(passport?:PassportObject) {
335
- let txb = this.protocol.CurrentSession();
336
321
  if (passport) {
337
- txb.moveCall({
338
- target:this.protocol.VoteFn('guard_lock_with_passport') as FnCallType,
339
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
322
+ this.txb.moveCall({
323
+ target:Protocol.Instance().VoteFn('guard_lock_with_passport') as FnCallType,
324
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
340
325
  })
341
326
  } else {
342
- txb.moveCall({
343
- target:this.protocol.VoteFn('guard_lock') as FnCallType,
344
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
327
+ this.txb.moveCall({
328
+ target:Protocol.Instance().VoteFn('guard_lock') as FnCallType,
329
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
345
330
  })
346
331
  }
347
332
  }
@@ -352,32 +337,29 @@ export class Vote {
352
337
  ERROR(Errors.InvalidParam, 'agree')
353
338
  }
354
339
 
355
- let txb = this.protocol.CurrentSession();
356
340
  if (passport) {
357
- txb.moveCall({
358
- target:this.protocol.VoteFn('with_passport') as FnCallType,
359
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
360
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
341
+ this.txb.moveCall({
342
+ target:Protocol.Instance().VoteFn('with_passport') as FnCallType,
343
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
344
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
361
345
  })
362
346
  } else {
363
- txb.moveCall({
364
- target:this.protocol.VoteFn('this.object') as FnCallType,
365
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
366
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
347
+ this.txb.moveCall({
348
+ target:Protocol.Instance().VoteFn('this.object') as FnCallType,
349
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
350
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
367
351
  })
368
352
  }
369
-
370
353
  }
371
354
 
372
355
  change_permission(new_permission:PermissionObject) {
373
356
  if (!Protocol.IsValidObjects([new_permission])) {
374
357
  ERROR(Errors.IsValidObjects)
375
358
  }
376
-
377
- let txb = this.protocol.CurrentSession();
378
- txb.moveCall({
379
- target:this.protocol.VoteFn('this.permission_set') as FnCallType,
380
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb,this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
359
+
360
+ this.txb.moveCall({
361
+ target:Protocol.Instance().VoteFn('this.permission_set') as FnCallType,
362
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb,this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
381
363
  })
382
364
  this.permission = new_permission
383
365
  }
package/src/wowok.ts CHANGED
@@ -1,55 +1,50 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject} from './protocol';
3
2
  import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
4
3
  import { ERROR, Errors } from './exception';
5
-
4
+ import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
6
5
 
7
6
  export class Wowok {
8
7
 
9
8
  protected object:TxbObject;
10
- protected protocol;
9
+ protected txb;
11
10
 
12
11
  get_object() { return this.object }
13
- private constructor(protocol:Protocol) {
14
- this.protocol = protocol;
12
+ private constructor(txb:TransactionBlock) {
13
+ this.txb = txb;
15
14
  this.object = '';
16
15
  }
17
16
 
18
- static From(protocol:Protocol) : Wowok {
19
- let r = new Wowok(protocol);
20
- r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), protocol.WowokObject());
17
+ static From(txb:TransactionBlock) : Wowok {
18
+ let r = new Wowok(txb);
19
+ r.object = Protocol.TXB_OBJECT(txb, Protocol.Instance().WowokObject());
21
20
  return r
22
21
  }
23
22
 
24
23
  register_grantor(name:string, grantee_permission:PermissionObject) {
25
24
  if (!IsValidName(name)) ERROR(Errors.IsValidName, 'register_grantor');
26
25
  if (!Protocol.IsValidObjects([grantee_permission])) ERROR(Errors.IsValidObjects, 'register_grantor');
27
-
28
- let txb = this.protocol.CurrentSession();
29
- txb.moveCall({
30
- target:this.protocol.WowokFn('grantor_register') as FnCallType,
31
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.object(Protocol.CLOCK_OBJECT),
32
- Protocol.TXB_OBJECT(txb, grantee_permission)]
26
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
27
+
28
+ this.txb.moveCall({
29
+ target:Protocol.Instance().WowokFn('grantor_register') as FnCallType,
30
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name), this.txb.object(clock),
31
+ Protocol.TXB_OBJECT(this.txb, grantee_permission)]
33
32
  })
34
33
  }
35
34
 
36
35
  grantor_time_expand_1year(grantor:string) {
37
36
  if (!IsValidAddress(grantor)) ERROR(Errors.IsValidAddress, 'grantor_time_expand_1year');
38
-
39
- let txb = this.protocol.CurrentSession();
40
- txb.moveCall({
41
- target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
42
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(grantor, BCS.ADDRESS)]
37
+ this.txb.moveCall({
38
+ target:Protocol.Instance().WowokFn('grantor_time_expand_1year') as FnCallType,
39
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(grantor)]
43
40
  })
44
41
  }
45
42
 
46
43
  grantor_rename(new_name:string) {
47
44
  if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'grantor_rename');
48
-
49
- let txb = this.protocol.CurrentSession();
50
- txb.moveCall({
51
- target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
52
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_name)]
45
+ this.txb.moveCall({
46
+ target:Protocol.Instance().WowokFn('grantor_time_expand_1year') as FnCallType,
47
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(new_name)]
53
48
  })
54
49
  }
55
50
  }