wowok 1.2.12 → 1.3.4

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/service.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
2
1
  import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
3
- IsValidAddress, IsValidEndpoint, IsValidUintLarge, IsValidInt, IsValidName, } from './utils'
2
+ IsValidAddress, IsValidEndpoint, IsValidU64, IsValidName,} from './utils'
4
3
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
5
4
  ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
6
5
  TxbObject} from './protocol';
@@ -13,8 +12,8 @@ export type Service_Guard_Percent = {
13
12
  }
14
13
  export type Service_Sale = {
15
14
  item:string;
16
- price:number;
17
- stock:number;
15
+ price:bigint;
16
+ stock:bigint;
18
17
  endpoint?:string;
19
18
  }
20
19
  export enum Service_Discount_Type {
@@ -27,7 +26,7 @@ export type Service_Discount = {
27
26
  off: number;
28
27
  duration_minutes: number;
29
28
  time_start?: number; // current time if undefined
30
- price_greater?: number;
29
+ price_greater?: bigint;
31
30
  }
32
31
 
33
32
  export type Service_Buy_RequiredInfo = {
@@ -48,13 +47,13 @@ export enum BuyRequiredEnum {
48
47
 
49
48
  export type Service_Buy = {
50
49
  item: string;
51
- max_price: number;
52
- count: number;
50
+ max_price: bigint;
51
+ count: bigint;
53
52
  }
54
53
 
55
54
  export type DicountDispatch = {
56
55
  receiver: string;
57
- count: number;
56
+ count: bigint;
58
57
  discount: Service_Discount;
59
58
  }
60
59
 
@@ -153,9 +152,9 @@ export class Service {
153
152
  })
154
153
  }
155
154
  }
156
- set_price(item:string, price:number, bNotFoundAssert:boolean=true, passport?:PassportObject) {
157
- if (!IsValidInt(price)) {
158
- ERROR(Errors.IsValidInt, 'price')
155
+ set_price(item:string, price:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
156
+ if (!IsValidU64(price)) {
157
+ ERROR(Errors.IsValidU64, 'price')
159
158
  }
160
159
  if (!IsValidName(item)) {
161
160
  ERROR(Errors.IsValidName, 'item')
@@ -179,12 +178,12 @@ export class Service {
179
178
  })
180
179
  }
181
180
  }
182
- set_stock(item:string, stock:number, bNotFoundAssert:boolean=true, passport?:PassportObject) {
181
+ set_stock(item:string, stock:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
183
182
  if (!IsValidName(item)) {
184
183
  ERROR(Errors.IsValidName, 'item')
185
184
  }
186
- if (!IsValidInt(stock)) {
187
- ERROR(Errors.IsValidInt, 'stock')
185
+ if (!IsValidU64(stock)) {
186
+ ERROR(Errors.IsValidU64, 'stock')
188
187
  }
189
188
 
190
189
  if (passport) {
@@ -205,11 +204,11 @@ export class Service {
205
204
  })
206
205
  }
207
206
  }
208
- add_stock(item:string, stock_add:number, bNotFoundAssert:boolean=true, passport?:PassportObject) {
207
+ add_stock(item:string, stock_add:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
209
208
  if (!IsValidName(item)) {
210
209
  ERROR(Errors.IsValidName, 'item')
211
210
  }
212
- if (!IsValidUintLarge(stock_add)) {
211
+ if (!IsValidU64(stock_add)) {
213
212
  ERROR(Errors.IsValidUint, 'stock_add')
214
213
  }
215
214
 
@@ -231,11 +230,11 @@ export class Service {
231
230
  })
232
231
  }
233
232
  }
234
- reduce_stock(item:string, stock_reduce:number, bNotFoundAssert:boolean=true, passport?:PassportObject) {
233
+ reduce_stock(item:string, stock_reduce:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
235
234
  if (!IsValidName(item)) {
236
235
  ERROR(Errors.IsValidName, 'item')
237
236
  }
238
- if (!IsValidUintLarge(stock_reduce)) {
237
+ if (!IsValidU64(stock_reduce)) {
239
238
  ERROR(Errors.IsValidUint, 'stock_reduce')
240
239
  }
241
240
 
@@ -506,8 +505,8 @@ export class Service {
506
505
  let bValid = true; let names:string[] = [];
507
506
  sales.forEach((v) => {
508
507
  if (!IsValidName(v.item)) bValid = false;
509
- if (!IsValidInt(v.price)) bValid = false;
510
- if (!IsValidUintLarge(v.stock)) bValid = false;
508
+ if (!IsValidU64(v.price)) bValid = false;
509
+ if (!IsValidU64(v.stock)) bValid = false;
511
510
  if (names.includes(v.item)) bValid = false;
512
511
  names.push(v.item)
513
512
  })
@@ -521,7 +520,7 @@ export class Service {
521
520
  ERROR(Errors.InvalidParam, 'add_sales')
522
521
  }
523
522
 
524
- let names: string[] = []; let price: number[] = []; let stock: number[] = []; let endpoint: string[] = [];
523
+ let names: string[] = []; let price: bigint[] = []; let stock: bigint[] = []; let endpoint: string[] = [];
525
524
  sales.forEach((s) => {
526
525
  if (s.endpoint && !IsValidEndpoint(s.endpoint)) {
527
526
  ERROR(Errors.IsValidEndpoint, 'add_sales')
@@ -532,24 +531,26 @@ export class Service {
532
531
  if (passport) {
533
532
  this.txb.moveCall({
534
533
  target:Protocol.Instance().ServiceFn('sales_add_with_passport') as FnCallType,
535
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
536
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, endpoint)), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
537
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_BOOL, bExistAssert)),
534
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', names),
535
+ this.txb.pure.vector('string', endpoint),
536
+ this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
537
+ this.txb.pure.bool(bExistAssert),
538
538
  Protocol.TXB_OBJECT(this.txb, this.permission)],
539
539
  typeArguments:[this.pay_token_type]
540
540
  })
541
541
  } else {
542
542
  this.txb.moveCall({
543
543
  target:Protocol.Instance().ServiceFn('sales_add') as FnCallType,
544
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
545
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, endpoint)),
546
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
547
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_BOOL, bExistAssert)),
544
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', names),
545
+ this.txb.pure.vector('string', endpoint),
546
+ this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
547
+ this.txb.pure.bool(bExistAssert),
548
548
  Protocol.TXB_OBJECT(this.txb, this.permission)],
549
549
  typeArguments:[this.pay_token_type]
550
550
  })
551
551
  }
552
552
  }
553
+
553
554
  remove_sales(sales:string[], passport?:PassportObject) {
554
555
  if (sales.length === 0) return;
555
556
 
@@ -560,14 +561,14 @@ export class Service {
560
561
  if (passport) {
561
562
  this.txb.moveCall({
562
563
  target:Protocol.Instance().ServiceFn('sales_remove_with_passport') as FnCallType,
563
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
564
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', array_unique(sales!)),
564
565
  Protocol.TXB_OBJECT(this.txb, this.permission)],
565
566
  typeArguments:[this.pay_token_type]
566
567
  })
567
568
  } else {
568
569
  this.txb.moveCall({
569
570
  target:Protocol.Instance().ServiceFn('sales_remove') as FnCallType,
570
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
571
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', array_unique(sales!)),
571
572
  Protocol.TXB_OBJECT(this.txb, this.permission)],
572
573
  typeArguments:[this.pay_token_type]
573
574
  })
@@ -582,20 +583,20 @@ export class Service {
582
583
  let bValid = true;
583
584
  discount_dispatch.forEach((v) => {
584
585
  if (!IsValidAddress(v.receiver)) bValid = false;
585
- if (!IsValidUintLarge(v.count) || v.count > Service.MAX_DISCOUNT_COUNT_ONCE) bValid = false;
586
+ if (!IsValidU64(v.count) || v.count > Service.MAX_DISCOUNT_COUNT_ONCE) bValid = false;
586
587
  if (!IsValidName_AllowEmpty(v.discount.name)) bValid = false;
587
588
  if (v.discount.type == Service_Discount_Type.ratio && !IsValidPercent(v.discount.off)) bValid = false;
588
- if (!IsValidUintLarge(v.discount.duration_minutes)) bValid = false;
589
- if (v.discount?.time_start && !IsValidUintLarge(v.discount.time_start)) bValid = false;
590
- if (v.discount?.price_greater && !IsValidInt(v.discount.price_greater)) bValid = false;
589
+ if (!IsValidU64(v.discount.duration_minutes)) bValid = false;
590
+ if (v.discount?.time_start && !IsValidU64(v.discount.time_start)) bValid = false;
591
+ if (v.discount?.price_greater && !IsValidU64(v.discount.price_greater)) bValid = false;
591
592
  })
592
593
  if (!bValid) {
593
594
  ERROR(Errors.InvalidParam, 'discount_dispatch')
594
595
  }
595
596
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
596
597
  discount_dispatch.forEach((discount) => {
597
- let price_greater = this.txb.pure.option('u64', discount.discount?.price_greater);
598
- let time_start = this.txb.pure.option('u64', discount.discount?.time_start);
598
+ let price_greater = this.txb.pure.option('u64', discount.discount?.price_greater ? discount.discount?.price_greater : undefined);
599
+ let time_start = this.txb.pure.option('u64', discount.discount?.time_start ? discount.discount?.time_start : undefined);
599
600
 
600
601
  if (passport) {
601
602
  this.txb.moveCall({
@@ -742,18 +743,18 @@ export class Service {
742
743
  }
743
744
 
744
745
  }
745
- clone(passport?:PassportObject) : ServiceObject {
746
+ clone(new_token_type?:string, passport?:PassportObject) : ServiceObject {
746
747
  if (passport) {
747
748
  return this.txb.moveCall({
748
749
  target:Protocol.Instance().ServiceFn('clone_withpassport') as FnCallType,
749
750
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
750
- typeArguments:[this.pay_token_type]
751
+ typeArguments:[this.pay_token_type, new_token_type ? new_token_type : this.pay_token_type]
751
752
  })
752
753
  } else {
753
754
  return this.txb.moveCall({
754
755
  target:Protocol.Instance().ServiceFn('clone') as FnCallType,
755
756
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
756
- typeArguments:[this.pay_token_type]
757
+ typeArguments:[this.pay_token_type, new_token_type ? new_token_type : this.pay_token_type]
757
758
  })
758
759
  }
759
760
  }
@@ -772,7 +773,7 @@ export class Service {
772
773
  this.txb.moveCall({
773
774
  target:Protocol.Instance().ServiceFn('required_set_with_passport') as FnCallType,
774
775
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
775
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, req)),
776
+ this.txb.pure.vector('string', req),
776
777
  this.txb.pure.string(pubkey), Protocol.TXB_OBJECT(this.txb, this.permission)],
777
778
  typeArguments:[this.pay_token_type]
778
779
  })
@@ -780,7 +781,7 @@ export class Service {
780
781
  this.txb.moveCall({
781
782
  target:Protocol.Instance().ServiceFn('required_set') as FnCallType,
782
783
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
783
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, req)),
784
+ this.txb.pure.vector('string', req),
784
785
  this.txb.pure.string(pubkey), Protocol.TXB_OBJECT(this.txb, this.permission)],
785
786
  typeArguments:[this.pay_token_type]
786
787
  })
@@ -895,7 +896,7 @@ export class Service {
895
896
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order),
896
897
  this.txb.pure.string(customer_info_crypto.pubkey),
897
898
  this.txb.pure.string(customer_info_crypto.customer_pubkey),
898
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_info_crypto.customer_info_crypt)))],
899
+ this.txb.pure.vector('vector<u8>', array_unique(customer_info_crypto.customer_info_crypt))],
899
900
  typeArguments:[this.pay_token_type]
900
901
  })
901
902
 
@@ -910,8 +911,8 @@ export class Service {
910
911
  let bValid = true; let names:string[] = [];
911
912
  buy_items.forEach((v) => {
912
913
  if (!IsValidName(v.item)) bValid = false;
913
- if (!IsValidInt(v.max_price)) bValid = false;
914
- if (!IsValidUintLarge(v.count)) bValid = false;
914
+ if (!IsValidU64(v.max_price)) bValid = false;
915
+ if (!IsValidU64(v.count)) bValid = false;
915
916
  if (names.includes(v.item)) bValid = false;
916
917
  names.push(v.item)
917
918
  })
@@ -919,23 +920,22 @@ export class Service {
919
920
  ERROR(Errors.InvalidParam, 'buy_items 2')
920
921
  }
921
922
 
922
- let name:string[] = []; let price:number[] = []; let stock:number[] = []; let order;
923
+ let name:string[] = []; let price:bigint[] = []; let stock:bigint[] = []; let order;
923
924
  buy_items.forEach((b) => { name.push(b.item); price.push(b.max_price); stock.push(b.count)})
924
925
  const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
925
926
  if (passport) {
926
927
  if (discount) {
927
928
  order = this.txb.moveCall({
928
929
  target:Protocol.Instance().ServiceFn('dicount_buy_with_passport') as FnCallType,
929
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
930
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
930
+ arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
931
+ this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
931
932
  Protocol.TXB_OBJECT(this.txb, coin), Protocol.TXB_OBJECT(this.txb, discount), this.txb.object(clock)],
932
933
  typeArguments:[this.pay_token_type]
933
934
  })} else {
934
935
  order = this.txb.moveCall({
935
936
  target:Protocol.Instance().ServiceFn('buy_with_passport') as FnCallType,
936
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
937
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
938
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
937
+ arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
938
+ this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
939
939
  Protocol.TXB_OBJECT(this.txb, coin)],
940
940
  typeArguments:[this.pay_token_type]
941
941
  })}
@@ -944,8 +944,8 @@ export class Service {
944
944
  order = this.txb.moveCall({
945
945
  target:Protocol.Instance().ServiceFn('disoucnt_buy') as FnCallType,
946
946
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
947
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
948
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
947
+ this.txb.pure.vector('u64', price),
948
+ this.txb.pure.vector('u64', stock),
949
949
  Protocol.TXB_OBJECT(this.txb, coin),
950
950
  Protocol.TXB_OBJECT(this.txb, discount), this.txb.object(clock)],
951
951
  typeArguments:[this.pay_token_type]
@@ -953,8 +953,8 @@ export class Service {
953
953
  order = this.txb.moveCall({
954
954
  target:Protocol.Instance().ServiceFn('buy') as FnCallType,
955
955
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
956
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
957
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
956
+ this.txb.pure.vector('u64', price),
957
+ this.txb.pure.vector('u64', stock),
958
958
  Protocol.TXB_OBJECT(this.txb, coin)],
959
959
  typeArguments:[this.pay_token_type]
960
960
  })}
package/src/utils.ts CHANGED
@@ -173,6 +173,12 @@ export class Bcs {
173
173
  'discord': BCS.STRING,
174
174
  'homepage': BCS.STRING,
175
175
  })
176
+ this.bcs.registerStructType('OptionAddress', {
177
+ 'address': 'Option<address>',
178
+ })
179
+ this.bcs.registerStructType('Guards', {
180
+ 'guards':'vector<OptionAddress>',
181
+ })
176
182
  }
177
183
  static getInstance() : Bcs {
178
184
  if (!Bcs._instance) {
@@ -254,7 +260,6 @@ export class Bcs {
254
260
  case ValueType.TYPE_U64:
255
261
  return this.bcs.de(BCS.U64, data);
256
262
  case ValueType.TYPE_U8:
257
- console.log(data)
258
263
  return this.bcs.de(BCS.U8, data);
259
264
  case ValueType.TYPE_VEC_U8:
260
265
  return this.bcs.de('vector<u8>', data);
@@ -297,7 +302,8 @@ export class Bcs {
297
302
  }
298
303
  }
299
304
 
300
- de_ent(data:Uint8Array) : any {
305
+ de_ent(data:Uint8Array | undefined) : any {
306
+ if (!data || data.length < 2) return ''
301
307
  const struct_vec = this.bcs.de('vector<u8>', data);
302
308
  return this.bcs.de('EntStruct', Uint8Array.from(struct_vec));
303
309
  /* const reader = new BcsReader(data);
@@ -314,12 +320,21 @@ export class Bcs {
314
320
  const dislike = reader.read32();
315
321
  return {avatar:avatar, resource:resource, like:like, dislike:dislike}*/
316
322
  }
317
- de_entInfo(data:Uint8Array) : any {
323
+ de_entInfo(data:Uint8Array | undefined) : any {
324
+ if (!data || data.length === 0) return ''
318
325
  let r = this.bcs.de('PersonalInfo', data);
319
326
  r.name = new TextDecoder().decode(Uint8Array.from(r.name));
320
327
  r.description = new TextDecoder().decode(Uint8Array.from(r.description));
321
328
  return r
322
329
  }
330
+ de_guards(data:Uint8Array | undefined) : any {
331
+ if (!data || data.length < 1) return ''
332
+ let r = this.bcs.de('Guards', data);
333
+ return r?.guards?.map((v:any) => {
334
+ if (v?.address?.none) return undefined;
335
+ return v?.address?.some;
336
+ })
337
+ }
323
338
  }
324
339
 
325
340
  export function stringToUint8Array(str:string) : Uint8Array {
@@ -380,28 +395,31 @@ export const IsValidAddress = (addr:string | undefined) : boolean => {
380
395
  }
381
396
  return true
382
397
  }
383
- export const IsValidBigint = (value:string | number | undefined, max:bigint=MAX_U256) : boolean => {
398
+ export const IsValidBigint = (value:string | number | undefined | bigint, max:bigint=MAX_U256, min?:bigint) : boolean => {
384
399
  if (value === '' || value === undefined) return false;
385
400
  try {
386
401
  const v = BigInt(value);
387
402
  if (v <= max) {
403
+ if (min !== undefined) {
404
+ return v >= min;
405
+ }
388
406
  return true
389
407
  }
390
408
  } catch (e) {
391
409
  }; return false
392
410
  }
393
411
 
394
- export const IsValidUintLarge = (value:string | number | undefined) : boolean => {
395
- return IsValidBigint(value)
412
+ export const IsValidUintLarge = (value:string | number | undefined | bigint) : boolean => {
413
+ return IsValidBigint(value, MAX_U64, BigInt(0))
396
414
  }
397
- export const IsValidU8 = (value:string | number | undefined) : boolean => {
398
- return IsValidBigint(value, MAX_U8)
415
+ export const IsValidU8 = (value:string | number | undefined | bigint) : boolean => {
416
+ return IsValidBigint(value, MAX_U8, BigInt(0))
399
417
  }
400
- export const IsValidU64 = (value:string | number | undefined) : boolean => {
401
- return IsValidBigint(value, MAX_U64)
418
+ export const IsValidU64 = (value:string | number | undefined | bigint) : boolean => {
419
+ return IsValidBigint(value, MAX_U64, BigInt(0))
402
420
  }
403
- export const IsValidU128 = (value:string | number | undefined) : boolean => {
404
- return IsValidBigint(value, MAX_U128)
421
+ export const IsValidU128 = (value:string | number | undefined | bigint) : boolean => {
422
+ return IsValidBigint(value, MAX_U128, BigInt(0))
405
423
  }
406
424
 
407
425
  export const IsValidTokenType = (argType: string) : boolean => {
@@ -433,14 +451,12 @@ export const IsValidInt = (value: number | string) : boolean => {
433
451
  }
434
452
  return Number.isSafeInteger(value)
435
453
  }
436
- export const IsValidPercent = (value: number | string) : boolean => {
437
- if (typeof(value) === 'string') {
438
- value = parseInt(value as string);
439
- }
440
- return Number.isSafeInteger(value) && value > 0 && value <= 100
454
+ export const IsValidPercent = (value: number | string | bigint) : boolean => {
455
+ return IsValidBigint(value, BigInt(100), BigInt(0))
441
456
  }
442
- export const IsValidArray = (arr: any[], validFunc:any) : boolean => {
443
- for (let i = 0; i < arr.length; ++i) {
457
+
458
+ export const IsValidArray = (arr: any, validFunc:any) : boolean => {
459
+ for (let i = 0; i < arr.length; i++) {
444
460
  if (!validFunc(arr[i])) {
445
461
  return false
446
462
  }
@@ -473,8 +489,6 @@ export const ResolveBalance = (balance:string, decimals:number) : string => {
473
489
  }
474
490
  }
475
491
 
476
- //export const OptionNone = (txb:TransactionBlock) : TransactionArgument => { return txb.pure.option([], BCS.U8) };
477
-
478
492
  export type ArgType = {
479
493
  isCoin: boolean;
480
494
  coin: string;
package/src/vote.ts CHANGED
@@ -229,7 +229,7 @@ export class Vote {
229
229
  this.txb.moveCall({
230
230
  target:Protocol.Instance().VoteFn('agrees_remove_with_passport') as FnCallType,
231
231
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
232
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
232
+ this.txb.pure.vector('string', array_unique(options)),
233
233
  Protocol.TXB_OBJECT(this.txb, this.permission)]
234
234
  })
235
235
  }
@@ -243,7 +243,7 @@ export class Vote {
243
243
  this.txb.moveCall({
244
244
  target:Protocol.Instance().VoteFn('agrees_remove') as FnCallType,
245
245
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
246
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
246
+ this.txb.pure.vector('string', array_unique(options)),
247
247
  Protocol.TXB_OBJECT(this.txb, this.permission)]
248
248
  })
249
249
  }
@@ -341,13 +341,13 @@ export class Vote {
341
341
  this.txb.moveCall({
342
342
  target:Protocol.Instance().VoteFn('with_passport') as FnCallType,
343
343
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
344
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
344
+ this.txb.pure.vector('string', array_unique(options))]
345
345
  })
346
346
  } else {
347
347
  this.txb.moveCall({
348
348
  target:Protocol.Instance().VoteFn('this.object') as FnCallType,
349
349
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
350
- this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
350
+ this.txb.pure.vector('string', array_unique(options))]
351
351
  })
352
352
  }
353
353
  }
package/src/wowok.ts CHANGED
@@ -1,4 +1,3 @@
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';