wowok 1.1.1 → 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/src/guard.ts CHANGED
@@ -5,139 +5,34 @@ import { concatenate, array_equal } from './utils';
5
5
  import { IsValidDesription, Bcs, IsValidInt, IsValidAddress } from './utils';
6
6
  import { ERROR, Errors } from './exception';
7
7
 
8
- export enum Guard_Sense_Binder {
9
- AND = 0, // first sense of guard always AND; for combining other guards
10
- OR = 1,
11
- }
12
-
13
- export type Guard_Sense = {
14
- input: Uint8Array;
15
- notAfterSense: boolean;
16
- binder:Guard_Sense_Binder ;
17
- };
18
8
  export type VariableType = Map<number, Guard_Vriable>;
19
9
 
20
- export type Guard_Vriable = {
10
+ export interface Guard_Vriable {
21
11
  type: ContextType | OperatorType,
22
12
  value?: Uint8Array,
23
13
  witness?: Uint8Array,
24
14
  }
15
+
25
16
  export type Guard_Creation = {
26
17
  description: string;
27
18
  variables?: VariableType;
28
- senses: Guard_Sense[];
19
+ input: Uint8Array;
29
20
  }
30
21
 
31
22
  export class Guard {
32
- static MAX_SENSE_COUNT = 16;
33
- static IsValidGuardVirableType = (type:OperatorType | ContextType) : boolean => {
34
- if (type == OperatorType.TYPE_FUTURE_QUERY || type == ContextType.TYPE_CONTEXT_FUTURE_ID || type == OperatorType.TYPE_QUERY_FROM_CONTEXT ||
35
- type == ContextType.TYPE_CONTEXT_bool || type ==ContextType.TYPE_CONTEXT_address || type == ContextType.TYPE_CONTEXT_u64 ||
36
- type == ContextType.TYPE_CONTEXT_u8 || type == ContextType.TYPE_CONTEXT_vec_u8) {
37
- return true;
38
- };
39
- return false;
40
- }
41
- static IsValidIndentifier = (identifier:number) : boolean => {
42
- if (!IsValidInt(identifier) || identifier > 255) return false;
43
- return true
44
- }
45
- static get_variable_value(variables:VariableType, identifier:number, type:OperatorType | ContextType) : Uint8Array | boolean {
46
- if (variables.has(identifier)) {
47
- let v = variables.get(identifier);
48
- if (v?.value && v.type == type) {
49
- return v.value;
50
- }
51
- } return false;
52
- }
53
- static get_variable_witness(variables:VariableType, identifier:number, type:OperatorType | ContextType) : Uint8Array | boolean {
54
- if (variables.has(identifier)) {
55
- let v = variables.get(identifier);
56
- if (v?.witness && v.type == type) {
57
- return v.witness;
58
- }
59
- } return false;
60
- }
61
-
62
- static add_future_variable(variables:VariableType, identifier:number, type:OperatorType | ContextType,
63
- witness:any, value?:any, bNeedSerialize=true) : boolean {
64
- if (!Guard.IsValidIndentifier(identifier)) return false;
65
- if (!Guard.IsValidGuardVirableType(type)) return false;
66
- if (!witness && !value) return false;
67
-
68
- switch (type) {
69
- case OperatorType.TYPE_FUTURE_QUERY :
70
- case ContextType.TYPE_CONTEXT_FUTURE_ID :
71
- if (variables.has(identifier)) {
72
- let v = (variables.get(identifier) as Guard_Vriable);
73
- if (bNeedSerialize) {
74
- v.value = value ? Bcs.getInstance().ser_address(value) : undefined;
75
- v.witness = witness ? Bcs.getInstance().ser_address(witness) : undefined;
76
- } else {
77
- v.value = value ? value : undefined;
78
- v.witness = witness ? witness : undefined;
79
- }
80
- } else {
81
- if (bNeedSerialize) {
82
- variables.set(identifier, {type:type, value:value ? Bcs.getInstance().ser_address(value) : undefined, witness:witness ? Bcs.getInstance().ser_address(witness) : undefined})
83
- } else {
84
- variables.set(identifier, {type:type, value:value?value:undefined, witness:witness?witness:undefined});
85
- }
86
- }
87
- return true;
88
- }
89
- return false;
90
- }
91
-
92
- static add_variable(variables:VariableType, identifier:number, type:OperatorType | ContextType,
93
- value:any, bNeedSerialize=true) : boolean {
94
- if (!Guard.IsValidIndentifier(identifier)) return false;
95
- if (!Guard.IsValidGuardVirableType(type)) return false;
96
- if (!value) return false;
97
-
98
- switch (type) {
99
- case ContextType.TYPE_CONTEXT_bool:
100
- bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_bool(value)}) :
101
- variables.set(identifier, {type:type, value:value})
102
- return true;
103
- case ContextType.TYPE_CONTEXT_address:
104
- case OperatorType.TYPE_QUERY_FROM_CONTEXT:
105
- bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_address(value)}):
106
- variables.set(identifier, {type:type, value:value});
107
- return true;
108
- case ContextType.TYPE_CONTEXT_u64:
109
- bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_u64(value)}) :
110
- variables.set(identifier, {type:type, value:value})
111
- return true;
112
- case ContextType.TYPE_CONTEXT_u8:
113
- bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_u8(value)}) :
114
- variables.set(identifier, {type:type, value:value})
115
- return true;
116
- case ContextType.TYPE_CONTEXT_vec_u8:
117
- bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_string(value)}) :
118
- variables.set(identifier, {type:type, value:value})
119
- return true;
120
- }
121
- return false;
122
- }
23
+ static MAX_INPUT_LENGTH = 2048;
123
24
  static launch(protocol:Protocol, creation:Guard_Creation) : GuardAddress {
124
25
  if (!IsValidDesription(creation.description)) {
125
26
  ERROR(Errors.IsValidDesription)
126
27
  }
127
- if (creation.senses.length == 0 || creation.senses.length > Guard.MAX_SENSE_COUNT) {
128
- ERROR(Errors.InvalidParam, 'creation.senses')
28
+ if (creation.input.length == 0 || creation.input.length > Guard.MAX_INPUT_LENGTH) {
29
+ ERROR(Errors.InvalidParam, 'creation.input')
129
30
  }
130
31
 
131
32
  let bValid = true;
132
- creation.senses.forEach((v) => {
133
- if (!v.input || v.input.length == 0) bValid = false;
134
- })
135
- if (!bValid) {
136
- ERROR(Errors.InvalidParam, 'creation.senses')
137
- }
138
33
  creation?.variables?.forEach((v, k) => {
139
- if (!Guard.IsValidIndentifier(k)) bValid = false;
140
- if (!Guard.IsValidGuardVirableType(v.type)) bValid = false;
34
+ if (!GuardVariableMaker.IsValidIndentifier(k)) bValid = false;
35
+ if (!GuardVariableMaker.IsValidGuardVirableType(v.type)) bValid = false;
141
36
  if (!v.value && !v.witness) bValid = false;
142
37
  })
143
38
  if (!bValid) {
@@ -145,19 +40,14 @@ export class Guard {
145
40
  }
146
41
 
147
42
  let txb = protocol.CurrentSession();
43
+ let input = new Uint8Array(creation.input); // copy new uint8array to reserve!
44
+
45
+ // reserve the bytes for guard
148
46
  let guard = txb.moveCall({
149
47
  target: protocol.GuardFn('new') as FnCallType,
150
- arguments: [txb.pure(creation.description , BCS.STRING)],
151
- });
152
- creation.senses.forEach((sense: Guard_Sense) => {
153
- txb.moveCall({
154
- target: protocol.GuardFn('sense_add') as FnCallType,
155
- arguments:[guard, txb.pure([].slice.call(sense.input)),
156
- txb.pure(sense.notAfterSense, BCS.BOOL),
157
- txb.pure(sense.binder, BCS.U8),
158
- ]
159
- })
48
+ arguments: [txb.pure(creation.description , BCS.STRING), txb.pure([].slice.call(input.reverse()))],
160
49
  });
50
+
161
51
  creation?.variables?.forEach((v, k) => {
162
52
  if (v.type == OperatorType.TYPE_FUTURE_QUERY || v.type == ContextType.TYPE_CONTEXT_FUTURE_ID) {
163
53
  if (!v.witness) {
@@ -222,7 +112,9 @@ export class Guard {
222
112
  [MODULES.repository, 'value', 9, [ValueType.TYPE_STATIC_address, ValueType.TYPE_STATIC_vec_u8], ValueType.TYPE_STATIC_vec_u8],
223
113
  [MODULES.repository, 'type', 10, [], ValueType.TYPE_STATIC_u8],
224
114
  [MODULES.repository, 'policy_mode', 11, [], ValueType.TYPE_STATIC_u8],
225
-
115
+ [MODULES.repository, 'reference_count', 12, [], ValueType.TYPE_STATIC_u64],
116
+ [MODULES.repository, 'has_reference', 13, [ValueType.TYPE_STATIC_address], ValueType.TYPE_STATIC_bool],
117
+
226
118
  [MODULES.machine, 'permission', 1, [], ValueType.TYPE_STATIC_address],
227
119
  [MODULES.machine, 'has_paused', 2, [], ValueType.TYPE_STATIC_bool],
228
120
  [MODULES.machine, 'has_published', 3, [], ValueType.TYPE_STATIC_bool],
@@ -350,40 +242,132 @@ export const graphql_query_objects = (protocol: Protocol, nodes:any) : Guard_Que
350
242
  return ret
351
243
  } */
352
244
 
353
- export class SenseMaker {
245
+ export class GuardVariableMaker {
246
+ static IsValidGuardVirableType = (type:OperatorType | ContextType) : boolean => {
247
+ if (type == OperatorType.TYPE_FUTURE_QUERY || type == ContextType.TYPE_CONTEXT_FUTURE_ID || type == OperatorType.TYPE_QUERY_FROM_CONTEXT ||
248
+ type == ContextType.TYPE_CONTEXT_bool || type ==ContextType.TYPE_CONTEXT_address || type == ContextType.TYPE_CONTEXT_u64 ||
249
+ type == ContextType.TYPE_CONTEXT_u8 || type == ContextType.TYPE_CONTEXT_vec_u8) {
250
+ return true;
251
+ };
252
+ return false;
253
+ }
254
+ static IsValidIndentifier = (identifier:number) : boolean => {
255
+ if (!IsValidInt(identifier) || identifier > 255) return false;
256
+ return true
257
+ }
258
+ static get_variable_value(variables:VariableType, identifier:number, type:OperatorType | ContextType) : Uint8Array | boolean {
259
+ if (variables.has(identifier)) {
260
+ let v = variables.get(identifier);
261
+ if (v?.value && v.type == type) {
262
+ return v.value;
263
+ }
264
+ } return false;
265
+ }
266
+ static get_variable_witness(variables:VariableType, identifier:number, type:OperatorType | ContextType) : Uint8Array | boolean {
267
+ if (variables.has(identifier)) {
268
+ let v = variables.get(identifier);
269
+ if (v?.witness && v.type == type) {
270
+ return v.witness;
271
+ }
272
+ } return false;
273
+ }
274
+
275
+ static add_future_variable(variables:VariableType, identifier:number, type:OperatorType | ContextType,
276
+ witness:any, value?:any, bNeedSerialize=true) : boolean {
277
+ if (!GuardVariableMaker.IsValidIndentifier(identifier)) return false;
278
+ if (!GuardVariableMaker.IsValidGuardVirableType(type)) return false;
279
+ if (!witness && !value) return false;
280
+
281
+ switch (type) {
282
+ case OperatorType.TYPE_FUTURE_QUERY :
283
+ case ContextType.TYPE_CONTEXT_FUTURE_ID :
284
+ if (variables.has(identifier)) {
285
+ let v = (variables.get(identifier) as Guard_Vriable);
286
+ if (bNeedSerialize) {
287
+ v.value = value ? Bcs.getInstance().ser_address(value) : undefined;
288
+ v.witness = witness ? Bcs.getInstance().ser_address(witness) : undefined;
289
+ } else {
290
+ v.value = value ? value : undefined;
291
+ v.witness = witness ? witness : undefined;
292
+ }
293
+ } else {
294
+ if (bNeedSerialize) {
295
+ variables.set(identifier, {type:type, value:value ? Bcs.getInstance().ser_address(value) : undefined, witness:witness ? Bcs.getInstance().ser_address(witness) : undefined})
296
+ } else {
297
+ variables.set(identifier, {type:type, value:value?value:undefined, witness:witness?witness:undefined});
298
+ }
299
+ }
300
+ return true;
301
+ }
302
+ return false;
303
+ }
304
+
305
+ static add_variable(variables:VariableType, identifier:number, type:OperatorType | ContextType,
306
+ value:any, bNeedSerialize=true) : boolean {
307
+ if (!GuardVariableMaker.IsValidIndentifier(identifier)) return false;
308
+ if (!GuardVariableMaker.IsValidGuardVirableType(type)) return false;
309
+ if (!value) return false;
310
+
311
+ switch (type) {
312
+ case ContextType.TYPE_CONTEXT_bool:
313
+ bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_bool(value)}) :
314
+ variables.set(identifier, {type:type, value:value})
315
+ return true;
316
+ case ContextType.TYPE_CONTEXT_address:
317
+ case OperatorType.TYPE_QUERY_FROM_CONTEXT:
318
+ bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_address(value)}):
319
+ variables.set(identifier, {type:type, value:value});
320
+ return true;
321
+ case ContextType.TYPE_CONTEXT_u64:
322
+ bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_u64(value)}) :
323
+ variables.set(identifier, {type:type, value:value})
324
+ return true;
325
+ case ContextType.TYPE_CONTEXT_u8:
326
+ bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_u8(value)}) :
327
+ variables.set(identifier, {type:type, value:value})
328
+ return true;
329
+ case ContextType.TYPE_CONTEXT_vec_u8:
330
+ bNeedSerialize ? variables.set(identifier, {type:type, value:Bcs.getInstance().ser_string(value)}) :
331
+ variables.set(identifier, {type:type, value:value})
332
+ return true;
333
+ }
334
+ return false;
335
+ }
336
+ }
337
+ export class GuardInputMaker {
354
338
  protected data : Uint8Array[] = [];
355
339
  protected type_validator : Data_Type[] = [];
356
340
  constructor() { }
357
341
 
358
342
  // serialize const & data
359
- add_param(type:ValueType | ContextType, param?:any, variable?:VariableType) : boolean {
343
+ add_param(type:ValueType | ContextType, param?:any, variable?:VariableType) {
360
344
  switch(type) {
361
345
  case ValueType.TYPE_STATIC_address:
362
- if (!param) return false
346
+ if (!param) ERROR(Errors.InvalidParam, 'param');
363
347
  this.data.push(Bcs.getInstance().ser_u8(type));
364
348
  this.data.push(Bcs.getInstance().ser_address(param));
365
349
  this.type_validator.push(type);
366
350
  break;
367
351
  case ValueType.TYPE_STATIC_bool:
368
- if (!param) return false
352
+ if (!param) ERROR(Errors.InvalidParam, 'param');
369
353
  this.data.push(Bcs.getInstance().ser_u8(type));
370
354
  this.data.push(Bcs.getInstance().ser_bool(param));
371
355
  this.type_validator.push(type);
372
356
  break;
373
357
  case ValueType.TYPE_STATIC_u8:
374
- if (!param) return false
358
+ if (!param) ERROR(Errors.InvalidParam, 'param');
375
359
  this.data.push(Bcs.getInstance().ser_u8(type));
376
360
  this.data.push(Bcs.getInstance().ser_u8(param));
377
361
  this.type_validator.push(type);
378
362
  break;
379
363
  case ValueType.TYPE_STATIC_u64:
380
- if (!param) return false
364
+ if (!param) ERROR(Errors.InvalidParam, 'param');
381
365
  this.data.push(Bcs.getInstance().ser_u8(type));
382
366
  this.data.push(Bcs.getInstance().ser_u64(param));
383
367
  this.type_validator.push(type);
384
368
  break;
385
369
  case ValueType.TYPE_STATIC_vec_u8:
386
- if (!param) return false
370
+ if (!param) ERROR(Errors.InvalidParam, 'param');
387
371
  this.data.push(Bcs.getInstance().ser_u8(type));
388
372
  this.data.push(Bcs.getInstance().ser_string(param));
389
373
  this.type_validator.push(type);
@@ -403,11 +387,14 @@ export class SenseMaker {
403
387
  case ContextType.TYPE_CONTEXT_vec_u8:
404
388
  case ContextType.TYPE_CONTEXT_address:
405
389
  case ContextType.TYPE_CONTEXT_FUTURE_ID:
406
- if (!variable || !param) return false;
407
- if (typeof(param) != 'number') return false;
408
- if (!IsValidInt(param) || param > 255) return false;
390
+ if (!variable || !param) {
391
+ ERROR(Errors.InvalidParam, 'variable or param');
392
+ }
393
+ if (typeof(param) != 'number' || !IsValidInt(param) || param > 255) {
394
+ ERROR(Errors.InvalidParam, 'param');
395
+ }
409
396
 
410
- var v = variable.get(param);
397
+ var v = variable!.get(param);
411
398
  if (v?.type == type) {
412
399
  this.data.push(Bcs.getInstance().ser_u8(type));
413
400
  this.data.push(Bcs.getInstance().ser_u8(param));
@@ -426,12 +413,10 @@ export class SenseMaker {
426
413
  }
427
414
  break;
428
415
  };
429
- return false;
416
+ ERROR(Errors.InvalidParam, 'variable');
430
417
  default:
431
- return false;
418
+ ERROR(Errors.InvalidParam, 'type');
432
419
  };
433
-
434
- return true;
435
420
  }
436
421
  static query_index(module:MODULES, query_name:string) : number {
437
422
  for (let i = 0; i < Guard.QUERIES.length; i++) {
@@ -441,20 +426,26 @@ export class SenseMaker {
441
426
  }
442
427
  return -1;
443
428
  }
444
- add_future_query(identifier:number, module:MODULES, query_name:string, variable:VariableType) : boolean {
445
- let query_index = SenseMaker.query_index(module, query_name);
446
- if (!Guard.IsValidIndentifier(identifier) || query_index == -1) return false;
447
- if (module != MODULES.order && module != MODULES.progress) return false;
448
- if (!variable || variable.get(identifier)?.type != OperatorType.TYPE_FUTURE_QUERY) return false;
429
+ add_future_query(identifier:number, module:MODULES, query_name:string, variable:VariableType) {
430
+ let query_index = GuardInputMaker.query_index(module, query_name);
431
+ if (!GuardVariableMaker.IsValidIndentifier(identifier) || query_index == -1) {
432
+ ERROR(Errors.InvalidParam, 'identifier or query_name');
433
+ }
434
+ if (module != MODULES.order && module != MODULES.progress){
435
+ ERROR(Errors.InvalidParam, 'module');
436
+ }
437
+ if (!variable || variable.get(identifier)?.type != OperatorType.TYPE_FUTURE_QUERY) {
438
+ ERROR(Errors.InvalidParam, 'variable');
439
+ }
449
440
 
450
441
  let offset = this.type_validator.length - Guard.QUERIES[query_index][3].length;
451
442
  if (offset < 0) {
452
- return false;
443
+ ERROR(Errors.InvalidParam, 'query_name');
453
444
  }
454
445
 
455
446
  let types = this.type_validator.slice(offset);
456
447
  if (!array_equal(types, Guard.QUERIES[query_index][3])) { // type validate
457
- return false;
448
+ ERROR(Errors.Fail, 'array_equal');
458
449
  }
459
450
 
460
451
  this.data.push(Bcs.getInstance().ser_u8(OperatorType.TYPE_FUTURE_QUERY)); // TYPE
@@ -464,27 +455,32 @@ export class SenseMaker {
464
455
  this.type_validator.splice(offset, Guard.QUERIES[query_index][3].length); // delete type stack
465
456
  this.type_validator.push(Guard.QUERIES[query_index][4]); // add the return value type to type stack
466
457
  // console.log(this.type_validator)
467
- return true;
468
458
  }
469
459
 
470
460
  // object_address_from: string for static address; number as identifier for variable
471
- add_query(module:MODULES, query_name:string, object_address_from:string | number) : boolean {
472
- let query_index = SenseMaker.query_index(module, query_name); // query_index: index(from 0) of array Guard.QUERIES
473
- if (query_index == -1) return false;
461
+ add_query(module:MODULES, query_name:string, object_address_from:string | number) {
462
+ let query_index = GuardInputMaker.query_index(module, query_name); // query_index: index(from 0) of array Guard.QUERIES
463
+ if (query_index == -1) {
464
+ ERROR(Errors.InvalidParam, 'query_name');
465
+ }
474
466
  if (typeof(object_address_from) == 'number') {
475
- if (!Guard.IsValidIndentifier(object_address_from)) return false;
467
+ if (!GuardVariableMaker.IsValidIndentifier(object_address_from)) {
468
+ ERROR(Errors.InvalidParam, 'object_address_from');
469
+ }
476
470
  } else {
477
- if (!IsValidAddress(object_address_from)) return false;
471
+ if (!IsValidAddress(object_address_from)) {
472
+ ERROR(Errors.InvalidParam, 'object_address_from');
473
+ }
478
474
  }
479
475
 
480
476
  let offset = this.type_validator.length - Guard.QUERIES[query_index][3].length;
481
477
  if (offset < 0) {
482
- return false;
478
+ ERROR(Errors.InvalidParam, 'query_name');
483
479
  }
484
480
 
485
481
  let types = this.type_validator.slice(offset);
486
482
  if (!array_equal(types, Guard.QUERIES[query_index][3])) { // type validate
487
- return false;
483
+ ERROR(Errors.Fail, 'array_equal');
488
484
  }
489
485
 
490
486
  if (typeof(object_address_from) == 'string') {
@@ -500,44 +496,64 @@ export class SenseMaker {
500
496
  this.type_validator.splice(offset, Guard.QUERIES[query_index][3].length); // delete type stack
501
497
  this.type_validator.push(Guard.QUERIES[query_index][4]); // add the return value type to type stack
502
498
  // console.log(this.type_validator)
503
- return true;
504
499
  }
505
500
 
506
- add_logic(type:OperatorType) : boolean {
501
+ add_logic(type:OperatorType) {
502
+ let splice_len = 2;
507
503
  switch (type) {
508
504
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
509
505
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
510
506
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
511
507
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
512
508
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
513
- if (this.type_validator.length < 2) { return false; }
514
- if (!SenseMaker.match_u128(this.type_validator[this.type_validator.length - 1])) { return false; }
515
- if (!SenseMaker.match_u128(this.type_validator[this.type_validator.length - 2])) { return false; }
509
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
510
+ if (!GuardInputMaker.match_u128(this.type_validator[this.type_validator.length - 1])) { ERROR(Errors.Fail, 'type_validator check') }
511
+ if (!GuardInputMaker.match_u128(this.type_validator[this.type_validator.length - 2])) { ERROR(Errors.Fail, 'type_validator check') }
516
512
  break;
517
513
  case OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
514
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
515
+ break;
518
516
  case OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
519
- if (this.type_validator.length < 2) { return false; }
517
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
518
+ break;
519
+ case OperatorType.TYPE_LOGIC_NOT:
520
+ splice_len = 1;
521
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
522
+ if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_STATIC_bool) { ERROR(Errors.Fail, 'type_validator check') }
523
+ break;
524
+ case OperatorType.TYPE_LOGIC_AND:
525
+ case OperatorType.TYPE_LOGIC_OR:
526
+ if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length') }
527
+ if (this.type_validator[this.type_validator.length -1] != ValueType.TYPE_STATIC_bool) { ERROR(Errors.Fail, 'type_validator check') }
528
+ if (this.type_validator[this.type_validator.length -2] != ValueType.TYPE_STATIC_bool) { ERROR(Errors.Fail, 'type_validator check') }
520
529
  break;
521
530
  default:
522
- return false;
531
+ ERROR(Errors.InvalidParam, 'type')
523
532
  }
524
533
  this.data.push(Bcs.getInstance().ser_u8(type)); // TYPE
525
- this.type_validator.splice(this.type_validator.length - 2); // delete type stack
534
+ this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
526
535
  this.type_validator.push(ValueType.TYPE_STATIC_bool); // add bool to type stack
527
- return true;
528
536
  }
529
537
 
530
- make(bNotAfterSense:boolean = false, binder:Guard_Sense_Binder = Guard_Sense_Binder.AND) : boolean | Guard_Sense {
538
+ make(bNot = false) : Uint8Array {
531
539
  //console.log(this.type_validator);
532
540
  //this.data.forEach((value:Uint8Array) => console.log(value));
533
541
  if (this.type_validator.length != 1 || this.type_validator[0] != ValueType.TYPE_STATIC_bool) {
534
542
  console.log(this.type_validator)
535
- return false;
543
+ ERROR(Errors.Fail, 'type_validator check')
536
544
  } // ERROR
545
+ if (bNot) {
546
+ this.add_logic(OperatorType.TYPE_LOGIC_NOT);
547
+ }
548
+ return concatenate(Uint8Array, ...this.data) as Uint8Array;
549
+ }
537
550
 
538
- let input = concatenate(Uint8Array, ...this.data) as Uint8Array;
539
- const sense:Guard_Sense = {input:input, notAfterSense:bNotAfterSense, binder:binder};
540
- return sense;
551
+ static combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
552
+ let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
553
+ return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser_u8(op)) as Uint8Array;
554
+ }
555
+ static not(input:Uint8Array) : Uint8Array {
556
+ return concatenate(Uint8Array, input, Bcs.getInstance().ser_u8(OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
541
557
  }
542
558
 
543
559
  static match_u128(type:number) : boolean {
package/src/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from './protocol'
10
10
  export * from './passport'
11
11
  export * from './machine'
12
12
  export * from './service'
13
+ export * from './graphql'
package/src/machine.ts CHANGED
@@ -9,19 +9,19 @@ import { Errors, ERROR} from './exception'
9
9
 
10
10
  export type MachineNodeObject = TransactionResult | String;
11
11
 
12
- export type Machine_Forward = {
12
+ export interface Machine_Forward {
13
13
  name: string; // foward name
14
14
  namedOperator?: string; // dynamic operator
15
15
  permission?: PermissionIndexType; // this.permission-index or named-operator MUST one defined.
16
16
  weight?: number;
17
17
  guard?: GuardObject;
18
18
  }
19
- export type Machine_Node_Pair = {
19
+ export interface Machine_Node_Pair {
20
20
  prior_node: string;
21
21
  forwards: Machine_Forward[];
22
22
  threshold?: number;
23
23
  }
24
- export type Machine_Node = {
24
+ export interface Machine_Node {
25
25
  name: string;
26
26
  description: string;
27
27
  pairs: Machine_Node_Pair[];