wowok 1.4.19 → 1.4.20
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/guard.ts +87 -155
- package/src/passport.ts +276 -418
- package/src/permission.ts +8 -0
- package/src/progress.ts +6 -5
- package/src/protocol.ts +9 -8
- package/src/utils.ts +2 -4
package/package.json
CHANGED
package/src/guard.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { Protocol, LogicsInfo, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType,
|
|
3
|
+
import { Protocol, LogicsInfo, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType, SER_VALUE} from './protocol';
|
|
4
4
|
import { concatenate, array_equal } from './utils';
|
|
5
5
|
import { IsValidDesription, Bcs, IsValidInt, IsValidAddress, FirstLetterUppercase, insertAtHead } from './utils';
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
@@ -9,9 +9,9 @@ import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
|
9
9
|
export type GuardConstant = Map<number, Guard_Variable>;
|
|
10
10
|
|
|
11
11
|
export interface Guard_Variable {
|
|
12
|
-
type:
|
|
12
|
+
type: ValueType ,
|
|
13
13
|
value?: Uint8Array,
|
|
14
|
-
|
|
14
|
+
bWitness : boolean,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface Guard_Options {
|
|
@@ -39,8 +39,9 @@ export class Guard {
|
|
|
39
39
|
|
|
40
40
|
let bValid = true;
|
|
41
41
|
constants?.forEach((v, k) => {
|
|
42
|
-
if (!
|
|
43
|
-
if (
|
|
42
|
+
if (!GuardMaker.IsValidIndentifier(k)) bValid = false;
|
|
43
|
+
if (v.value && v.bWitness) bValid = false;
|
|
44
|
+
if (v.value === undefined && !v.bWitness) bValid = false;
|
|
44
45
|
})
|
|
45
46
|
if (!bValid) {
|
|
46
47
|
ERROR(Errors.InvalidParam, 'launch constants')
|
|
@@ -55,23 +56,17 @@ export class Guard {
|
|
|
55
56
|
});
|
|
56
57
|
|
|
57
58
|
constants?.forEach((v, k) => {
|
|
58
|
-
if (v.
|
|
59
|
-
|
|
60
|
-
ERROR(Errors.InvalidParam, 'constants type')
|
|
61
|
-
}
|
|
62
|
-
const n = insertAtHead(v.witness!, v.type);
|
|
59
|
+
if (v.bWitness) {
|
|
60
|
+
const n = new Uint8Array(1); n.set([v.type], 0);
|
|
63
61
|
txb.moveCall({
|
|
64
62
|
target:Protocol.Instance().GuardFn("constant_add") as FnCallType,
|
|
65
|
-
arguments:[guard, txb.pure.u8(k), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
|
|
66
|
-
})
|
|
63
|
+
arguments:[guard, txb.pure.u8(k), txb.pure.bool(true), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
|
|
64
|
+
})
|
|
67
65
|
} else {
|
|
68
|
-
if (!v.value) {
|
|
69
|
-
ERROR(Errors.InvalidParam, 'constants type')
|
|
70
|
-
}
|
|
71
66
|
const n = insertAtHead(v.value!, v.type);
|
|
72
67
|
txb.moveCall({
|
|
73
68
|
target:Protocol.Instance().GuardFn("constant_add") as FnCallType,
|
|
74
|
-
arguments:[guard, txb.pure.u8(k), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
|
|
69
|
+
arguments:[guard, txb.pure.u8(k), txb.pure.bool(false), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(true)]
|
|
75
70
|
})
|
|
76
71
|
}
|
|
77
72
|
});
|
|
@@ -95,7 +90,6 @@ export class Guard {
|
|
|
95
90
|
arguments: []
|
|
96
91
|
});
|
|
97
92
|
}
|
|
98
|
-
|
|
99
93
|
static QUERIES:any[] = [
|
|
100
94
|
// module, 'name', 'id', [input], output
|
|
101
95
|
[MODULES.permission, 'Owner', 1, [], ValueType.TYPE_ADDRESS, "Owner's address."],
|
|
@@ -121,14 +115,14 @@ export class Guard {
|
|
|
121
115
|
[MODULES.repository, 'Policy Mode', 110, [], ValueType.TYPE_U8, 'Policy Mode. 0: Free mode; 1: Strict mode.'],
|
|
122
116
|
[MODULES.repository, 'Reference Count', 111, [], ValueType.TYPE_U64, 'The number of times it is referenced by other objects.'],
|
|
123
117
|
[MODULES.repository, 'Is Referenced by An Object', 112, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is it referenced by an object?', 'Input:address'],
|
|
124
|
-
[MODULES.repository, 'Data
|
|
125
|
-
[MODULES.repository, 'Data
|
|
126
|
-
[MODULES.repository, 'Data
|
|
127
|
-
[MODULES.repository, 'Data
|
|
128
|
-
[MODULES.repository, '
|
|
129
|
-
[MODULES.repository, '
|
|
130
|
-
[MODULES.repository, '
|
|
131
|
-
[MODULES.repository, '
|
|
118
|
+
[MODULES.repository, 'Number Data', 113, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_U256, 'Data for a field at an address and get unsigned integer type data.', 'Input 1:address, Input 2:the field name'],
|
|
119
|
+
[MODULES.repository, 'String Data', 114, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_STRING, 'Data for a field at an address and get string type data.', 'Input 1:address, Input 2:the field name'],
|
|
120
|
+
[MODULES.repository, 'Address Data', 115, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'Data for a field at an address and get address type data.', 'Input 1:address, Input 2:the field name'],
|
|
121
|
+
[MODULES.repository, 'Bool Data', 116, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Data for a field at an address and get bool type data.', 'Input 1:address, Input 2:the field name'],
|
|
122
|
+
[MODULES.repository, 'Number Vector Data', 117, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_U256, 'Data for a field at an address and get unsigned integer vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
123
|
+
[MODULES.repository, 'String Vector Data', 118, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_STRING, 'Data for a field at an address and get string vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
124
|
+
[MODULES.repository, 'Address Vector Data', 119, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_ADDRESS, 'Data for a field at an address and get address vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
125
|
+
[MODULES.repository, 'Bool Vector Data', 120, [ValueType.TYPE_ADDRESS, ValueType.TYPE_STRING], ValueType.TYPE_VEC_BOOL, 'Data for a field at an address and get bool vector type data.', 'Input 1:address, Input 2:the field name'],
|
|
132
126
|
|
|
133
127
|
[MODULES.entity, 'Contains Entity?', 200, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is an entity already registered?', 'Input:address'],
|
|
134
128
|
[MODULES.entity, 'Likes', 201, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The number of likes for an address by other addresses.', 'Input:address'],
|
|
@@ -244,7 +238,45 @@ export class Guard {
|
|
|
244
238
|
[MODULES.wowok, 'Grantor Expired Time', 907, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The expiration time of a grantor.', 'Input:address'],
|
|
245
239
|
[MODULES.wowok, 'Grantee Object for Grantor', 908, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
246
240
|
|
|
247
|
-
|
|
241
|
+
[MODULES.payment, 'Sender', 1200, [], ValueType.TYPE_ADDRESS, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
242
|
+
[MODULES.payment, 'Total Amount', 1201, [], ValueType.TYPE_U64, "Name of a grantor.", 'Input:address'],
|
|
243
|
+
[MODULES.payment, 'Tips', 1202, [], ValueType.TYPE_STRING, 'Registration time of a grantor.', 'Input:address'],
|
|
244
|
+
[MODULES.payment, 'Has Guard for Perpose', 1203, [], ValueType.TYPE_BOOL, 'The expiration time of a grantor.', 'Input:address'],
|
|
245
|
+
[MODULES.payment, 'Has Object for Perpose', 1204, [], ValueType.TYPE_BOOL, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
246
|
+
[MODULES.payment, 'Guard for Perpose', 1205, [], ValueType.TYPE_ADDRESS, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
247
|
+
[MODULES.payment, 'Object for Perpose', 1206, [], ValueType.TYPE_ADDRESS, "Name of a grantor.", 'Input:address'],
|
|
248
|
+
[MODULES.payment, 'Number of Transfer', 1207, [], ValueType.TYPE_U64, 'Registration time of a grantor.', 'Input:address'],
|
|
249
|
+
[MODULES.payment, 'Is a Recipient', 1208, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'The expiration time of a grantor.', 'Input:address'],
|
|
250
|
+
[MODULES.payment, 'Amount for a Recipient', 1209, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
251
|
+
[MODULES.payment, 'Time', 1210, [], ValueType.TYPE_U64, 'Registration time of a grantor.', 'Input:address'],
|
|
252
|
+
[MODULES.payment, 'Is from Treasury', 1211, [], ValueType.TYPE_BOOL, 'The expiration time of a grantor.', 'Input:address'],
|
|
253
|
+
[MODULES.payment, 'Treasury Address', 1212, [], ValueType.TYPE_ADDRESS, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
254
|
+
|
|
255
|
+
[MODULES.withholding, 'Has Deposited', 1300, [], ValueType.TYPE_BOOL, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
256
|
+
[MODULES.withholding, 'Original Type Deposited', 1301, [], ValueType.TYPE_STRING, "Name of a grantor.", 'Input:address'],
|
|
257
|
+
[MODULES.withholding, 'Original Package', 1302, [], ValueType.TYPE_ADDRESS, 'Registration time of a grantor.', 'Input:address'],
|
|
258
|
+
[MODULES.withholding, 'Original Module', 1303, [], ValueType.TYPE_STRING, 'The expiration time of a grantor.', 'Input:address'],
|
|
259
|
+
[MODULES.withholding, 'Type Deposited', 1304, [], ValueType.TYPE_STRING, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
260
|
+
[MODULES.withholding, 'Package', 1305, [], ValueType.TYPE_ADDRESS, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
261
|
+
[MODULES.withholding, 'Module', 1306, [], ValueType.TYPE_STRING, 'The expiration time of a grantor.', 'Input:address'],
|
|
262
|
+
[MODULES.withholding, 'Guard for Withdrawing', 1307, [], ValueType.TYPE_ADDRESS, 'Registration time of a grantor.', 'Input:address'],
|
|
263
|
+
[MODULES.withholding, 'Guard for Refunding', 1308, [], ValueType.TYPE_STRING, 'The expiration time of a grantor.', 'Input:address'],
|
|
264
|
+
[MODULES.withholding, 'Deposit Time', 1309, [], ValueType.TYPE_U64, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
265
|
+
[MODULES.withholding, 'Refund Time', 1310, [], ValueType.TYPE_U64, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
266
|
+
[MODULES.withholding, 'Depositor address', 1311, [], ValueType.TYPE_ADDRESS, 'The expiration time of a grantor.', 'Input:address'],
|
|
267
|
+
[MODULES.withholding, 'Re address', 1312, [], ValueType.TYPE_U64, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
268
|
+
// [MODULES.withholding, 'Refund Time', 1313, [], ValueType.TYPE_U64, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
269
|
+
// [MODULES.withholding, 'Depositor address', 1314, [], ValueType.TYPE_ADDRESS, 'The expiration time of a grantor.', 'Input:address'],
|
|
270
|
+
|
|
271
|
+
[MODULES.treasury, 'Permission', 1400, [], ValueType.TYPE_ADDRESS, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
272
|
+
[MODULES.treasury, 'Balance', 1401, [], ValueType.TYPE_U64, "Name of a grantor.", 'Input:address'],
|
|
273
|
+
[MODULES.treasury, 'Number of Flow Records', 1402, [], ValueType.TYPE_U64, 'Registration time of a grantor.', 'Input:address'],
|
|
274
|
+
[MODULES.treasury, 'Deposit Flow', 1403, [], ValueType.TYPE_U128, 'The expiration time of a grantor.', 'Input:address'],
|
|
275
|
+
[MODULES.treasury, 'Take Flow', 1404, [], ValueType.TYPE_U128, 'Grantee repository address of a grantor.', 'Input:address'],
|
|
276
|
+
[MODULES.treasury, 'Flow over a Period of Time', 1405, [ValueType.TYPE_U64, ValueType.TYPE_U64], ValueType.TYPE_U128, 'Whether an address has been registered as a grantor?', , 'Input:address'],
|
|
277
|
+
[MODULES.treasury, 'Deposit Flow over a Period of Time', 1406, [ValueType.TYPE_U64, ValueType.TYPE_U64], ValueType.TYPE_U128, "Name of a grantor.", 'Input:address'],
|
|
278
|
+
[MODULES.treasury, 'Take Flow over a Period of Time', 1407, [ValueType.TYPE_U64, ValueType.TYPE_U64], ValueType.TYPE_U128, 'Registration time of a grantor.', 'Input:address'],
|
|
279
|
+
|
|
248
280
|
/* [MODULES.vote, 'Permission', 171, [], ValueType.TYPE_ADDRESS],
|
|
249
281
|
[MODULES.vote, 'Options Locked', 172, [], ValueType.TYPE_BOOL],
|
|
250
282
|
[MODULES.vote, 'Deadline Locked', 173, [], ValueType.TYPE_BOOL],
|
|
@@ -351,89 +383,6 @@ export class Guard {
|
|
|
351
383
|
return Guard.CommonOptions(ret_type);
|
|
352
384
|
}
|
|
353
385
|
}
|
|
354
|
-
|
|
355
|
-
export class GuardConstantHelper {
|
|
356
|
-
static IsValidIndentifier = (identifier:number) : boolean => {
|
|
357
|
-
if (!IsValidInt(identifier) || identifier > 255) return false;
|
|
358
|
-
return true
|
|
359
|
-
}
|
|
360
|
-
static get_constant_value(constants:GuardConstant, identifier:number, type:ConstantType) : Uint8Array | undefined {
|
|
361
|
-
if (constants.has(identifier)) {
|
|
362
|
-
let v = constants.get(identifier);
|
|
363
|
-
if (v?.value && v.type == type) {
|
|
364
|
-
return v.value;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
static get_constant_witness(constants:GuardConstant, identifier:number) : Uint8Array | undefined {
|
|
369
|
-
if (constants.has(identifier)) {
|
|
370
|
-
let v = constants.get(identifier);
|
|
371
|
-
if (v?.witness && v.type == ContextType.TYPE_WITNESS_ID) {
|
|
372
|
-
return v.witness;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
static add_future_constant(constants:GuardConstant, identifier:number, witness:any, value?:any, bNeedSerialize=true) {
|
|
378
|
-
if (!GuardConstantHelper.IsValidIndentifier(identifier)) ERROR(Errors.IsValidIndentifier, 'add_future_constant');
|
|
379
|
-
if (!witness && !value) ERROR(Errors.InvalidParam, 'both witness and value invalid');
|
|
380
|
-
let v = constants.get(identifier);
|
|
381
|
-
if (!v || v.type == ContextType.TYPE_WITNESS_ID) {
|
|
382
|
-
if (bNeedSerialize) {
|
|
383
|
-
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value ? Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, value) : undefined,
|
|
384
|
-
witness:witness ? Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, witness) : undefined})
|
|
385
|
-
} else {
|
|
386
|
-
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value?value:undefined, witness:witness?witness:undefined});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
static add_constant(constants:GuardConstant, identifier:number, type:ValueType, value:any, bNeedSerialize=true) {
|
|
392
|
-
const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
|
|
393
|
-
if (!GuardConstantHelper.IsValidIndentifier(identifier)) {
|
|
394
|
-
ERROR(Errors.InvalidParam, 'add_constant identifier')
|
|
395
|
-
}
|
|
396
|
-
if (value === undefined) {
|
|
397
|
-
ERROR(Errors.InvalidParam, 'add_constant value')
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
switch (type) {
|
|
401
|
-
case ValueType.TYPE_BOOL:
|
|
402
|
-
case ValueType.TYPE_ADDRESS:
|
|
403
|
-
case ValueType.TYPE_U64:
|
|
404
|
-
case ValueType.TYPE_U8:
|
|
405
|
-
case ValueType.TYPE_U128:
|
|
406
|
-
case ValueType.TYPE_U256:
|
|
407
|
-
case ValueType.TYPE_VEC_U64:
|
|
408
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
409
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
410
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
411
|
-
case ValueType.TYPE_OPTION_U128:
|
|
412
|
-
case ValueType.TYPE_OPTION_U256:
|
|
413
|
-
case ValueType.TYPE_OPTION_U64:
|
|
414
|
-
case ValueType.TYPE_OPTION_U8:
|
|
415
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
416
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
417
|
-
case ValueType.TYPE_VEC_U128:
|
|
418
|
-
case ValueType.TYPE_VEC_U256:
|
|
419
|
-
case ValueType.TYPE_STRING:
|
|
420
|
-
case ValueType.TYPE_VEC_U8:
|
|
421
|
-
case ValueType.TYPE_OPTION_STRING:
|
|
422
|
-
case ValueType.TYPE_OPTION_VEC_U8:
|
|
423
|
-
case ValueType.TYPE_VEC_STRING:
|
|
424
|
-
let ser = SER_VALUE.find(s=>s.type==type);
|
|
425
|
-
if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type:'+e);
|
|
426
|
-
if (bNeedSerialize) {
|
|
427
|
-
constants.set(identifier, {type:type, value:Bcs.getInstance().ser(type, value)})
|
|
428
|
-
} else {
|
|
429
|
-
constants.set(identifier, {type:type, value:value})
|
|
430
|
-
}
|
|
431
|
-
return
|
|
432
|
-
default:
|
|
433
|
-
ERROR(Errors.Fail, 'add_constant serialize not impl yet:'+e)
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
386
|
export class GuardMaker {
|
|
438
387
|
protected data : Uint8Array[] = [];
|
|
439
388
|
protected type_validator : Data_Type[] = [];
|
|
@@ -446,32 +395,27 @@ export class GuardMaker {
|
|
|
446
395
|
}
|
|
447
396
|
return GuardMaker.index++
|
|
448
397
|
}
|
|
449
|
-
|
|
398
|
+
static IsValidIndentifier = (identifier:number) : boolean => {
|
|
399
|
+
if (!IsValidInt(identifier) || identifier > 255) return false;
|
|
400
|
+
return true
|
|
401
|
+
}
|
|
450
402
|
constructor() { }
|
|
451
403
|
|
|
452
|
-
|
|
404
|
+
// undefined value means witness
|
|
405
|
+
add_constant(type:ValueType, value?:any, identifier?:number, bNeedSerialize=true) : number {
|
|
453
406
|
if (identifier === undefined) identifier = GuardMaker.get_index();
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
407
|
+
let v = this.constant.get(identifier);
|
|
408
|
+
if (!v) {
|
|
409
|
+
if (bNeedSerialize && value !== undefined) {
|
|
410
|
+
value = Bcs.getInstance().ser(type, value);
|
|
411
|
+
}
|
|
412
|
+
this.constant.set(identifier, {type:type, value:value===undefined ? undefined:value, bWitness:value===undefined ? true:false});
|
|
413
|
+
}
|
|
460
414
|
return identifier
|
|
461
415
|
}
|
|
462
416
|
|
|
463
|
-
|
|
464
|
-
if (param === undefined) ERROR(Errors.InvalidParam, 'param');
|
|
465
|
-
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
466
|
-
let ser = SER_VALUE.find(s=>s.type==type);
|
|
467
|
-
if (!ser) ERROR(Errors.Fail, 'serValueParam: invalid type');
|
|
468
|
-
this.data.push(Bcs.getInstance().ser(ser!.type as number, param));
|
|
469
|
-
this.type_validator.push(type);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// serialize const & data
|
|
417
|
+
// serialize const & data, WITNESS use constants only.
|
|
473
418
|
add_param(type:ValueType | ContextType, param?:any) : GuardMaker {
|
|
474
|
-
const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
|
|
475
419
|
switch(type) {
|
|
476
420
|
case ValueType.TYPE_ADDRESS:
|
|
477
421
|
case ValueType.TYPE_BOOL:
|
|
@@ -491,12 +435,14 @@ export class GuardMaker {
|
|
|
491
435
|
case ValueType.TYPE_OPTION_U256:
|
|
492
436
|
case ValueType.TYPE_OPTION_U8:
|
|
493
437
|
case ValueType.TYPE_VEC_U256:
|
|
494
|
-
this.
|
|
438
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
439
|
+
this.data.push(Bcs.getInstance().ser(type as number, param));
|
|
440
|
+
this.type_validator.push(type);
|
|
495
441
|
break;
|
|
496
442
|
case ValueType.TYPE_STRING:
|
|
497
443
|
case ValueType.TYPE_VEC_U8:
|
|
498
|
-
if (!param) ERROR(Errors.InvalidParam, 'param:'+
|
|
499
|
-
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
444
|
+
if (!param) ERROR(Errors.InvalidParam, 'param: ' + type);
|
|
445
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
500
446
|
if (typeof(param) == 'string') {
|
|
501
447
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_STRING, param));
|
|
502
448
|
} else {
|
|
@@ -512,45 +458,32 @@ export class GuardMaker {
|
|
|
512
458
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
513
459
|
this.type_validator.push(ValueType.TYPE_U64);
|
|
514
460
|
break;
|
|
515
|
-
case ContextType.TYPE_WITNESS_ID:
|
|
516
|
-
if (!param) ERROR(Errors.InvalidParam, 'param:'+e);
|
|
517
|
-
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
|
|
518
|
-
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, param));
|
|
519
|
-
this.type_validator.push(ValueType.TYPE_ADDRESS);
|
|
520
|
-
break;
|
|
521
461
|
case ContextType.TYPE_CONSTANT:
|
|
522
|
-
if (!param) {
|
|
523
|
-
ERROR(Errors.InvalidParam, 'param invalid:'+e);
|
|
524
|
-
}
|
|
525
|
-
if (typeof(param) != 'number' || !IsValidInt(param) || param > 255) {
|
|
462
|
+
if (typeof(param) !== 'number' || !IsValidInt(param) || param > 255) {
|
|
526
463
|
ERROR(Errors.InvalidParam, 'add_param param:'+type);
|
|
527
464
|
}
|
|
528
465
|
|
|
529
466
|
var v = this.constant.get(param);
|
|
530
|
-
if (!v) ERROR(Errors.Fail, 'identifier not in constant:'+
|
|
531
|
-
|
|
532
|
-
if (v?.type === ContextType.TYPE_WITNESS_ID) {
|
|
533
|
-
t = ValueType.TYPE_ADDRESS;
|
|
534
|
-
}
|
|
535
|
-
this.type_validator.push(t); //@ type validator convert
|
|
467
|
+
if (!v) ERROR(Errors.Fail, 'identifier not in constant:'+param);
|
|
468
|
+
this.type_validator.push(v!.type); //@ type validator convert
|
|
536
469
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // constant flag
|
|
537
470
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param)); // identifier
|
|
538
471
|
break;
|
|
539
472
|
default:
|
|
540
|
-
ERROR(Errors.InvalidParam, 'add_param type:'+
|
|
473
|
+
ERROR(Errors.InvalidParam, 'add_param type:'+type);
|
|
541
474
|
};
|
|
542
475
|
return this;
|
|
543
476
|
}
|
|
544
477
|
|
|
545
478
|
// object_address_from: string for static address; number as identifier inconstant
|
|
546
|
-
add_query(module:MODULES, query_name:string, object_address_from:string | number
|
|
479
|
+
add_query(module:MODULES, query_name:string, object_address_from:string | number) : GuardMaker {
|
|
547
480
|
let query_index = Guard.QUERIES.findIndex((q) => { return q[0] == module && q[1] == query_name})
|
|
548
481
|
if (query_index == -1) {
|
|
549
482
|
ERROR(Errors.InvalidParam, 'query_name:'+query_name);
|
|
550
483
|
}
|
|
551
484
|
|
|
552
485
|
if (typeof(object_address_from) == 'number' ) {
|
|
553
|
-
if (!
|
|
486
|
+
if (!GuardMaker.IsValidIndentifier(object_address_from)) {
|
|
554
487
|
ERROR(Errors.InvalidParam, 'object_address_from:'+query_name);
|
|
555
488
|
}
|
|
556
489
|
} else {
|
|
@@ -571,13 +504,12 @@ export class GuardMaker {
|
|
|
571
504
|
|
|
572
505
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE
|
|
573
506
|
if (typeof(object_address_from) == 'string') {
|
|
574
|
-
|
|
575
|
-
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ValueType.TYPE_ADDRESS));
|
|
507
|
+
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ValueType.TYPE_ADDRESS));
|
|
576
508
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, object_address_from)); // object address
|
|
577
509
|
} else {
|
|
578
510
|
let v = this.constant.get(object_address_from);
|
|
579
511
|
if (!v) ERROR(Errors.Fail, 'object_address_from not in constant:'+query_name);
|
|
580
|
-
if (
|
|
512
|
+
if (v?.type == ValueType.TYPE_ADDRESS) {
|
|
581
513
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
|
|
582
514
|
this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, object_address_from)); // object identifer in constants
|
|
583
515
|
} else {
|
|
@@ -694,13 +626,13 @@ export class GuardMaker {
|
|
|
694
626
|
if (!otherBuilt.IsReady() || !this.IsReady()) { ERROR(Errors.Fail, 'both should built yet')};
|
|
695
627
|
let maker = new GuardMaker();
|
|
696
628
|
this.constant.forEach((v, k) => {
|
|
697
|
-
maker.constant.set(k, {type:v.type, value:v.value,
|
|
629
|
+
maker.constant.set(k, {type:v.type, value:v.value, bWitness:v.bWitness});
|
|
698
630
|
})
|
|
699
631
|
otherBuilt.constant.forEach((v, k) => {
|
|
700
632
|
if (maker.constant.has(k) && !bCombinConstant) {
|
|
701
633
|
ERROR(Errors.Fail, 'constant identifier exist');
|
|
702
634
|
}
|
|
703
|
-
maker.constant.set(k, {type:v.type, value:v.value,
|
|
635
|
+
maker.constant.set(k, {type:v.type, value:v.value, bWitness:v.bWitness});
|
|
704
636
|
})
|
|
705
637
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
706
638
|
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op), Bcs.getInstance().ser(ValueType.TYPE_U8, 2)));
|