wowok 1.2.3 → 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 +5 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +9 -3
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +5 -15
- package/dist/service.js +25 -25
- package/dist/utils.d.ts +9 -21
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +114 -53
- 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 +13 -6
- package/src/repository.ts +5 -14
- package/src/service.ts +25 -25
- package/src/utils.ts +116 -57
- package/src/vote.ts +8 -8
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';
|
|
@@ -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({
|
|
@@ -501,16 +501,16 @@ export class Service {
|
|
|
501
501
|
if (passport) {
|
|
502
502
|
txb.moveCall({
|
|
503
503
|
target:this.protocol.ServiceFn('sales_add_with_passport') as FnCallType,
|
|
504
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
505
|
-
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)),
|
|
506
506
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
507
507
|
typeArguments:[this.pay_token_type]
|
|
508
508
|
})
|
|
509
509
|
} else {
|
|
510
510
|
txb.moveCall({
|
|
511
511
|
target:this.protocol.ServiceFn('sales_add') as FnCallType,
|
|
512
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
513
|
-
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)),
|
|
514
514
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
515
515
|
typeArguments:[this.pay_token_type]
|
|
516
516
|
})
|
|
@@ -536,7 +536,7 @@ export class Service {
|
|
|
536
536
|
} else {
|
|
537
537
|
txb.moveCall({
|
|
538
538
|
target:this.protocol.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
539
|
-
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!))),
|
|
540
540
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
541
541
|
typeArguments:[this.pay_token_type]
|
|
542
542
|
})
|
|
@@ -551,7 +551,7 @@ export class Service {
|
|
|
551
551
|
} else {
|
|
552
552
|
txb.moveCall({
|
|
553
553
|
target:this.protocol.ServiceFn('sales_remove') as FnCallType,
|
|
554
|
-
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!))),
|
|
555
555
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
556
556
|
typeArguments:[this.pay_token_type]
|
|
557
557
|
})
|
|
@@ -581,9 +581,9 @@ export class Service {
|
|
|
581
581
|
let txb = this.protocol.CurrentSession();
|
|
582
582
|
discount_dispatch.forEach((discount) => {
|
|
583
583
|
let price_greater = discount.discount?.price_greater ?
|
|
584
|
-
txb.pure(Bcs.getInstance().
|
|
584
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, discount.discount.price_greater)) : OptionNone(txb);
|
|
585
585
|
let time_start = discount.discount?.time_start ?
|
|
586
|
-
txb.pure(Bcs.getInstance().
|
|
586
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, discount.discount.time_start)) : OptionNone(txb);
|
|
587
587
|
|
|
588
588
|
if (passport) {
|
|
589
589
|
txb.moveCall({
|
|
@@ -702,7 +702,7 @@ export class Service {
|
|
|
702
702
|
}
|
|
703
703
|
|
|
704
704
|
let txb = this.protocol.CurrentSession();
|
|
705
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
705
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
706
706
|
|
|
707
707
|
if (passport) {
|
|
708
708
|
txb.moveCall({
|
|
@@ -765,7 +765,7 @@ export class Service {
|
|
|
765
765
|
txb.moveCall({
|
|
766
766
|
target:this.protocol.ServiceFn('required_set_with_passport') as FnCallType,
|
|
767
767
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
768
|
-
txb.pure(Bcs.getInstance().
|
|
768
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_required))),
|
|
769
769
|
txb.pure(pubkey, 'vector<u8>'), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
770
770
|
typeArguments:[this.pay_token_type]
|
|
771
771
|
})
|
|
@@ -773,7 +773,7 @@ export class Service {
|
|
|
773
773
|
txb.moveCall({
|
|
774
774
|
target:this.protocol.ServiceFn('required_set') as FnCallType,
|
|
775
775
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
776
|
-
txb.pure(Bcs.getInstance().
|
|
776
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_required))),
|
|
777
777
|
txb.pure(pubkey, 'vector<u8>'), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
778
778
|
typeArguments:[this.pay_token_type]
|
|
779
779
|
})
|
|
@@ -894,7 +894,7 @@ export class Service {
|
|
|
894
894
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, order),
|
|
895
895
|
txb.pure(customer_info_crypto.pubkey, 'vector<u8>'),
|
|
896
896
|
txb.pure(customer_info_crypto.customer_pubkey, 'vector<u8>'),
|
|
897
|
-
txb.pure(Bcs.getInstance().
|
|
897
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_info_crypto.customer_info_crypt)))],
|
|
898
898
|
typeArguments:[this.pay_token_type]
|
|
899
899
|
})
|
|
900
900
|
|
|
@@ -926,16 +926,16 @@ export class Service {
|
|
|
926
926
|
if (discount) {
|
|
927
927
|
order = txb.moveCall({
|
|
928
928
|
target:this.protocol.ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
929
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
930
|
-
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)),
|
|
931
931
|
Protocol.TXB_OBJECT(txb, coin), Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
932
932
|
typeArguments:[this.pay_token_type]
|
|
933
933
|
})} else {
|
|
934
934
|
order = txb.moveCall({
|
|
935
935
|
target:this.protocol.ServiceFn('buy_with_passport') as FnCallType,
|
|
936
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
937
|
-
txb.pure(Bcs.getInstance().
|
|
938
|
-
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)),
|
|
939
939
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
940
940
|
typeArguments:[this.pay_token_type]
|
|
941
941
|
})}
|
|
@@ -943,18 +943,18 @@ export class Service {
|
|
|
943
943
|
if (discount) {
|
|
944
944
|
order = txb.moveCall({
|
|
945
945
|
target:this.protocol.ServiceFn('disoucnt_buy') as FnCallType,
|
|
946
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
947
|
-
txb.pure(Bcs.getInstance().
|
|
948
|
-
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)),
|
|
949
949
|
Protocol.TXB_OBJECT(txb, coin),
|
|
950
950
|
Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
951
951
|
typeArguments:[this.pay_token_type]
|
|
952
952
|
})} else {
|
|
953
953
|
order = txb.moveCall({
|
|
954
954
|
target:this.protocol.ServiceFn('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().
|
|
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)),
|
|
958
958
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
959
959
|
typeArguments:[this.pay_token_type]
|
|
960
960
|
})}
|
package/src/utils.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, StructTypeDefinit
|
|
|
2
2
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
4
|
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui.js/utils'
|
|
5
|
-
|
|
5
|
+
import { ValueType } from './protocol'
|
|
6
6
|
|
|
7
7
|
export const OPTION_NONE = 0;
|
|
8
|
-
export const readOption = (arr: number[], de:
|
|
8
|
+
export const readOption = (arr: number[], de:ValueType) : {bNone:boolean, value:any}=> {
|
|
9
9
|
let o = arr.splice(0, 1);
|
|
10
10
|
if (o[0] == 1) { // true
|
|
11
11
|
return {bNone:false, value:Bcs.getInstance().de(de, Uint8Array.from(arr))};
|
|
@@ -17,6 +17,21 @@ export const readOption = (arr: number[], de:string) : {bNone:boolean, value:any
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
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
|
+
|
|
20
35
|
export const ulebDecode = (arr: Uint8Array) : {value: number, length: number} => {
|
|
21
36
|
let total = 0;
|
|
22
37
|
let shift = 0;
|
|
@@ -125,63 +140,107 @@ export class Bcs {
|
|
|
125
140
|
};
|
|
126
141
|
return Bcs._instance;
|
|
127
142
|
}
|
|
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
|
-
|
|
156
|
-
|
|
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();
|
|
157
193
|
}
|
|
158
194
|
|
|
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
|
-
|
|
184
|
-
|
|
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
|
+
}
|
|
185
244
|
}
|
|
186
245
|
}
|
|
187
246
|
|
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
|
|