wowok 1.1.0 → 1.1.2
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/README.md +1 -1
- package/dist/demand.d.ts +2 -3
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +19 -11
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/graphql.d.ts +2 -0
- package/dist/graphql.d.ts.map +1 -1
- package/dist/graphql.js +19 -0
- package/dist/guard.d.ts +18 -23
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +220 -199
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/machine.d.ts +6 -6
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +7 -7
- package/dist/passport.d.ts +34 -22
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +124 -214
- package/dist/permission.d.ts +3 -0
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +5 -2
- package/dist/progress.js +3 -3
- package/dist/protocol.d.ts +11 -5
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +30 -6
- package/dist/repository.d.ts +2 -0
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +73 -5
- package/dist/service.d.ts +3 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +115 -116
- package/dist/utils.d.ts +10 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +39 -1
- package/dist/vote.js +8 -8
- package/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/graphql.ts +20 -0
- package/src/guard.ts +208 -192
- package/src/index.ts +1 -0
- package/src/machine.ts +10 -10
- package/src/passport.ts +139 -251
- package/src/permission.ts +5 -2
- package/src/progress.ts +3 -3
- package/src/protocol.ts +26 -5
- package/src/repository.ts +73 -5
- package/src/service.ts +25 -25
- package/src/utils.ts +44 -4
- package/src/vote.ts +8 -8
- package/tsconfig.json +3 -2
package/src/repository.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { Protocol, FnCallType, ValueType, RepositoryObject, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
|
|
3
3
|
import { PermissionIndexType, Permission } from './permission'
|
|
4
|
-
import {
|
|
4
|
+
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, } from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
6
|
|
|
7
7
|
export enum Repository_Policy_Mode {
|
|
@@ -139,6 +139,74 @@ export class Repository {
|
|
|
139
139
|
],
|
|
140
140
|
})
|
|
141
141
|
}
|
|
142
|
+
add_reference(references:string[], passport?:PassportObject) {
|
|
143
|
+
if (!references) {
|
|
144
|
+
ERROR(Errors.InvalidParam, 'references')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!IsValidArray(references, IsValidAddress)) {
|
|
148
|
+
ERROR(Errors.IsValidArray, 'references')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let txb = this.protocol.CurrentSession();
|
|
152
|
+
if (passport) {
|
|
153
|
+
txb.moveCall({
|
|
154
|
+
target:this.protocol.RepositoryFn('reference_add_with_passport') as FnCallType,
|
|
155
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
156
|
+
txb.pure(array_unique(references), 'vector<address>'),
|
|
157
|
+
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
158
|
+
})
|
|
159
|
+
} else {
|
|
160
|
+
txb.moveCall({
|
|
161
|
+
target:this.protocol.RepositoryFn('reference_add') as FnCallType,
|
|
162
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
163
|
+
txb.pure(array_unique(references), 'vector<address>'),
|
|
164
|
+
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
remove_reference(references:string[], removeall?:boolean, passport?:PassportObject) {
|
|
169
|
+
if (!references) {
|
|
170
|
+
ERROR(Errors.InvalidParam, 'references')
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!IsValidArray(references, IsValidAddress)) {
|
|
174
|
+
ERROR(Errors.IsValidArray, 'references')
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let txb = this.protocol.CurrentSession();
|
|
178
|
+
if (removeall) {
|
|
179
|
+
if (passport) {
|
|
180
|
+
txb.moveCall({
|
|
181
|
+
target:this.protocol.RepositoryFn('reference_removeall_with_passport') as FnCallType,
|
|
182
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
183
|
+
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
184
|
+
})
|
|
185
|
+
} else {
|
|
186
|
+
txb.moveCall({
|
|
187
|
+
target:this.protocol.RepositoryFn('reference_removeall') as FnCallType,
|
|
188
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
189
|
+
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
if (passport) {
|
|
194
|
+
txb.moveCall({
|
|
195
|
+
target:this.protocol.RepositoryFn('reference_remove_with_passport') as FnCallType,
|
|
196
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
197
|
+
txb.pure(array_unique(references), 'vector<address>'),
|
|
198
|
+
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
199
|
+
})
|
|
200
|
+
} else {
|
|
201
|
+
txb.moveCall({
|
|
202
|
+
target:this.protocol.RepositoryFn('reference_remove') as FnCallType,
|
|
203
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
204
|
+
txb.pure(array_unique(references), 'vector<address>'),
|
|
205
|
+
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
142
210
|
// add or modify the old
|
|
143
211
|
add_policies(policies:Repository_Policy[], passport?:PassportObject) {
|
|
144
212
|
if (!policies) {
|
|
@@ -157,7 +225,7 @@ export class Repository {
|
|
|
157
225
|
|
|
158
226
|
let txb = this.protocol.CurrentSession();
|
|
159
227
|
policies.forEach((policy) => {
|
|
160
|
-
let permission_index = policy?.permission ? txb.pure(
|
|
228
|
+
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().ser_option_u64(policy.permission)) : OptionNone(txb);
|
|
161
229
|
if (passport) {
|
|
162
230
|
txb.moveCall({
|
|
163
231
|
target:this.protocol.RepositoryFn('policy_add_with_passport') as FnCallType,
|
|
@@ -199,7 +267,7 @@ export class Repository {
|
|
|
199
267
|
txb.moveCall({
|
|
200
268
|
target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
201
269
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
202
|
-
txb.pure(
|
|
270
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(policy_keys))),
|
|
203
271
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
204
272
|
})
|
|
205
273
|
}
|
|
@@ -213,7 +281,7 @@ export class Repository {
|
|
|
213
281
|
txb.moveCall({
|
|
214
282
|
target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
|
|
215
283
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
216
|
-
txb.pure(
|
|
284
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(policy_keys))),
|
|
217
285
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
218
286
|
})
|
|
219
287
|
}
|
|
@@ -293,7 +361,7 @@ export class Repository {
|
|
|
293
361
|
if(!Permission.IsValidPermissionIndex(permission_index)) {
|
|
294
362
|
ERROR(Errors.IsValidPermissionIndex)
|
|
295
363
|
}
|
|
296
|
-
index = txb.pure(
|
|
364
|
+
index = txb.pure(Bcs.getInstance().ser_option_u64(permission_index));
|
|
297
365
|
}
|
|
298
366
|
|
|
299
367
|
if (passport) {
|
package/src/service.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
|
|
2
|
-
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty,
|
|
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
5
|
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol,
|
|
@@ -95,7 +95,7 @@ export class Service {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
let txb = protocol.CurrentSession();
|
|
98
|
-
let ep = endpoint? txb.pure(
|
|
98
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser_option_string(endpoint)) : OptionNone(txb);
|
|
99
99
|
|
|
100
100
|
if (passport) {
|
|
101
101
|
s.object = txb.moveCall({
|
|
@@ -499,16 +499,16 @@ export class Service {
|
|
|
499
499
|
if (passport) {
|
|
500
500
|
txb.moveCall({
|
|
501
501
|
target:this.protocol.ServiceFn('sales_add_with_passport') as FnCallType,
|
|
502
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
503
|
-
txb.pure(
|
|
502
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(names)),
|
|
503
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(price)), txb.pure(Bcs.getInstance().ser_vector_u64(stock)),
|
|
504
504
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
505
505
|
typeArguments:[this.pay_token_type]
|
|
506
506
|
})
|
|
507
507
|
} else {
|
|
508
508
|
txb.moveCall({
|
|
509
509
|
target:this.protocol.ServiceFn('sales_add') as FnCallType,
|
|
510
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
511
|
-
txb.pure(
|
|
510
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(names)),
|
|
511
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(price)), txb.pure(Bcs.getInstance().ser_vector_u64(stock)),
|
|
512
512
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
513
513
|
typeArguments:[this.pay_token_type]
|
|
514
514
|
})
|
|
@@ -534,7 +534,7 @@ export class Service {
|
|
|
534
534
|
} else {
|
|
535
535
|
txb.moveCall({
|
|
536
536
|
target:this.protocol.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
537
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
537
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(array_unique(sales!))),
|
|
538
538
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
539
539
|
typeArguments:[this.pay_token_type]
|
|
540
540
|
})
|
|
@@ -549,7 +549,7 @@ export class Service {
|
|
|
549
549
|
} else {
|
|
550
550
|
txb.moveCall({
|
|
551
551
|
target:this.protocol.ServiceFn('sales_remove') as FnCallType,
|
|
552
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
552
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(array_unique(sales!))),
|
|
553
553
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
554
554
|
typeArguments:[this.pay_token_type]
|
|
555
555
|
})
|
|
@@ -579,9 +579,9 @@ export class Service {
|
|
|
579
579
|
let txb = this.protocol.CurrentSession();
|
|
580
580
|
discount_dispatch.forEach((discount) => {
|
|
581
581
|
let price_greater = discount.discount?.price_greater ?
|
|
582
|
-
txb.pure(
|
|
582
|
+
txb.pure(Bcs.getInstance().ser_option_u64(discount.discount.price_greater)) : OptionNone(txb);
|
|
583
583
|
let time_start = discount.discount?.time_start ?
|
|
584
|
-
txb.pure(
|
|
584
|
+
txb.pure(Bcs.getInstance().ser_option_u64(discount.discount.time_start)) : OptionNone(txb);
|
|
585
585
|
|
|
586
586
|
if (passport) {
|
|
587
587
|
txb.moveCall({
|
|
@@ -700,7 +700,7 @@ export class Service {
|
|
|
700
700
|
}
|
|
701
701
|
|
|
702
702
|
let txb = this.protocol.CurrentSession();
|
|
703
|
-
let ep = endpoint? txb.pure(
|
|
703
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser_option_string(endpoint)) : OptionNone(txb);
|
|
704
704
|
|
|
705
705
|
if (passport) {
|
|
706
706
|
txb.moveCall({
|
|
@@ -763,7 +763,7 @@ export class Service {
|
|
|
763
763
|
txb.moveCall({
|
|
764
764
|
target:this.protocol.ServiceFn('required_set_with_passport') as FnCallType,
|
|
765
765
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
766
|
-
txb.pure(
|
|
766
|
+
txb.pure(Bcs.getInstance().ser_vector_vector_u8(array_unique(customer_required))),
|
|
767
767
|
txb.pure(pubkey, 'vector<u8>'), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
768
768
|
typeArguments:[this.pay_token_type]
|
|
769
769
|
})
|
|
@@ -771,7 +771,7 @@ export class Service {
|
|
|
771
771
|
txb.moveCall({
|
|
772
772
|
target:this.protocol.ServiceFn('required_set') as FnCallType,
|
|
773
773
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
774
|
-
txb.pure(
|
|
774
|
+
txb.pure(Bcs.getInstance().ser_vector_vector_u8(array_unique(customer_required))),
|
|
775
775
|
txb.pure(pubkey, 'vector<u8>'), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
776
776
|
typeArguments:[this.pay_token_type]
|
|
777
777
|
})
|
|
@@ -892,7 +892,7 @@ export class Service {
|
|
|
892
892
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, order),
|
|
893
893
|
txb.pure(customer_info_crypto.pubkey, 'vector<u8>'),
|
|
894
894
|
txb.pure(customer_info_crypto.customer_pubkey, 'vector<u8>'),
|
|
895
|
-
txb.pure(
|
|
895
|
+
txb.pure(Bcs.getInstance().ser_vector_vector_u8(array_unique(customer_info_crypto.customer_info_crypt)))],
|
|
896
896
|
typeArguments:[this.pay_token_type]
|
|
897
897
|
})
|
|
898
898
|
|
|
@@ -924,16 +924,16 @@ export class Service {
|
|
|
924
924
|
if (discount) {
|
|
925
925
|
order = txb.moveCall({
|
|
926
926
|
target:this.protocol.ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
927
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
928
|
-
txb.pure(
|
|
927
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(name)),
|
|
928
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(price)), txb.pure(Bcs.getInstance().ser_vector_u64(stock)),
|
|
929
929
|
Protocol.TXB_OBJECT(txb, coin), Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
930
930
|
typeArguments:[this.pay_token_type]
|
|
931
931
|
})} else {
|
|
932
932
|
order = txb.moveCall({
|
|
933
933
|
target:this.protocol.ServiceFn('buy_with_passport') as FnCallType,
|
|
934
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
935
|
-
txb.pure(
|
|
936
|
-
txb.pure(
|
|
934
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(name)),
|
|
935
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(price)),
|
|
936
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(stock)),
|
|
937
937
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
938
938
|
typeArguments:[this.pay_token_type]
|
|
939
939
|
})}
|
|
@@ -941,18 +941,18 @@ export class Service {
|
|
|
941
941
|
if (discount) {
|
|
942
942
|
order = txb.moveCall({
|
|
943
943
|
target:this.protocol.ServiceFn('disoucnt_buy') as FnCallType,
|
|
944
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
945
|
-
txb.pure(
|
|
946
|
-
txb.pure(
|
|
944
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(name)),
|
|
945
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(price)),
|
|
946
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(stock)),
|
|
947
947
|
Protocol.TXB_OBJECT(txb, coin),
|
|
948
948
|
Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
949
949
|
typeArguments:[this.pay_token_type]
|
|
950
950
|
})} else {
|
|
951
951
|
order = txb.moveCall({
|
|
952
952
|
target:this.protocol.ServiceFn('buy') as FnCallType,
|
|
953
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
954
|
-
txb.pure(
|
|
955
|
-
txb.pure(
|
|
953
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(name)),
|
|
954
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(price)),
|
|
955
|
+
txb.pure(Bcs.getInstance().ser_vector_u64(stock)),
|
|
956
956
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
957
957
|
typeArguments:[this.pay_token_type]
|
|
958
958
|
})}
|
package/src/utils.ts
CHANGED
|
@@ -72,12 +72,19 @@ export function parse_object_type(object_data:string) : string[] {
|
|
|
72
72
|
|
|
73
73
|
export class Bcs {
|
|
74
74
|
bcs = new BCS(getSuiMoveConfig());
|
|
75
|
-
|
|
75
|
+
private static _instance : any;
|
|
76
|
+
private constructor() {
|
|
76
77
|
this.bcs.registerEnumType('Option<T>', {
|
|
77
78
|
'none': null,
|
|
78
79
|
'some': 'T',
|
|
79
80
|
});
|
|
80
81
|
}
|
|
82
|
+
static getInstance() : Bcs {
|
|
83
|
+
if (!Bcs._instance) {
|
|
84
|
+
Bcs._instance = new Bcs();
|
|
85
|
+
};
|
|
86
|
+
return Bcs._instance;
|
|
87
|
+
}
|
|
81
88
|
ser_option_string(data:string) : Uint8Array {
|
|
82
89
|
return this.bcs.ser('Option<string>', {'some': data}).toBytes();
|
|
83
90
|
}
|
|
@@ -119,9 +126,6 @@ export class Bcs {
|
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
128
|
|
|
122
|
-
export const BCS_CONVERT = new Bcs();
|
|
123
|
-
|
|
124
|
-
|
|
125
129
|
export function stringToUint8Array(str:string) : Uint8Array {
|
|
126
130
|
var arr = [];
|
|
127
131
|
for (var i = 0, j = str.length; i < j; ++i) {
|
|
@@ -193,3 +197,39 @@ export const IsValidArray = (arr: any[], validFunc:any) : boolean => {
|
|
|
193
197
|
|
|
194
198
|
export const OptionNone = (txb:TransactionBlock) : TransactionArgument => { return txb.pure([], BCS.U8) };
|
|
195
199
|
|
|
200
|
+
export type ArgType = {
|
|
201
|
+
isCoin: boolean;
|
|
202
|
+
coin: string;
|
|
203
|
+
token: string;
|
|
204
|
+
}
|
|
205
|
+
export const ParseType = (type:string) : ArgType => {
|
|
206
|
+
let i = type.indexOf('<');
|
|
207
|
+
if (i > 0 && type.length > 12) {
|
|
208
|
+
let c = type.slice(0, i);
|
|
209
|
+
if (c === '0x2::coin::Coin' || c === '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin') {
|
|
210
|
+
let coin = type.slice(i+1, type.length-1); // < >>
|
|
211
|
+
let t = coin.lastIndexOf('::');
|
|
212
|
+
return {isCoin:true, coin:coin, token:coin.slice(t+2)}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {isCoin:false, coin:'', token:''}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function toFixed(x:number) {
|
|
219
|
+
let res = '';
|
|
220
|
+
if (Math.abs(x) < 1.0) {
|
|
221
|
+
var e = parseInt(x.toString().split('e-')[1]);
|
|
222
|
+
if (e) {
|
|
223
|
+
x *= Math.pow(10,e-1);
|
|
224
|
+
res = '0.' + (new Array(e)).join('0') + x.toString().substring(2);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
var e = parseInt(x.toString().split('+')[1]);
|
|
228
|
+
if (e > 20) {
|
|
229
|
+
e -= 20;
|
|
230
|
+
x /= Math.pow(10,e);
|
|
231
|
+
res = x + (new Array(e+1)).join('0');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return res;
|
|
235
|
+
}
|
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, IsValidUint, IsValidAddress, OptionNone,
|
|
3
|
+
import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
5
|
|
|
6
6
|
export const MAX_AGREES_COUNT = 200;
|
|
@@ -50,7 +50,7 @@ export class Vote {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
let txb = protocol.CurrentSession();
|
|
53
|
-
let reference = reference_address? txb.pure(
|
|
53
|
+
let reference = reference_address? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
|
|
54
54
|
let choice_count = max_choice_count ? max_choice_count : 1;
|
|
55
55
|
|
|
56
56
|
if (passport) {
|
|
@@ -111,7 +111,7 @@ export class Vote {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
let txb = this.protocol.CurrentSession();
|
|
114
|
-
let reference = reference_address? txb.pure(
|
|
114
|
+
let reference = reference_address? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
|
|
115
115
|
if (passport) {
|
|
116
116
|
txb.moveCall({
|
|
117
117
|
target:this.protocol.VoteFn('reference_set_with_passport') as FnCallType,
|
|
@@ -206,7 +206,7 @@ export class Vote {
|
|
|
206
206
|
let txb = this.protocol.CurrentSession();
|
|
207
207
|
options.forEach((option) => {
|
|
208
208
|
let reference = option?.reference_address ?
|
|
209
|
-
txb.pure(
|
|
209
|
+
txb.pure(Bcs.getInstance().ser_option_address(option.reference_address)) :
|
|
210
210
|
OptionNone(txb);
|
|
211
211
|
|
|
212
212
|
if (passport) {
|
|
@@ -243,7 +243,7 @@ export class Vote {
|
|
|
243
243
|
txb.moveCall({
|
|
244
244
|
target:this.protocol.VoteFn('agrees_remove_with_passport') as FnCallType,
|
|
245
245
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
246
|
-
txb.pure(
|
|
246
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options))),
|
|
247
247
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
248
248
|
})
|
|
249
249
|
}
|
|
@@ -257,7 +257,7 @@ export class Vote {
|
|
|
257
257
|
txb.moveCall({
|
|
258
258
|
target:this.protocol.VoteFn('agrees_remove') as FnCallType,
|
|
259
259
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
260
|
-
txb.pure(
|
|
260
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options))),
|
|
261
261
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
262
262
|
})
|
|
263
263
|
}
|
|
@@ -359,13 +359,13 @@ export class Vote {
|
|
|
359
359
|
txb.moveCall({
|
|
360
360
|
target:this.protocol.VoteFn('with_passport') as FnCallType,
|
|
361
361
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
362
|
-
txb.pure(
|
|
362
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
|
|
363
363
|
})
|
|
364
364
|
} else {
|
|
365
365
|
txb.moveCall({
|
|
366
366
|
target:this.protocol.VoteFn('this.object') as FnCallType,
|
|
367
367
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
368
|
-
txb.pure(
|
|
368
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
|
|
369
369
|
})
|
|
370
370
|
}
|
|
371
371
|
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
// "outDir": "out",
|
|
4
|
+
// "outDir": "out",
|
|
5
5
|
// "sourceMap": true,
|
|
6
6
|
/* Projects */
|
|
7
7
|
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
/* Language and Environment */
|
|
15
15
|
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
16
16
|
"lib": ["es2020", "DOM"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
-
|
|
17
|
+
"downlevelIteration": true,
|
|
18
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
19
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
20
|
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
21
|
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|