wowok 1.2.2 → 1.2.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/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +26 -25
- package/dist/machine.js +7 -6
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +30 -28
- package/dist/permission.js +2 -1
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +3 -12
- package/dist/protocol.d.ts +11 -3
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +36 -6
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +5 -15
- package/dist/service.d.ts +4 -4
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +29 -39
- package/dist/utils.d.ts +9 -21
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +116 -54
- package/dist/vote.js +8 -7
- package/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/guard.ts +26 -25
- package/src/machine.ts +7 -7
- package/src/passport.ts +30 -27
- package/src/permission.ts +2 -2
- package/src/progress.ts +4 -12
- package/src/protocol.ts +37 -9
- package/src/repository.ts +5 -14
- package/src/service.ts +30 -39
- package/src/utils.ts +118 -58
- package/src/vote.ts +8 -8
package/src/repository.ts
CHANGED
|
@@ -82,16 +82,7 @@ export class Repository {
|
|
|
82
82
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
87
|
-
if (!Protocol.IsValidObjects([this.object])) return false;
|
|
88
|
-
let txb = this.protocol.CurrentSession();
|
|
89
|
-
txb.moveCall({
|
|
90
|
-
target:this.protocol.RepositoryFn(like) as FnCallType,
|
|
91
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
*/
|
|
85
|
+
|
|
95
86
|
add_data(data:Repository_Policy_Data) {
|
|
96
87
|
if (!Repository.IsValidName(data.key)) {
|
|
97
88
|
ERROR(Errors.IsValidName)
|
|
@@ -235,7 +226,7 @@ export class Repository {
|
|
|
235
226
|
|
|
236
227
|
let txb = this.protocol.CurrentSession();
|
|
237
228
|
policies.forEach((policy) => {
|
|
238
|
-
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().
|
|
229
|
+
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, policy.permission)) : OptionNone(txb);
|
|
239
230
|
if (passport) {
|
|
240
231
|
txb.moveCall({
|
|
241
232
|
target:this.protocol.RepositoryFn('policy_add_with_passport') as FnCallType,
|
|
@@ -277,7 +268,7 @@ export class Repository {
|
|
|
277
268
|
txb.moveCall({
|
|
278
269
|
target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
279
270
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
280
|
-
txb.pure(Bcs.getInstance().
|
|
271
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
281
272
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
282
273
|
})
|
|
283
274
|
}
|
|
@@ -291,7 +282,7 @@ export class Repository {
|
|
|
291
282
|
txb.moveCall({
|
|
292
283
|
target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
|
|
293
284
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
294
|
-
txb.pure(Bcs.getInstance().
|
|
285
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
295
286
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
296
287
|
})
|
|
297
288
|
}
|
|
@@ -371,7 +362,7 @@ export class Repository {
|
|
|
371
362
|
if(!Permission.IsValidPermissionIndex(permission_index)) {
|
|
372
363
|
ERROR(Errors.IsValidPermissionIndex)
|
|
373
364
|
}
|
|
374
|
-
index = txb.pure(Bcs.getInstance().
|
|
365
|
+
index = txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, permission_index));
|
|
375
366
|
}
|
|
376
367
|
|
|
377
368
|
if (passport) {
|
package/src/service.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
|
|
|
2
2
|
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidArgType, IsValidDesription,
|
|
3
3
|
IsValidAddress, IsValidEndpoint, OptionNone, IsValidUint, IsValidInt, IsValidName, } from './utils'
|
|
4
4
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
|
|
5
|
-
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol,
|
|
5
|
+
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
|
|
6
6
|
TxbObject} from './protocol';
|
|
7
7
|
import { ERROR, Errors } from './exception';
|
|
8
8
|
import { Resource } from './resource';
|
|
@@ -39,10 +39,10 @@ export type Customer_RequiredInfo = {
|
|
|
39
39
|
customer_info_crypt: string[];
|
|
40
40
|
}
|
|
41
41
|
export enum BuyRequiredEnum {
|
|
42
|
-
address = '
|
|
43
|
-
phone = '
|
|
44
|
-
name = '
|
|
45
|
-
postcode = '
|
|
42
|
+
address = 'Address',
|
|
43
|
+
phone = 'Phone',
|
|
44
|
+
name = 'Name',
|
|
45
|
+
postcode = 'Postcode'
|
|
46
46
|
}
|
|
47
47
|
export type Service_Buy = {
|
|
48
48
|
item: string;
|
|
@@ -96,7 +96,7 @@ export class Service {
|
|
|
96
96
|
|
|
97
97
|
let s = new Service(protocol, pay_token_type, permission);
|
|
98
98
|
let txb = protocol.CurrentSession();
|
|
99
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
99
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
100
100
|
|
|
101
101
|
if (passport) {
|
|
102
102
|
s.object = txb.moveCall({
|
|
@@ -130,16 +130,7 @@ export class Service {
|
|
|
130
130
|
typeArguments:[this.pay_token_type]
|
|
131
131
|
})
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
135
|
-
let txb = this.protocol.CurrentSession();
|
|
136
|
-
txb.moveCall({
|
|
137
|
-
target:this.protocol.ServiceFn(like) as FnCallType,
|
|
138
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
139
|
-
typeArguments:[this.pay_token_type]
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
*/
|
|
133
|
+
|
|
143
134
|
set_description(description:string, passport?:PassportObject) {
|
|
144
135
|
if (!IsValidDesription(description)) {
|
|
145
136
|
ERROR(Errors.IsValidDesription)
|
|
@@ -510,16 +501,16 @@ export class Service {
|
|
|
510
501
|
if (passport) {
|
|
511
502
|
txb.moveCall({
|
|
512
503
|
target:this.protocol.ServiceFn('sales_add_with_passport') as FnCallType,
|
|
513
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
514
|
-
txb.pure(Bcs.getInstance().
|
|
504
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
|
|
505
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
515
506
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
516
507
|
typeArguments:[this.pay_token_type]
|
|
517
508
|
})
|
|
518
509
|
} else {
|
|
519
510
|
txb.moveCall({
|
|
520
511
|
target:this.protocol.ServiceFn('sales_add') as FnCallType,
|
|
521
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
522
|
-
txb.pure(Bcs.getInstance().
|
|
512
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
|
|
513
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
523
514
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
524
515
|
typeArguments:[this.pay_token_type]
|
|
525
516
|
})
|
|
@@ -545,7 +536,7 @@ export class Service {
|
|
|
545
536
|
} else {
|
|
546
537
|
txb.moveCall({
|
|
547
538
|
target:this.protocol.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
548
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
539
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
549
540
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
550
541
|
typeArguments:[this.pay_token_type]
|
|
551
542
|
})
|
|
@@ -560,7 +551,7 @@ export class Service {
|
|
|
560
551
|
} else {
|
|
561
552
|
txb.moveCall({
|
|
562
553
|
target:this.protocol.ServiceFn('sales_remove') as FnCallType,
|
|
563
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
554
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
564
555
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
565
556
|
typeArguments:[this.pay_token_type]
|
|
566
557
|
})
|
|
@@ -590,9 +581,9 @@ export class Service {
|
|
|
590
581
|
let txb = this.protocol.CurrentSession();
|
|
591
582
|
discount_dispatch.forEach((discount) => {
|
|
592
583
|
let price_greater = discount.discount?.price_greater ?
|
|
593
|
-
txb.pure(Bcs.getInstance().
|
|
584
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, discount.discount.price_greater)) : OptionNone(txb);
|
|
594
585
|
let time_start = discount.discount?.time_start ?
|
|
595
|
-
txb.pure(Bcs.getInstance().
|
|
586
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, discount.discount.time_start)) : OptionNone(txb);
|
|
596
587
|
|
|
597
588
|
if (passport) {
|
|
598
589
|
txb.moveCall({
|
|
@@ -711,7 +702,7 @@ export class Service {
|
|
|
711
702
|
}
|
|
712
703
|
|
|
713
704
|
let txb = this.protocol.CurrentSession();
|
|
714
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
705
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
715
706
|
|
|
716
707
|
if (passport) {
|
|
717
708
|
txb.moveCall({
|
|
@@ -774,7 +765,7 @@ export class Service {
|
|
|
774
765
|
txb.moveCall({
|
|
775
766
|
target:this.protocol.ServiceFn('required_set_with_passport') as FnCallType,
|
|
776
767
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
777
|
-
txb.pure(Bcs.getInstance().
|
|
768
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_required))),
|
|
778
769
|
txb.pure(pubkey, 'vector<u8>'), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
779
770
|
typeArguments:[this.pay_token_type]
|
|
780
771
|
})
|
|
@@ -782,7 +773,7 @@ export class Service {
|
|
|
782
773
|
txb.moveCall({
|
|
783
774
|
target:this.protocol.ServiceFn('required_set') as FnCallType,
|
|
784
775
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
785
|
-
txb.pure(Bcs.getInstance().
|
|
776
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_required))),
|
|
786
777
|
txb.pure(pubkey, 'vector<u8>'), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
787
778
|
typeArguments:[this.pay_token_type]
|
|
788
779
|
})
|
|
@@ -903,7 +894,7 @@ export class Service {
|
|
|
903
894
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, order),
|
|
904
895
|
txb.pure(customer_info_crypto.pubkey, 'vector<u8>'),
|
|
905
896
|
txb.pure(customer_info_crypto.customer_pubkey, 'vector<u8>'),
|
|
906
|
-
txb.pure(Bcs.getInstance().
|
|
897
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_info_crypto.customer_info_crypt)))],
|
|
907
898
|
typeArguments:[this.pay_token_type]
|
|
908
899
|
})
|
|
909
900
|
|
|
@@ -935,16 +926,16 @@ export class Service {
|
|
|
935
926
|
if (discount) {
|
|
936
927
|
order = txb.moveCall({
|
|
937
928
|
target:this.protocol.ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
938
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
939
|
-
txb.pure(Bcs.getInstance().
|
|
929
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
930
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
940
931
|
Protocol.TXB_OBJECT(txb, coin), Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
941
932
|
typeArguments:[this.pay_token_type]
|
|
942
933
|
})} else {
|
|
943
934
|
order = txb.moveCall({
|
|
944
935
|
target:this.protocol.ServiceFn('buy_with_passport') as FnCallType,
|
|
945
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
946
|
-
txb.pure(Bcs.getInstance().
|
|
947
|
-
txb.pure(Bcs.getInstance().
|
|
936
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
937
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
938
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
948
939
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
949
940
|
typeArguments:[this.pay_token_type]
|
|
950
941
|
})}
|
|
@@ -952,18 +943,18 @@ export class Service {
|
|
|
952
943
|
if (discount) {
|
|
953
944
|
order = txb.moveCall({
|
|
954
945
|
target:this.protocol.ServiceFn('disoucnt_buy') as FnCallType,
|
|
955
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
956
|
-
txb.pure(Bcs.getInstance().
|
|
957
|
-
txb.pure(Bcs.getInstance().
|
|
946
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
947
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
948
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
958
949
|
Protocol.TXB_OBJECT(txb, coin),
|
|
959
950
|
Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
960
951
|
typeArguments:[this.pay_token_type]
|
|
961
952
|
})} else {
|
|
962
953
|
order = txb.moveCall({
|
|
963
954
|
target:this.protocol.ServiceFn('buy') as FnCallType,
|
|
964
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
965
|
-
txb.pure(Bcs.getInstance().
|
|
966
|
-
txb.pure(Bcs.getInstance().
|
|
955
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
956
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
957
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
967
958
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
968
959
|
typeArguments:[this.pay_token_type]
|
|
969
960
|
})}
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, StructTypeDefinition } from '@mysten/bcs';
|
|
2
2
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
|
-
import {
|
|
4
|
+
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui.js/utils'
|
|
5
|
+
import { ValueType } from './protocol'
|
|
5
6
|
|
|
6
7
|
export const OPTION_NONE = 0;
|
|
7
|
-
export const readOption = (arr: number[], de:
|
|
8
|
+
export const readOption = (arr: number[], de:ValueType) : {bNone:boolean, value:any}=> {
|
|
8
9
|
let o = arr.splice(0, 1);
|
|
9
10
|
if (o[0] == 1) { // true
|
|
10
11
|
return {bNone:false, value:Bcs.getInstance().de(de, Uint8Array.from(arr))};
|
|
@@ -16,6 +17,21 @@ export const readOption = (arr: number[], de:string) : {bNone:boolean, value:any
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
export const readOptionString = (arr: number[]) : {bNone:boolean, value:any}=> {
|
|
21
|
+
let o = arr.splice(0, 1);
|
|
22
|
+
if (o[0] == 1) { // true
|
|
23
|
+
let r = ulebDecode(Uint8Array.from(arr));
|
|
24
|
+
let value = Bcs.getInstance().de(ValueType.TYPE_STRING, Uint8Array.from(arr));
|
|
25
|
+
arr.splice(0, r.value+r.length);
|
|
26
|
+
return {bNone:false, value:value};
|
|
27
|
+
} else if (o[0] == 0) {
|
|
28
|
+
return {bNone:true, value:OPTION_NONE};
|
|
29
|
+
} else {
|
|
30
|
+
ERROR(Errors.Fail, 'readOption: option invalid')
|
|
31
|
+
return {bNone:true, value:OPTION_NONE}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
19
35
|
export const ulebDecode = (arr: Uint8Array) : {value: number, length: number} => {
|
|
20
36
|
let total = 0;
|
|
21
37
|
let shift = 0;
|
|
@@ -124,63 +140,107 @@ export class Bcs {
|
|
|
124
140
|
};
|
|
125
141
|
return Bcs._instance;
|
|
126
142
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
143
|
+
ser(type:ValueType, data:Uint8Array | any) : Uint8Array {
|
|
144
|
+
switch(type) {
|
|
145
|
+
case ValueType.TYPE_BOOL:
|
|
146
|
+
return this.bcs.ser(BCS.BOOL, data).toBytes();
|
|
147
|
+
case ValueType.TYPE_ADDRESS:
|
|
148
|
+
return this.bcs.ser(BCS.ADDRESS, data).toBytes();
|
|
149
|
+
case ValueType.TYPE_U64:
|
|
150
|
+
return this.bcs.ser(BCS.U64, data).toBytes();
|
|
151
|
+
case ValueType.TYPE_U8:
|
|
152
|
+
return this.bcs.ser(BCS.U8, data).toBytes();
|
|
153
|
+
case ValueType.TYPE_VEC_U8:
|
|
154
|
+
return this.bcs.ser('vector<u8>', data).toBytes();
|
|
155
|
+
case ValueType.TYPE_U128:
|
|
156
|
+
return this.bcs.ser(BCS.U128, data).toBytes();
|
|
157
|
+
case ValueType.TYPE_VEC_ADDRESS:
|
|
158
|
+
return this.bcs.ser('vector<address>', data).toBytes();
|
|
159
|
+
case ValueType.TYPE_VEC_BOOL:
|
|
160
|
+
return this.bcs.ser('vector<bool>', data).toBytes();
|
|
161
|
+
case ValueType.TYPE_VEC_VEC_U8:
|
|
162
|
+
return this.bcs.ser('vector<vector<u8>>', data).toBytes();
|
|
163
|
+
case ValueType.TYPE_VEC_U64:
|
|
164
|
+
return this.bcs.ser('vector<u64>', data).toBytes();
|
|
165
|
+
case ValueType.TYPE_VEC_U128:
|
|
166
|
+
return this.bcs.ser('vector<u128>', data).toBytes();
|
|
167
|
+
case ValueType.TYPE_OPTION_ADDRESS:
|
|
168
|
+
return this.bcs.ser('Option<address>', {'some': data}).toBytes();
|
|
169
|
+
case ValueType.TYPE_OPTION_BOOL:
|
|
170
|
+
return this.bcs.ser('Option<bool>', {'some': data}).toBytes();
|
|
171
|
+
case ValueType.TYPE_OPTION_U8:
|
|
172
|
+
return this.bcs.ser('Option<u8>', {'some': data}).toBytes();
|
|
173
|
+
case ValueType.TYPE_OPTION_U64:
|
|
174
|
+
return this.bcs.ser('Option<u64>', {'some': data}).toBytes();
|
|
175
|
+
case ValueType.TYPE_OPTION_U128:
|
|
176
|
+
return this.bcs.ser('Option<u128>', {'some': data}).toBytes();
|
|
177
|
+
case ValueType.TYPE_OPTION_U256:
|
|
178
|
+
return this.bcs.ser('Option<u256>', {'some': data}).toBytes();
|
|
179
|
+
case ValueType.TYPE_OPTION_STRING:
|
|
180
|
+
return this.bcs.ser('Option<string>', {'some': data}).toBytes();
|
|
181
|
+
case ValueType.TYPE_VEC_U256:
|
|
182
|
+
return this.bcs.ser('vector<u256>', data).toBytes();
|
|
183
|
+
case ValueType.TYPE_U256:
|
|
184
|
+
return this.bcs.ser(BCS.U256, data).toBytes();
|
|
185
|
+
case ValueType.TYPE_STRING:
|
|
186
|
+
return this.bcs.ser(BCS.STRING, data).toBytes();
|
|
187
|
+
case ValueType.TYPE_VEC_STRING:
|
|
188
|
+
return this.bcs.ser('vector<string>', data).toBytes();
|
|
189
|
+
default:
|
|
190
|
+
ERROR(Errors.bcsTypeInvalid, 'ser');
|
|
191
|
+
}
|
|
192
|
+
return new Uint8Array();
|
|
156
193
|
}
|
|
157
194
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
de(type:ValueType, data:Uint8Array | any) : any {
|
|
196
|
+
switch(type) {
|
|
197
|
+
case ValueType.TYPE_BOOL:
|
|
198
|
+
return this.bcs.de(BCS.BOOL, data);
|
|
199
|
+
case ValueType.TYPE_ADDRESS:
|
|
200
|
+
return this.bcs.de(BCS.ADDRESS, data);
|
|
201
|
+
case ValueType.TYPE_U64:
|
|
202
|
+
return this.bcs.de(BCS.U64, data);
|
|
203
|
+
case ValueType.TYPE_U8:
|
|
204
|
+
return this.bcs.de(BCS.U8, data);
|
|
205
|
+
case ValueType.TYPE_VEC_U8:
|
|
206
|
+
return this.bcs.de('vector<u8>', data);
|
|
207
|
+
case ValueType.TYPE_U128:
|
|
208
|
+
return this.bcs.de(BCS.U128, data);
|
|
209
|
+
case ValueType.TYPE_VEC_ADDRESS:
|
|
210
|
+
return this.bcs.de('vector<address>', data);
|
|
211
|
+
case ValueType.TYPE_VEC_BOOL:
|
|
212
|
+
return this.bcs.de('vector<bool>', data);
|
|
213
|
+
case ValueType.TYPE_VEC_VEC_U8:
|
|
214
|
+
return this.bcs.de('vector<vector<u8>>', data);
|
|
215
|
+
case ValueType.TYPE_VEC_U64:
|
|
216
|
+
return this.bcs.de('vector<u64>', data);
|
|
217
|
+
case ValueType.TYPE_VEC_U128:
|
|
218
|
+
return this.bcs.de('vector<u128>', data);
|
|
219
|
+
case ValueType.TYPE_OPTION_ADDRESS:
|
|
220
|
+
return this.bcs.de('Option<address>', data);
|
|
221
|
+
case ValueType.TYPE_OPTION_BOOL:
|
|
222
|
+
return this.bcs.de('Option<bool>', data);
|
|
223
|
+
case ValueType.TYPE_OPTION_U8:
|
|
224
|
+
return this.bcs.de('Option<u8>', data);
|
|
225
|
+
case ValueType.TYPE_OPTION_U64:
|
|
226
|
+
return this.bcs.de('Option<u64>', data);
|
|
227
|
+
case ValueType.TYPE_OPTION_U128:
|
|
228
|
+
return this.bcs.de('Option<u128>', data);
|
|
229
|
+
case ValueType.TYPE_OPTION_U256:
|
|
230
|
+
return this.bcs.de('Option<u256>', data);
|
|
231
|
+
case ValueType.TYPE_OPTION_STRING:
|
|
232
|
+
return this.bcs.de('Option<string>', data);
|
|
233
|
+
case ValueType.TYPE_VEC_U256:
|
|
234
|
+
return this.bcs.de('vector<u256>', data);
|
|
235
|
+
case ValueType.TYPE_STRING:
|
|
236
|
+
return this.bcs.de(BCS.STRING, data);
|
|
237
|
+
case ValueType.TYPE_VEC_STRING:
|
|
238
|
+
return this.bcs.de('vector<string>', data);
|
|
239
|
+
case ValueType.TYPE_U256:
|
|
240
|
+
return this.bcs.de(BCS.U256, data);
|
|
241
|
+
default:
|
|
242
|
+
ERROR(Errors.bcsTypeInvalid, 'de');
|
|
243
|
+
}
|
|
184
244
|
}
|
|
185
245
|
}
|
|
186
246
|
|
|
@@ -238,7 +298,7 @@ export const IsValidDesription = (description:string) : boolean => { return desc
|
|
|
238
298
|
export const IsValidName = (name:string) : boolean => { if(!name) return false; return name.length <= MAX_NAME_LENGTH && name.length != 0 }
|
|
239
299
|
export const IsValidName_AllowEmpty = (name:string) : boolean => { return name.length <= MAX_NAME_LENGTH }
|
|
240
300
|
export const IsValidEndpoint = (endpoint:string) : boolean => { if (!endpoint) return false; return endpoint.length <= MAX_ENDPOINT_LENGTH }
|
|
241
|
-
export const IsValidAddress = (addr:string) : boolean => { if (!addr) return false; return true}
|
|
301
|
+
export const IsValidAddress = (addr:string) : boolean => { if (!addr || !isValidSuiAddress(addr)) return false; return true}
|
|
242
302
|
export const IsValidArgType = (argType: string) : boolean => { if (!argType) return false; return argType.length != 0 }
|
|
243
303
|
export const IsValidUint = (value: number) : boolean => { return Number.isSafeInteger(value) && value != 0 }
|
|
244
304
|
export const IsValidInt = (value: number) : boolean => { return Number.isSafeInteger(value) }
|
package/src/vote.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BCS } from '@mysten/bcs';
|
|
|
2
2
|
import { FnCallType, PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject} from './protocol';
|
|
3
3
|
import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
import {
|
|
5
|
+
import { ValueType } from './protocol';
|
|
6
6
|
|
|
7
7
|
export const MAX_AGREES_COUNT = 200;
|
|
8
8
|
export const MAX_CHOICE_COUNT = 200;
|
|
@@ -51,7 +51,7 @@ export class Vote {
|
|
|
51
51
|
|
|
52
52
|
let v = new Vote(protocol, permission);
|
|
53
53
|
let txb = protocol.CurrentSession();
|
|
54
|
-
let reference = reference_address? txb.pure(Bcs.getInstance().
|
|
54
|
+
let reference = reference_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
|
|
55
55
|
let choice_count = max_choice_count ? max_choice_count : 1;
|
|
56
56
|
|
|
57
57
|
if (passport) {
|
|
@@ -112,7 +112,7 @@ export class Vote {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
let txb = this.protocol.CurrentSession();
|
|
115
|
-
let reference = reference_address? txb.pure(Bcs.getInstance().
|
|
115
|
+
let reference = reference_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
|
|
116
116
|
if (passport) {
|
|
117
117
|
txb.moveCall({
|
|
118
118
|
target:this.protocol.VoteFn('reference_set_with_passport') as FnCallType,
|
|
@@ -207,7 +207,7 @@ export class Vote {
|
|
|
207
207
|
let txb = this.protocol.CurrentSession();
|
|
208
208
|
options.forEach((option) => {
|
|
209
209
|
let reference = option?.reference_address ?
|
|
210
|
-
txb.pure(Bcs.getInstance().
|
|
210
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, option.reference_address)) :
|
|
211
211
|
OptionNone(txb);
|
|
212
212
|
|
|
213
213
|
if (passport) {
|
|
@@ -244,7 +244,7 @@ export class Vote {
|
|
|
244
244
|
txb.moveCall({
|
|
245
245
|
target:this.protocol.VoteFn('agrees_remove_with_passport') as FnCallType,
|
|
246
246
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
247
|
-
txb.pure(Bcs.getInstance().
|
|
247
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
|
|
248
248
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
249
249
|
})
|
|
250
250
|
}
|
|
@@ -258,7 +258,7 @@ export class Vote {
|
|
|
258
258
|
txb.moveCall({
|
|
259
259
|
target:this.protocol.VoteFn('agrees_remove') as FnCallType,
|
|
260
260
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
261
|
-
txb.pure(Bcs.getInstance().
|
|
261
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
|
|
262
262
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
263
263
|
})
|
|
264
264
|
}
|
|
@@ -360,13 +360,13 @@ export class Vote {
|
|
|
360
360
|
txb.moveCall({
|
|
361
361
|
target:this.protocol.VoteFn('with_passport') as FnCallType,
|
|
362
362
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
363
|
-
txb.pure(Bcs.getInstance().
|
|
363
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
|
|
364
364
|
})
|
|
365
365
|
} else {
|
|
366
366
|
txb.moveCall({
|
|
367
367
|
target:this.protocol.VoteFn('this.object') as FnCallType,
|
|
368
368
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
369
|
-
txb.pure(Bcs.getInstance().
|
|
369
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
|
|
370
370
|
})
|
|
371
371
|
}
|
|
372
372
|
|