wowok 1.2.7 → 1.2.9
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/package.json +1 -1
- package/src/demand.ts +5 -5
- package/src/entity.ts +8 -0
- package/src/guard.ts +217 -144
- package/src/machine.ts +205 -53
- package/src/passport.ts +8 -8
- package/src/permission.ts +91 -119
- package/src/progress.ts +101 -43
- package/src/protocol.ts +46 -55
- package/src/repository.ts +107 -20
- package/src/resource.ts +19 -9
- package/src/reward.ts +9 -11
- package/src/service.ts +35 -33
- package/src/utils.ts +88 -43
- package/src/vote.ts +18 -21
- package/src/wowok.ts +2 -2
package/src/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
|
|
2
2
|
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
|
|
3
|
-
IsValidAddress, IsValidEndpoint, OptionNone,
|
|
3
|
+
IsValidAddress, IsValidEndpoint, OptionNone, IsValidUintLarge, IsValidInt, IsValidName, } from './utils'
|
|
4
4
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
|
|
5
5
|
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
|
|
6
6
|
TxbObject} from './protocol';
|
|
@@ -113,7 +113,7 @@ export class Service {
|
|
|
113
113
|
} else {
|
|
114
114
|
s.object = txb.moveCall({
|
|
115
115
|
target:protocol.ServiceFn('new') as FnCallType,
|
|
116
|
-
arguments:[txb.pure(description
|
|
116
|
+
arguments:[txb.pure(description), txb.pure(payee_address, BCS.ADDRESS), ep, Protocol.TXB_OBJECT(txb, permission)],
|
|
117
117
|
typeArguments:[pay_token_type],
|
|
118
118
|
})
|
|
119
119
|
}
|
|
@@ -211,7 +211,7 @@ export class Service {
|
|
|
211
211
|
if (!IsValidName(item)) {
|
|
212
212
|
ERROR(Errors.IsValidName, 'item')
|
|
213
213
|
}
|
|
214
|
-
if (!
|
|
214
|
+
if (!IsValidUintLarge(stock_add)) {
|
|
215
215
|
ERROR(Errors.IsValidUint, 'stock_add')
|
|
216
216
|
}
|
|
217
217
|
|
|
@@ -236,7 +236,7 @@ export class Service {
|
|
|
236
236
|
if (!IsValidName(item)) {
|
|
237
237
|
ERROR(Errors.IsValidName, 'item')
|
|
238
238
|
}
|
|
239
|
-
if (!
|
|
239
|
+
if (!IsValidUintLarge(stock_reduce)) {
|
|
240
240
|
ERROR(Errors.IsValidUint, 'stock_reduce')
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -323,11 +323,10 @@ export class Service {
|
|
|
323
323
|
})
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
|
-
repository_remove(repository_address
|
|
327
|
-
if (!removeall &&
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (repository_address && !IsValidArray(repository_address, IsValidAddress)) {
|
|
326
|
+
repository_remove(repository_address:string[], removeall?:boolean, passport?:PassportObject) {
|
|
327
|
+
if (!removeall && repository_address.length===0) return;
|
|
328
|
+
|
|
329
|
+
if (!IsValidArray(repository_address, IsValidAddress)) {
|
|
331
330
|
ERROR(Errors.IsValidArray, 'repository_address');
|
|
332
331
|
}
|
|
333
332
|
|
|
@@ -366,6 +365,8 @@ export class Service {
|
|
|
366
365
|
}
|
|
367
366
|
|
|
368
367
|
add_withdraw_guards(guards:Service_Guard_Percent[], passport?:PassportObject) {
|
|
368
|
+
if (guards.length === 0) return;
|
|
369
|
+
|
|
369
370
|
let bValid = true;
|
|
370
371
|
guards.forEach((v) => {
|
|
371
372
|
if (!Protocol.IsValidObjects([v.guard])) bValid = false;
|
|
@@ -394,12 +395,12 @@ export class Service {
|
|
|
394
395
|
}
|
|
395
396
|
})
|
|
396
397
|
}
|
|
397
|
-
remove_withdraw_guards(guard_address
|
|
398
|
-
if (!removeall &&
|
|
399
|
-
|
|
398
|
+
remove_withdraw_guards(guard_address:string[], removeall?:boolean, passport?:PassportObject) {
|
|
399
|
+
if (!removeall && guard_address.length===0) {
|
|
400
|
+
return
|
|
400
401
|
}
|
|
401
402
|
|
|
402
|
-
if (
|
|
403
|
+
if (!IsValidArray(guard_address, IsValidAddress)) {
|
|
403
404
|
ERROR(Errors.IsValidArray, 'guard_address')
|
|
404
405
|
}
|
|
405
406
|
|
|
@@ -437,6 +438,8 @@ export class Service {
|
|
|
437
438
|
}
|
|
438
439
|
}
|
|
439
440
|
add_refund_guards(guards:Service_Guard_Percent[], passport?:PassportObject) {
|
|
441
|
+
if (guards.length === 0) return;
|
|
442
|
+
|
|
440
443
|
let bValid = true;
|
|
441
444
|
guards.forEach((v) => {
|
|
442
445
|
if (!Protocol.IsValidObjects([v.guard])) bValid = false;
|
|
@@ -465,11 +468,9 @@ export class Service {
|
|
|
465
468
|
}
|
|
466
469
|
})
|
|
467
470
|
}
|
|
468
|
-
remove_refund_guards(guard_address
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
if (guard_address && !IsValidArray(guard_address, IsValidAddress)) {
|
|
471
|
+
remove_refund_guards(guard_address:string[], removeall?:boolean, passport?:PassportObject) {
|
|
472
|
+
if (guard_address.length===0 && !removeall) return ;
|
|
473
|
+
if (!IsValidArray(guard_address, IsValidAddress)) {
|
|
473
474
|
ERROR(Errors.InvalidParam, 'guard_address')
|
|
474
475
|
}
|
|
475
476
|
|
|
@@ -512,22 +513,24 @@ export class Service {
|
|
|
512
513
|
sales.forEach((v) => {
|
|
513
514
|
if (!IsValidName(v.item)) bValid = false;
|
|
514
515
|
if (!IsValidInt(v.price)) bValid = false;
|
|
515
|
-
if (!
|
|
516
|
+
if (!IsValidUintLarge(v.stock)) bValid = false;
|
|
516
517
|
if (names.includes(v.item)) bValid = false;
|
|
517
518
|
names.push(v.item)
|
|
518
519
|
})
|
|
519
520
|
return bValid
|
|
520
521
|
}
|
|
521
522
|
|
|
522
|
-
|
|
523
|
-
if (
|
|
524
|
-
|
|
523
|
+
add_sales(sales:Service_Sale[], bExistAssert:boolean=false, passport?:PassportObject) {
|
|
524
|
+
if (sales.length === 0) return;
|
|
525
|
+
|
|
526
|
+
if (!this.is_valid_sale(sales)) {
|
|
527
|
+
ERROR(Errors.InvalidParam, 'add_sales')
|
|
525
528
|
}
|
|
526
529
|
|
|
527
530
|
let names: string[] = []; let price: number[] = []; let stock: number[] = []; let endpoint: string[] = [];
|
|
528
531
|
sales.forEach((s) => {
|
|
529
532
|
if (s.endpoint && !IsValidEndpoint(s.endpoint)) {
|
|
530
|
-
ERROR(Errors.IsValidEndpoint, '
|
|
533
|
+
ERROR(Errors.IsValidEndpoint, 'add_sales')
|
|
531
534
|
}
|
|
532
535
|
names.push(s.item); price.push(s.price); stock.push(s.stock); endpoint.push(s.endpoint ?? '')
|
|
533
536
|
})
|
|
@@ -554,12 +557,11 @@ export class Service {
|
|
|
554
557
|
})
|
|
555
558
|
}
|
|
556
559
|
}
|
|
557
|
-
remove_sales(sales
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
ERROR(Errors.IsValidArray, 'sales')
|
|
560
|
+
remove_sales(sales:string[], passport?:PassportObject) {
|
|
561
|
+
if (sales.length === 0) return;
|
|
562
|
+
|
|
563
|
+
if (!IsValidArray(sales, IsValidName)) {
|
|
564
|
+
ERROR(Errors.IsValidArray, 'remove_sales')
|
|
563
565
|
}
|
|
564
566
|
|
|
565
567
|
let txb = this.protocol.CurrentSession();
|
|
@@ -588,11 +590,11 @@ export class Service {
|
|
|
588
590
|
let bValid = true;
|
|
589
591
|
discount_dispatch.forEach((v) => {
|
|
590
592
|
if (!IsValidAddress(v.receiver)) bValid = false;
|
|
591
|
-
if (!
|
|
593
|
+
if (!IsValidUintLarge(v.count) || v.count > Service.MAX_DISCOUNT_COUNT_ONCE) bValid = false;
|
|
592
594
|
if (!IsValidName_AllowEmpty(v.discount.name)) bValid = false;
|
|
593
595
|
if (v.discount.type == Service_Discount_Type.ratio && !IsValidPercent(v.discount.off)) bValid = false;
|
|
594
|
-
if (!
|
|
595
|
-
if (v.discount?.time_start && !
|
|
596
|
+
if (!IsValidUintLarge(v.discount.duration_minutes)) bValid = false;
|
|
597
|
+
if (v.discount?.time_start && !IsValidUintLarge(v.discount.time_start)) bValid = false;
|
|
596
598
|
if (v.discount?.price_greater && !IsValidInt(v.discount.price_greater)) bValid = false;
|
|
597
599
|
})
|
|
598
600
|
if (!bValid) {
|
|
@@ -932,7 +934,7 @@ export class Service {
|
|
|
932
934
|
buy_items.forEach((v) => {
|
|
933
935
|
if (!IsValidName(v.item)) bValid = false;
|
|
934
936
|
if (!IsValidInt(v.max_price)) bValid = false;
|
|
935
|
-
if (!
|
|
937
|
+
if (!IsValidUintLarge(v.count)) bValid = false;
|
|
936
938
|
if (names.includes(v.item)) bValid = false;
|
|
937
939
|
names.push(v.item)
|
|
938
940
|
})
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, BcsReader } from '@mysten/bcs';
|
|
2
2
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
3
|
+
import { SuiObjectResponse, DynamicFieldPage } from '@mysten/sui.js/client';
|
|
3
4
|
import { ERROR, Errors } from './exception';
|
|
4
5
|
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui.js/utils'
|
|
5
|
-
import { RepositoryValueType, ValueType } from './protocol'
|
|
6
|
+
import { RepositoryValueType, ValueType, Protocol } from './protocol'
|
|
6
7
|
|
|
7
|
-
export const MAX_U8 = BigInt('
|
|
8
|
+
export const MAX_U8 = BigInt('255');
|
|
8
9
|
export const MAX_U64 = BigInt('18446744073709551615');
|
|
9
10
|
export const MAX_U128 = BigInt('340282366920938463463374607431768211455');
|
|
10
11
|
export const MAX_U256 = BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639935');
|
|
@@ -30,36 +31,7 @@ export const ValueTypeConvert = (type:ValueType | null | undefined) : Repository
|
|
|
30
31
|
return -1;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export const
|
|
34
|
-
if (dataType === RepositoryValueType.String) {
|
|
35
|
-
return {type: ValueType.TYPE_STRING, data: Bcs.getInstance().ser(ValueType.TYPE_VEC_U8, new TextEncoder().encode(data.toString()))}
|
|
36
|
-
} else if (dataType === RepositoryValueType.PositiveNumber) {
|
|
37
|
-
try {
|
|
38
|
-
const value = BigInt(data.toString());
|
|
39
|
-
var t = ValueType.TYPE_U8;
|
|
40
|
-
if (value <= MAX_U8) {
|
|
41
|
-
} else if (value <= MAX_U64) {
|
|
42
|
-
t = ValueType.TYPE_U64;
|
|
43
|
-
} else if (value <= MAX_U128) {
|
|
44
|
-
t = ValueType.TYPE_U128;
|
|
45
|
-
} else if (value <= MAX_U256) {
|
|
46
|
-
t = ValueType.TYPE_U256;
|
|
47
|
-
} else {
|
|
48
|
-
return undefined
|
|
49
|
-
}
|
|
50
|
-
} catch (e) {
|
|
51
|
-
console.log(e)
|
|
52
|
-
return undefined
|
|
53
|
-
}
|
|
54
|
-
return {type:t, data:Bcs.getInstance().ser(t, data)}
|
|
55
|
-
} else if (dataType === RepositoryValueType.Address) {
|
|
56
|
-
return {type:ValueType.TYPE_ADDRESS, data:Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, data)}
|
|
57
|
-
}
|
|
58
|
-
//@ todo vector....
|
|
59
|
-
return undefined
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const readOption = (arr: number[], de:ValueType) : {bNone:boolean, value:any}=> {
|
|
34
|
+
export const readOption = (arr: number[], de:ValueType) : {bNone:boolean, value:any} => {
|
|
63
35
|
let o = arr.splice(0, 1);
|
|
64
36
|
if (o[0] == 1) { // true
|
|
65
37
|
return {bNone:false, value:Bcs.getInstance().de(de, Uint8Array.from(arr))};
|
|
@@ -209,7 +181,15 @@ export class Bcs {
|
|
|
209
181
|
return Bcs._instance;
|
|
210
182
|
}
|
|
211
183
|
|
|
212
|
-
|
|
184
|
+
ser_option_u32(data:Uint8Array | any) : Uint8Array {
|
|
185
|
+
return this.bcs.ser('Option<u32>', {'some': data}).toBytes();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
ser(type:ValueType | string, data:Uint8Array | any) : Uint8Array {
|
|
189
|
+
if (typeof(type) === 'string') {
|
|
190
|
+
return this.bcs.ser(type, data).toBytes();
|
|
191
|
+
}
|
|
192
|
+
|
|
213
193
|
switch(type) {
|
|
214
194
|
case ValueType.TYPE_BOOL:
|
|
215
195
|
return this.bcs.ser(BCS.BOOL, data).toBytes();
|
|
@@ -375,7 +355,6 @@ export const deepClone = <T>(origin: T, target?: Record<string, any> | T ): T =>
|
|
|
375
355
|
} else {
|
|
376
356
|
tar[key] = origin[key]
|
|
377
357
|
}
|
|
378
|
-
|
|
379
358
|
}
|
|
380
359
|
}
|
|
381
360
|
|
|
@@ -391,12 +370,36 @@ export const IsValidDesription = (description:string) : boolean => { return desc
|
|
|
391
370
|
export const IsValidName = (name:string) : boolean => { if(!name) return false; return name.length <= MAX_NAME_LENGTH && name.length != 0 }
|
|
392
371
|
export const IsValidName_AllowEmpty = (name:string) : boolean => { return name.length <= MAX_NAME_LENGTH }
|
|
393
372
|
export const IsValidEndpoint = (endpoint:string) : boolean => { if (!endpoint) return false; return endpoint.length <= MAX_ENDPOINT_LENGTH }
|
|
394
|
-
export const IsValidAddress = (addr:string) : boolean => {
|
|
373
|
+
export const IsValidAddress = (addr:string | undefined) : boolean => {
|
|
395
374
|
if (!addr || !isValidSuiAddress(addr)) {
|
|
396
375
|
return false;
|
|
397
376
|
}
|
|
398
377
|
return true
|
|
399
378
|
}
|
|
379
|
+
export const IsValidBigint = (value:string | number | undefined, max:bigint=MAX_U256) : boolean => {
|
|
380
|
+
if (value === '' || value === undefined) return false;
|
|
381
|
+
try {
|
|
382
|
+
const v = BigInt(value);
|
|
383
|
+
if (v <= max) {
|
|
384
|
+
return true
|
|
385
|
+
}
|
|
386
|
+
} catch (e) {
|
|
387
|
+
}; return false
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export const IsValidUintLarge = (value:string | number | undefined) : boolean => {
|
|
391
|
+
return IsValidBigint(value)
|
|
392
|
+
}
|
|
393
|
+
export const IsValidU8 = (value:string | number | undefined) : boolean => {
|
|
394
|
+
return IsValidBigint(value, MAX_U8)
|
|
395
|
+
}
|
|
396
|
+
export const IsValidU64 = (value:string | number | undefined) : boolean => {
|
|
397
|
+
return IsValidBigint(value, MAX_U64)
|
|
398
|
+
}
|
|
399
|
+
export const IsValidU128 = (value:string | number | undefined) : boolean => {
|
|
400
|
+
return IsValidBigint(value, MAX_U128)
|
|
401
|
+
}
|
|
402
|
+
|
|
400
403
|
export const IsValidTokenType = (argType: string) : boolean => {
|
|
401
404
|
if (!argType || argType.length === 0) {
|
|
402
405
|
return false;
|
|
@@ -420,12 +423,6 @@ export const IsValidArgType = (argType: string) : boolean => {
|
|
|
420
423
|
}
|
|
421
424
|
return true;
|
|
422
425
|
}
|
|
423
|
-
export const IsValidUint = (value: number | string) : boolean => {
|
|
424
|
-
if (typeof(value) === 'string') {
|
|
425
|
-
value = parseInt(value as string);
|
|
426
|
-
}
|
|
427
|
-
return Number.isSafeInteger(value) && value > 0
|
|
428
|
-
}
|
|
429
426
|
export const IsValidInt = (value: number | string) : boolean => {
|
|
430
427
|
if (typeof(value) === 'string') {
|
|
431
428
|
value = parseInt(value as string);
|
|
@@ -468,7 +465,7 @@ export const ResolveBalance = (balance:string, decimals:number) : string => {
|
|
|
468
465
|
let end = balance.slice(Math.abs(pos));
|
|
469
466
|
return start + '.' + end;
|
|
470
467
|
} else {
|
|
471
|
-
return '.' + balance.padStart(
|
|
468
|
+
return '.' + balance.padStart(decimals, '0');
|
|
472
469
|
}
|
|
473
470
|
}
|
|
474
471
|
|
|
@@ -525,4 +522,52 @@ export function isValidHttpUrl(url:string) : boolean {
|
|
|
525
522
|
}
|
|
526
523
|
|
|
527
524
|
return r.protocol === "http:" || r.protocol === "https:" || r.protocol === 'ipfs:';
|
|
528
|
-
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export interface query_object_param {
|
|
528
|
+
id:string;
|
|
529
|
+
onBegin?:(id:string)=>void;
|
|
530
|
+
onObjectRes?:(id:string, res:SuiObjectResponse)=>void;
|
|
531
|
+
onDynamicRes?:(id:string, res:DynamicFieldPage)=>void;
|
|
532
|
+
onFieldsRes?:(id:string, fields_res:SuiObjectResponse[])=>void;
|
|
533
|
+
onObjectErr?:(id:string, err:any)=>void;
|
|
534
|
+
onDynamicErr?:(id:string, err:any)=>void;
|
|
535
|
+
onFieldsErr?:(id:string, err:any)=>void;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export const query_object = (param:query_object_param) => {
|
|
539
|
+
if (param.id) {
|
|
540
|
+
if(param?.onBegin) param.onBegin(param.id);
|
|
541
|
+
Protocol.Client().getObject({id:param.id, options:{showContent:true, showType:true}}).then((res) => {
|
|
542
|
+
if (res.error) {
|
|
543
|
+
if(param?.onObjectErr) param.onObjectErr(param.id, res.error);
|
|
544
|
+
} else {
|
|
545
|
+
if(param?.onObjectRes) param.onObjectRes(param.id, res);
|
|
546
|
+
}
|
|
547
|
+
}).catch((err) => {
|
|
548
|
+
console.log(err)
|
|
549
|
+
if (param?.onObjectErr) param.onObjectErr(param.id, err);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
Protocol.Client().getDynamicFields({parentId:param.id}).then((res) => {
|
|
553
|
+
if (param?.onDynamicRes) param.onDynamicRes(param.id, res);
|
|
554
|
+
|
|
555
|
+
if (res.data.length > 0) {
|
|
556
|
+
Protocol.Client().multiGetObjects({ids:res.data.map(v => v.objectId), options:{showContent:true}}).then((fields) => {
|
|
557
|
+
if (param?.onFieldsRes) param.onFieldsRes(param.id, fields);
|
|
558
|
+
}).catch((err) => {
|
|
559
|
+
console.log(err)
|
|
560
|
+
if (param?.onFieldsErr) param.onFieldsErr(param.id, err);
|
|
561
|
+
})
|
|
562
|
+
}
|
|
563
|
+
}).catch((err) => {
|
|
564
|
+
console.log(err)
|
|
565
|
+
if (param?.onDynamicErr) param.onDynamicErr(param.id, err);
|
|
566
|
+
})
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export const FirstLetterUppercase = (str:string) => {
|
|
571
|
+
if (!str) return str;
|
|
572
|
+
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
573
|
+
}
|
package/src/vote.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { FnCallType, PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject} from './protocol';
|
|
3
|
-
import { IsValidDesription,
|
|
3
|
+
import { IsValidDesription, IsValidUintLarge, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
5
|
import { ValueType } from './protocol';
|
|
6
6
|
|
|
@@ -36,10 +36,10 @@ export class Vote {
|
|
|
36
36
|
if (!IsValidDesription(description)) {
|
|
37
37
|
ERROR(Errors.IsValidDesription)
|
|
38
38
|
}
|
|
39
|
-
if (!
|
|
39
|
+
if (!IsValidUintLarge(time)) {
|
|
40
40
|
ERROR(Errors.IsValidUint, 'time')
|
|
41
41
|
}
|
|
42
|
-
if (max_choice_count && !
|
|
42
|
+
if (max_choice_count && !IsValidUintLarge(max_choice_count)) {
|
|
43
43
|
ERROR(Errors.IsValidUint, 'max_choice_count')
|
|
44
44
|
}
|
|
45
45
|
if (max_choice_count && max_choice_count > MAX_CHOICE_COUNT) {
|
|
@@ -128,10 +128,10 @@ export class Vote {
|
|
|
128
128
|
}
|
|
129
129
|
add_guard(guard:GuardObject, weight:number, passport?:PassportObject) {
|
|
130
130
|
if (!Protocol.IsValidObjects([guard])) {
|
|
131
|
-
ERROR(Errors.IsValidObjects, '
|
|
131
|
+
ERROR(Errors.IsValidObjects, 'add_guard')
|
|
132
132
|
}
|
|
133
|
-
if (!
|
|
134
|
-
ERROR(Errors.IsValidUint, '
|
|
133
|
+
if (!IsValidUintLarge(weight)) {
|
|
134
|
+
ERROR(Errors.IsValidUint, 'add_guard')
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
let txb = this.protocol.CurrentSession();
|
|
@@ -151,12 +151,10 @@ export class Vote {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
remove_guard(guard_address:string[], removeall?:boolean, passport?:PassportObject) {
|
|
154
|
-
if (!removeall &&
|
|
155
|
-
ERROR(Errors.AllInvalid, 'guard_address & removeall')
|
|
156
|
-
}
|
|
154
|
+
if (!removeall && guard_address.length===0) return;
|
|
157
155
|
|
|
158
|
-
if (
|
|
159
|
-
ERROR(Errors.IsValidArray, '
|
|
156
|
+
if (!IsValidArray(guard_address, IsValidAddress)) {
|
|
157
|
+
ERROR(Errors.IsValidArray, 'remove_guard')
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
let txb = this.protocol.CurrentSession();
|
|
@@ -191,9 +189,7 @@ export class Vote {
|
|
|
191
189
|
}
|
|
192
190
|
|
|
193
191
|
add_option(options:VoteOption[], passport?:PassportObject) {
|
|
194
|
-
if (
|
|
195
|
-
ERROR(Errors.InvalidParam, 'options')
|
|
196
|
-
}
|
|
192
|
+
if (options.length === 0) return ;
|
|
197
193
|
|
|
198
194
|
let bValid = true;
|
|
199
195
|
options.forEach((v) => {
|
|
@@ -226,11 +222,11 @@ export class Vote {
|
|
|
226
222
|
})
|
|
227
223
|
}
|
|
228
224
|
remove_option(options:string[], removeall?:boolean, passport?:PassportObject) {
|
|
229
|
-
if (!removeall &&
|
|
230
|
-
|
|
225
|
+
if (!removeall && options.length===0) {
|
|
226
|
+
return
|
|
231
227
|
}
|
|
232
228
|
if (options && !IsValidArray(options, IsValidAddress)) {
|
|
233
|
-
ERROR(Errors.IsValidArray, '
|
|
229
|
+
ERROR(Errors.IsValidArray, 'remove_option')
|
|
234
230
|
}
|
|
235
231
|
|
|
236
232
|
let txb = this.protocol.CurrentSession();
|
|
@@ -265,7 +261,7 @@ export class Vote {
|
|
|
265
261
|
}
|
|
266
262
|
}
|
|
267
263
|
set_max_choice_count(max_choice_count:number, passport?:PassportObject) {
|
|
268
|
-
if (!
|
|
264
|
+
if (!IsValidUintLarge(max_choice_count) || max_choice_count > MAX_CHOICE_COUNT) {
|
|
269
265
|
ERROR(Errors.InvalidParam, 'max_choice_count')
|
|
270
266
|
}
|
|
271
267
|
|
|
@@ -315,7 +311,7 @@ export class Vote {
|
|
|
315
311
|
}
|
|
316
312
|
|
|
317
313
|
expand_deadline(ms_expand:boolean, time:number, passport?:PassportObject) {
|
|
318
|
-
if (!
|
|
314
|
+
if (!IsValidUintLarge(time)) {
|
|
319
315
|
ERROR(Errors.IsValidUint, 'time')
|
|
320
316
|
}
|
|
321
317
|
|
|
@@ -351,8 +347,9 @@ export class Vote {
|
|
|
351
347
|
}
|
|
352
348
|
|
|
353
349
|
agree(options:string[], passport?:PassportObject) {
|
|
354
|
-
if (
|
|
355
|
-
|
|
350
|
+
if (options.length === 0) return;
|
|
351
|
+
if (options.length > MAX_CHOICE_COUNT) {
|
|
352
|
+
ERROR(Errors.InvalidParam, 'agree')
|
|
356
353
|
}
|
|
357
354
|
|
|
358
355
|
let txb = this.protocol.CurrentSession();
|
package/src/wowok.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class Wowok {
|
|
|
28
28
|
let txb = this.protocol.CurrentSession();
|
|
29
29
|
txb.moveCall({
|
|
30
30
|
target:this.protocol.WowokFn('grantor_register') as FnCallType,
|
|
31
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
31
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.object(Protocol.CLOCK_OBJECT),
|
|
32
32
|
Protocol.TXB_OBJECT(txb, grantee_permission)]
|
|
33
33
|
})
|
|
34
34
|
}
|
|
@@ -49,7 +49,7 @@ export class Wowok {
|
|
|
49
49
|
let txb = this.protocol.CurrentSession();
|
|
50
50
|
txb.moveCall({
|
|
51
51
|
target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
|
|
52
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_name
|
|
52
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_name)]
|
|
53
53
|
})
|
|
54
54
|
}
|
|
55
55
|
}
|