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/repository.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
3
2
  import { PermissionIndexType, Permission } from './permission'
4
- import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, IsValidName, ValueTypeConvert} from './utils';
3
+ import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert} from './utils';
5
4
  import { ERROR, Errors } from './exception';
6
5
  import { MAX_U8, MAX_U128, MAX_U256, MAX_U64 } from './utils';
6
+ import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
7
7
 
8
8
  export enum Repository_Policy_Mode {
9
9
  POLICY_MODE_FREE = 0,
@@ -37,20 +37,20 @@ export type Repository_Value = {
37
37
  export class Repository {
38
38
  protected permission ;
39
39
  protected object:TxbObject;
40
- protected protocol;
40
+ protected txb;
41
41
 
42
42
  get_object() { return this.object }
43
- private constructor(protocol:Protocol, permission:PermissionObject) {
44
- this.protocol = protocol;
43
+ private constructor(txb:TransactionBlock, permission:PermissionObject) {
44
+ this.txb = txb;
45
45
  this.permission = permission;
46
46
  this.object = '';
47
47
  }
48
- static From(protocol:Protocol, permission:PermissionObject, object:TxbObject) : Repository {
49
- let r = new Repository(protocol, permission);
50
- r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
48
+ static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Repository {
49
+ let r = new Repository(txb, permission);
50
+ r.object = Protocol.TXB_OBJECT(txb, object);
51
51
  return r
52
52
  }
53
- static New(protocol:Protocol, permission:PermissionObject, description:string,
53
+ static New(txb:TransactionBlock, permission:PermissionObject, description:string,
54
54
  policy_mode: Repository_Policy_Mode, passport?:PassportObject) : Repository {
55
55
  if (!Protocol.IsValidObjects([permission])) {
56
56
  ERROR(Errors.IsValidObjects, 'permission')
@@ -59,36 +59,34 @@ export class Repository {
59
59
  ERROR(Errors.IsValidDesription)
60
60
  }
61
61
 
62
- let r = new Repository(protocol, permission);
63
- let txb = protocol.CurrentSession();
62
+ let r = new Repository(txb, permission);
64
63
 
65
64
  if (passport) {
66
65
  r.object = txb.moveCall({
67
- target:protocol.RepositoryFn('new_with_passport') as FnCallType,
68
- arguments:[passport, txb.pure(description), txb.pure(policy_mode, BCS.U8), Protocol.TXB_OBJECT(txb, permission)],
66
+ target:Protocol.Instance().RepositoryFn('new_with_passport') as FnCallType,
67
+ arguments:[passport, txb.pure.string(description), txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(txb, permission)],
69
68
  })
70
69
  } else {
71
70
  r.object = txb.moveCall({
72
- target:protocol.RepositoryFn('new') as FnCallType,
73
- arguments:[txb.pure(description), txb.pure(policy_mode, BCS.U8), Protocol.TXB_OBJECT(txb, permission)],
71
+ target:Protocol.Instance().RepositoryFn('new') as FnCallType,
72
+ arguments:[txb.pure.string(description), txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(txb, permission)],
74
73
  })
75
74
  }
76
75
  return r
77
76
  }
78
77
 
79
78
  launch() : RepositoryAddress {
80
- let txb = this.protocol.CurrentSession();
81
- return txb.moveCall({
82
- target:this.protocol.RepositoryFn('create') as FnCallType,
83
- arguments:[Protocol.TXB_OBJECT(txb, this.object)],
79
+ return this.txb.moveCall({
80
+ target:Protocol.Instance().RepositoryFn('create') as FnCallType,
81
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
84
82
  })
85
83
  }
84
+
86
85
  destroy() {
87
86
  if (!Protocol.IsValidObjects([this.object])) return false;
88
- let txb = this.protocol.CurrentSession();
89
- txb.moveCall({
90
- target:this.protocol.RepositoryFn('destroy') as FnCallType,
91
- arguments: [Protocol.TXB_OBJECT(txb, this.object)],
87
+ this.txb.moveCall({
88
+ target:Protocol.Instance().RepositoryFn('destroy') as FnCallType,
89
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
92
90
  })
93
91
  }
94
92
 
@@ -105,27 +103,26 @@ export class Repository {
105
103
  if (!bValid) {
106
104
  ERROR(Errors.InvalidParam)
107
105
  }
108
-
109
- let txb = this.protocol.CurrentSession();
110
- if (data?.value_type) {
111
- data.data.forEach((d) => txb.moveCall({
112
- target:this.protocol.RepositoryFn('add') as FnCallType,
113
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
114
- txb.pure(d.address, BCS.ADDRESS),
115
- txb.pure(data.key),
116
- txb.pure(data.value_type, BCS.U8),
117
- txb.pure([...d.bcsBytes], 'vector<u8>'),
118
- Protocol.TXB_OBJECT(txb, this.permission),
106
+
107
+ if (data?.value_type !== undefined) {
108
+ data.data.forEach((d) => this.txb.moveCall({
109
+ target:Protocol.Instance().RepositoryFn('add') as FnCallType,
110
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
111
+ this.txb.pure.address(d.address),
112
+ this.txb.pure.string(data.key),
113
+ this.txb.pure.u8(data.value_type!),
114
+ this.txb.pure.vector('u8', [...d.bcsBytes]),
115
+ Protocol.TXB_OBJECT(this.txb, this.permission),
119
116
  ],
120
117
  }))
121
118
  } else {
122
- data.data.forEach((d) => txb.moveCall({
123
- target:this.protocol.RepositoryFn('add_typed_data') as FnCallType,
124
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
125
- txb.pure(d.address, BCS.ADDRESS),
126
- txb.pure(data.key),
127
- txb.pure([...d.bcsBytes], 'vector<u8>'),
128
- Protocol.TXB_OBJECT(txb, this.permission),
119
+ data.data.forEach((d) => this.txb.moveCall({
120
+ target:Protocol.Instance().RepositoryFn('add_typed_data') as FnCallType,
121
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
122
+ this.txb.pure.address(d.address),
123
+ this.txb.pure.string(data.key),
124
+ this.txb.pure.vector('u8', [...d.bcsBytes]),
125
+ Protocol.TXB_OBJECT(this.txb, this.permission),
129
126
  ],
130
127
  }))
131
128
  }
@@ -138,14 +135,13 @@ export class Repository {
138
135
  if (!IsValidAddress(address)) {
139
136
  ERROR(Errors.IsValidAddress)
140
137
  }
141
-
142
- let txb = this.protocol.CurrentSession();
143
- txb.moveCall({
144
- target:this.protocol.RepositoryFn('remove') as FnCallType,
145
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
146
- txb.pure(address, BCS.ADDRESS),
147
- txb.pure(key),
148
- Protocol.TXB_OBJECT(txb, this.permission),
138
+
139
+ this.txb.moveCall({
140
+ target:Protocol.Instance().RepositoryFn('remove') as FnCallType,
141
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
142
+ this.txb.pure.address(address),
143
+ this.txb.pure.string(key),
144
+ Protocol.TXB_OBJECT(this.txb, this.permission),
149
145
  ],
150
146
  })
151
147
  }
@@ -154,21 +150,20 @@ export class Repository {
154
150
  if (!IsValidArray(references, IsValidAddress)) {
155
151
  ERROR(Errors.IsValidArray, 'add_reference')
156
152
  }
157
-
158
- let txb = this.protocol.CurrentSession();
153
+
159
154
  if (passport) {
160
- txb.moveCall({
161
- target:this.protocol.RepositoryFn('reference_add_with_passport') as FnCallType,
162
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
163
- txb.pure(array_unique(references), 'vector<address>'),
164
- Protocol.TXB_OBJECT(txb, this.permission)]
155
+ this.txb.moveCall({
156
+ target:Protocol.Instance().RepositoryFn('reference_add_with_passport') as FnCallType,
157
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
158
+ this.txb.pure.vector('address', array_unique(references)),
159
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
165
160
  })
166
161
  } else {
167
- txb.moveCall({
168
- target:this.protocol.RepositoryFn('reference_add') as FnCallType,
169
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
170
- txb.pure(array_unique(references), 'vector<address>'),
171
- Protocol.TXB_OBJECT(txb, this.permission)]
162
+ this.txb.moveCall({
163
+ target:Protocol.Instance().RepositoryFn('reference_add') as FnCallType,
164
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
165
+ this.txb.pure.vector('address', array_unique(references)),
166
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
172
167
  })
173
168
  }
174
169
  }
@@ -178,36 +173,35 @@ export class Repository {
178
173
  if (!IsValidArray(references, IsValidAddress)) {
179
174
  ERROR(Errors.IsValidArray, 'remove_reference')
180
175
  }
181
-
182
- let txb = this.protocol.CurrentSession();
176
+
183
177
  if (removeall) {
184
178
  if (passport) {
185
- txb.moveCall({
186
- target:this.protocol.RepositoryFn('reference_removeall_with_passport') as FnCallType,
187
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
188
- Protocol.TXB_OBJECT(txb, this.permission)]
179
+ this.txb.moveCall({
180
+ target:Protocol.Instance().RepositoryFn('reference_removeall_with_passport') as FnCallType,
181
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
182
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
189
183
  })
190
184
  } else {
191
- txb.moveCall({
192
- target:this.protocol.RepositoryFn('reference_removeall') as FnCallType,
193
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
194
- Protocol.TXB_OBJECT(txb, this.permission)]
185
+ this.txb.moveCall({
186
+ target:Protocol.Instance().RepositoryFn('reference_removeall') as FnCallType,
187
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
188
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
195
189
  })
196
190
  }
197
191
  } else {
198
192
  if (passport) {
199
- txb.moveCall({
200
- target:this.protocol.RepositoryFn('reference_remove_with_passport') as FnCallType,
201
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
202
- txb.pure(array_unique(references), 'vector<address>'),
203
- Protocol.TXB_OBJECT(txb, this.permission)]
193
+ this.txb.moveCall({
194
+ target:Protocol.Instance().RepositoryFn('reference_remove_with_passport') as FnCallType,
195
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
196
+ this.txb.pure.vector('address', array_unique(references)),
197
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
204
198
  })
205
199
  } else {
206
- txb.moveCall({
207
- target:this.protocol.RepositoryFn('reference_remove') as FnCallType,
208
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
209
- txb.pure(array_unique(references), 'vector<address>'),
210
- Protocol.TXB_OBJECT(txb, this.permission)]
200
+ this.txb.moveCall({
201
+ target:Protocol.Instance().RepositoryFn('reference_remove') as FnCallType,
202
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
203
+ this.txb.pure.vector('address', array_unique(references)),
204
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
211
205
  })
212
206
  }
213
207
  }
@@ -226,26 +220,25 @@ export class Repository {
226
220
  ERROR(Errors.InvalidParam, 'policies')
227
221
  }
228
222
 
229
- let txb = this.protocol.CurrentSession();
230
223
  policies.forEach((policy) => {
231
- let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, policy.permission)) : OptionNone(txb);
224
+ let permission_index = this.txb.pure.option('u64', policy?.permission ? policy?.permission : undefined);
232
225
  if (passport) {
233
- txb.moveCall({
234
- target:this.protocol.RepositoryFn('policy_add_with_passport') as FnCallType,
235
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
236
- txb.pure(policy.key),
237
- txb.pure(policy.description),
238
- permission_index, txb.pure(policy.data_type, BCS.U8),
239
- Protocol.TXB_OBJECT(txb, this.permission)]
226
+ this.txb.moveCall({
227
+ target:Protocol.Instance().RepositoryFn('policy_add_with_passport') as FnCallType,
228
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
229
+ this.txb.pure.string(policy.key),
230
+ this.txb.pure.string(policy.description),
231
+ permission_index, this.txb.pure.u8(policy.data_type),
232
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
240
233
  })
241
234
  } else {
242
- txb.moveCall({
243
- target:this.protocol.RepositoryFn('policy_add') as FnCallType,
244
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
245
- txb.pure(policy.key),
246
- txb.pure(policy.description),
247
- permission_index, txb.pure(policy.data_type, BCS.U8),
248
- Protocol.TXB_OBJECT(txb, this.permission)]
235
+ this.txb.moveCall({
236
+ target:Protocol.Instance().RepositoryFn('policy_add') as FnCallType,
237
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
238
+ this.txb.pure.string(policy.key),
239
+ this.txb.pure.string(policy.description),
240
+ permission_index, this.txb.pure.u8(policy.data_type),
241
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
249
242
  })
250
243
  }
251
244
  });
@@ -256,21 +249,20 @@ export class Repository {
256
249
  if (!IsValidArray(policy_keys, Repository.IsValidName)){
257
250
  ERROR(Errors.InvalidParam, 'policy_keys')
258
251
  }
259
-
260
- let txb = this.protocol.CurrentSession();
252
+
261
253
  if (passport) {
262
- txb.moveCall({
263
- target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
264
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
265
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
266
- Protocol.TXB_OBJECT(txb, this.permission)]
254
+ this.txb.moveCall({
255
+ target:Protocol.Instance().RepositoryFn('policy_remove_with_passport') as FnCallType,
256
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
257
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
258
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
267
259
  })
268
260
  } else {
269
- txb.moveCall({
270
- target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
271
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
272
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
273
- Protocol.TXB_OBJECT(txb, this.permission)]
261
+ this.txb.moveCall({
262
+ target:Protocol.Instance().RepositoryFn('policy_remove') as FnCallType,
263
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
264
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
265
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
274
266
  })
275
267
  }
276
268
  }
@@ -278,21 +270,20 @@ export class Repository {
278
270
  if (!IsValidName(policy_key) || !IsValidName(new_policy_key)) {
279
271
  ERROR(Errors.IsValidName, 'change_policy')
280
272
  }
281
-
282
- let txb = this.protocol.CurrentSession();
273
+
283
274
  if (passport) {
284
- txb.moveCall({
285
- target:this.protocol.RepositoryFn('policy_rename_with_passport') as FnCallType,
286
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
287
- txb.pure(policy_key), txb.pure(new_policy_key),
288
- Protocol.TXB_OBJECT(txb, this.permission)]
275
+ this.txb.moveCall({
276
+ target:Protocol.Instance().RepositoryFn('policy_rename_with_passport') as FnCallType,
277
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
278
+ this.txb.pure.string(policy_key), this.txb.pure.string(new_policy_key),
279
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
289
280
  })
290
281
  } else {
291
- txb.moveCall({
292
- target:this.protocol.RepositoryFn('policy_rename') as FnCallType,
293
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
294
- txb.pure(policy_key), txb.pure(new_policy_key),
295
- Protocol.TXB_OBJECT(txb, this.permission)]
282
+ this.txb.moveCall({
283
+ target:Protocol.Instance().RepositoryFn('policy_rename') as FnCallType,
284
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
285
+ this.txb.pure.string(policy_key), this.txb.pure.string(new_policy_key),
286
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
296
287
  })
297
288
  }
298
289
  }
@@ -302,33 +293,31 @@ export class Repository {
302
293
  if (!IsValidDesription(description)){
303
294
  ERROR(Errors.IsValidDesription)
304
295
  }
305
-
306
- let txb = this.protocol.CurrentSession();
296
+
307
297
  if (passport) {
308
- txb.moveCall({
309
- target:this.protocol.RepositoryFn('description_set_with_passport') as FnCallType,
310
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
298
+ this.txb.moveCall({
299
+ target:Protocol.Instance().RepositoryFn('description_set_with_passport') as FnCallType,
300
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
311
301
  })
312
302
  } else {
313
- txb.moveCall({
314
- target:this.protocol.RepositoryFn('description_set') as FnCallType,
315
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
303
+ this.txb.moveCall({
304
+ target:Protocol.Instance().RepositoryFn('description_set') as FnCallType,
305
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
316
306
  })
317
307
  }
318
308
 
319
309
  }
320
310
 
321
311
  set_policy_mode(policy_mode:Repository_Policy_Mode, passport?:PassportObject) {
322
- let txb = this.protocol.CurrentSession();
323
312
  if (passport) {
324
- txb.moveCall({
325
- target:this.protocol.RepositoryFn('policy_mode_set_with_passport') as FnCallType,
326
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy_mode), Protocol.TXB_OBJECT(txb, this.permission)]
313
+ this.txb.moveCall({
314
+ target:Protocol.Instance().RepositoryFn('policy_mode_set_with_passport') as FnCallType,
315
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(this.txb, this.permission)]
327
316
  })
328
317
  } else {
329
- txb.moveCall({
330
- target:this.protocol.RepositoryFn('policy_mode_set') as FnCallType,
331
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy_mode), Protocol.TXB_OBJECT(txb, this.permission)]
318
+ this.txb.moveCall({
319
+ target:Protocol.Instance().RepositoryFn('policy_mode_set') as FnCallType,
320
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(this.txb, this.permission)]
332
321
  })
333
322
  }
334
323
  }
@@ -340,19 +329,18 @@ export class Repository {
340
329
  if (!IsValidDesription(description)) {
341
330
  ERROR(Errors.IsValidDesription)
342
331
  }
343
-
344
- let txb = this.protocol.CurrentSession();
332
+
345
333
  if (passport) {
346
- txb.moveCall({
347
- target:this.protocol.RepositoryFn('policy_description_set_with_passport') as FnCallType,
348
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy), txb.pure(description),
349
- Protocol.TXB_OBJECT(txb, this.permission)]
334
+ this.txb.moveCall({
335
+ target:Protocol.Instance().RepositoryFn('policy_description_set_with_passport') as FnCallType,
336
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(policy), this.txb.pure.string(description),
337
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
350
338
  })
351
339
  } else {
352
- txb.moveCall({
353
- target:this.protocol.RepositoryFn('policy_description_set') as FnCallType,
354
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy), txb.pure(description),
355
- Protocol.TXB_OBJECT(txb, this.permission)]
340
+ this.txb.moveCall({
341
+ target:Protocol.Instance().RepositoryFn('policy_description_set') as FnCallType,
342
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(policy), this.txb.pure.string(description),
343
+ Protocol.TXB_OBJECT(this.txb, this.permission)]
356
344
  })
357
345
  }
358
346
  }
@@ -362,25 +350,23 @@ export class Repository {
362
350
  ERROR(Errors.IsValidName, 'policy')
363
351
  }
364
352
 
365
- let txb = this.protocol.CurrentSession();
366
- let index = OptionNone(txb);
367
-
368
- if (permission_index) {
353
+ let index = this.txb.pure.option('u64', undefined);
354
+ if (permission_index !== undefined) {
369
355
  if(!Permission.IsValidPermissionIndex(permission_index)) {
370
356
  ERROR(Errors.IsValidPermissionIndex)
371
357
  }
372
- index = txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, permission_index));
358
+ index = this.txb.pure.option('u64', permission_index);
373
359
  }
374
360
 
375
361
  if (passport) {
376
- txb.moveCall({
377
- target:this.protocol.RepositoryFn('policy_permission_set_with_passport') as FnCallType,
378
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), index, Protocol.TXB_OBJECT(txb, this.permission)]
362
+ this.txb.moveCall({
363
+ target:Protocol.Instance().RepositoryFn('policy_permission_set_with_passport') as FnCallType,
364
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), index, Protocol.TXB_OBJECT(this.txb, this.permission)]
379
365
  })
380
366
  } else {
381
- txb.moveCall({
382
- target:this.protocol.RepositoryFn('policy_permission_set') as FnCallType,
383
- arguments:[Protocol.TXB_OBJECT(txb, this.object), index, Protocol.TXB_OBJECT(txb, this.permission)]
367
+ this.txb.moveCall({
368
+ target:Protocol.Instance().RepositoryFn('policy_permission_set') as FnCallType,
369
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), index, Protocol.TXB_OBJECT(this.txb, this.permission)]
384
370
  })
385
371
  }
386
372
  }
@@ -389,10 +375,10 @@ export class Repository {
389
375
  if (!Protocol.IsValidObjects([new_permission])) {
390
376
  ERROR(Errors.IsValidObjects)
391
377
  }
392
- let txb = this.protocol.CurrentSession();
393
- txb.moveCall({
394
- target:this.protocol.RepositoryFn('permission_set') as FnCallType,
395
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
378
+
379
+ this.txb.moveCall({
380
+ target:Protocol.Instance().RepositoryFn('permission_set') as FnCallType,
381
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
396
382
  typeArguments:[]
397
383
  })
398
384
  this.permission = new_permission
package/src/resource.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { Protocol, FnCallType, TxbObject, ResourceAddress} from './protocol';
3
2
  import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
4
3
  import { ERROR, Errors } from './exception';
4
+ import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
5
+
5
6
  export interface Tags {
6
7
  address: string;
7
8
  nick: string;
@@ -22,36 +23,35 @@ export class Resource {
22
23
  static FavorName = "favor";
23
24
 
24
25
  protected object:TxbObject;
25
- protected protocol;
26
+ protected txb;
26
27
 
27
28
  get_object() { return this.object }
28
- private constructor(protocol:Protocol) {
29
- this.protocol = protocol;
29
+ private constructor(txb:TransactionBlock) {
30
+ this.txb = txb;
30
31
  this.object = '';
31
32
  }
32
33
 
33
- static From(protocol:Protocol, object:TxbObject) : Resource {
34
- let r = new Resource(protocol);
35
- r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
34
+ static From(txb:TransactionBlock, object:TxbObject) : Resource {
35
+ let r = new Resource(txb);
36
+ r.object = Protocol.TXB_OBJECT(txb, object);
36
37
  return r
37
38
  }
38
39
 
39
40
  launch() {
40
41
  if (!this.object) ERROR(Errors.Fail, 'launch object Invalid');
41
- let txb = this.protocol.CurrentSession();
42
- txb.moveCall({
43
- target:this.protocol.ResourceFn('create') as FnCallType,
44
- arguments:[Protocol.TXB_OBJECT(txb, this.object)]
42
+ this.txb.moveCall({
43
+ target:Protocol.Instance().ResourceFn('create') as FnCallType,
44
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
45
45
  });
46
46
  }
47
47
  add(name:string, object:string[]) {
48
48
  if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add');
49
49
  if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'add');
50
50
 
51
- let txb = this.protocol.CurrentSession();
52
- txb.moveCall({
53
- target:this.protocol.ResourceFn('add') as FnCallType,
54
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.pure(object, 'vector<address>')]
51
+ this.txb.moveCall({
52
+ target:Protocol.Instance().ResourceFn('add') as FnCallType,
53
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
54
+ this.txb.pure.vector('address', object)]
55
55
  });
56
56
  }
57
57
 
@@ -60,10 +60,10 @@ export class Resource {
60
60
  if (!IsValidArray(name, IsValidName)) ERROR(Errors.IsValidArray, 'add2');
61
61
  if (!name) return
62
62
 
63
- let txb = this.protocol.CurrentSession();
64
- txb.moveCall({
65
- target:this.protocol.ResourceFn('add2') as FnCallType,
66
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(name, 'vector<string>')]
63
+ this.txb.moveCall({
64
+ target:Protocol.Instance().ResourceFn('add2') as FnCallType,
65
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
66
+ this.txb.pure.vector('string', name)]
67
67
  });
68
68
  }
69
69
 
@@ -71,18 +71,18 @@ export class Resource {
71
71
  if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
72
72
  if (object.length===0 && !removeall) return;
73
73
 
74
- let txb = this.protocol.CurrentSession();
75
74
  if (removeall) {
76
- txb.moveCall({
77
- target:this.protocol.ResourceFn('remove_all') as FnCallType,
78
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name)]
75
+ this.txb.moveCall({
76
+ target:Protocol.Instance().ResourceFn('remove_all') as FnCallType,
77
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name)]
79
78
  });
80
79
  } else if(object) {
81
80
  if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
82
81
 
83
- txb.moveCall({
84
- target:this.protocol.ResourceFn('remove') as FnCallType,
85
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.pure(object, 'vector<address>')]
82
+ this.txb.moveCall({
83
+ target:Protocol.Instance().ResourceFn('remove') as FnCallType,
84
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
85
+ this.txb.pure.vector('address', object)]
86
86
  });
87
87
  }
88
88
  }
@@ -92,20 +92,20 @@ export class Resource {
92
92
  if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
93
93
  if (!name) return
94
94
 
95
- let txb = this.protocol.CurrentSession();
96
- txb.moveCall({
97
- target:this.protocol.ResourceFn('remove2') as FnCallType,
98
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(name, 'vector<string>')]
95
+ this.txb.moveCall({
96
+ target:Protocol.Instance().ResourceFn('remove2') as FnCallType,
97
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
98
+ this.txb.pure.vector('string', name)]
99
99
  });
100
100
  }
101
101
 
102
102
  rename(old_name:string, new_name:string) {
103
103
  if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'Resource: rename');
104
104
 
105
- let txb = this.protocol.CurrentSession();
106
- txb.moveCall({
107
- target:this.protocol.ResourceFn('rename') as FnCallType,
108
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_name), txb.pure(new_name)]
105
+ this.txb.moveCall({
106
+ target:Protocol.Instance().ResourceFn('rename') as FnCallType,
107
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(old_name),
108
+ this.txb.pure.string(new_name)]
109
109
  });
110
110
  }
111
111
 
@@ -116,25 +116,22 @@ export class Resource {
116
116
  if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'add_tags');
117
117
  if (tags.length > Resource.MAX_TAGS) ERROR(Errors.InvalidParam, 'add_tags');
118
118
 
119
- const txb = this.protocol.CurrentSession();
120
119
  const encode = new TextEncoder();
121
-
122
- txb.moveCall({
123
- target:this.protocol.ResourceFn('tags_add') as FnCallType,
124
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS),
125
- txb.pure(nick),
126
- txb.pure(tags, 'vector<string>')
120
+ this.txb.moveCall({
121
+ target:Protocol.Instance().ResourceFn('tags_add') as FnCallType,
122
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
123
+ this.txb.pure.string(nick),
124
+ this.txb.pure.vector('string', tags)
127
125
  ]
128
126
  });
129
127
  }
130
128
 
131
129
  remove_tags(object:string) {
132
130
  if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove_tags');
133
-
134
- let txb = this.protocol.CurrentSession();
135
- txb.moveCall({
136
- target:this.protocol.ResourceFn('tags_remove') as FnCallType,
137
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS)]
131
+
132
+ this.txb.moveCall({
133
+ target:Protocol.Instance().ResourceFn('tags_remove') as FnCallType,
134
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object)]
138
135
  });
139
136
  }
140
137
  }