wowok 1.0.6 → 1.0.8

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
@@ -2,9 +2,11 @@ import { SuiObjectResponse, SuiObjectDataOptions, SuiParsedData } from '@mysten/
2
2
  import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
3
3
  import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
4
4
  import { PROTOCOL, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, OBJECTS_TYPE,
5
- OBJECTS_TYPE_PREFIX, Query_Param, IsValidDesription, ValueType, OperatorType} from './protocol';
5
+ OBJECTS_TYPE_PREFIX, Query_Param, IsValidDesription, ValueType, OperatorType,
6
+ IsValidInt,
7
+ IsValidAddress} from './protocol';
6
8
  import { concatenate, array_equal, ulebDecode, array_unique } from './utils';
7
- import { stringToUint8Array } from './utils';
9
+ import { stringToUint8Array, BCS_CONVERT } from './utils';
8
10
 
9
11
 
10
12
  export const MAX_SENSE_COUNT = 16;
@@ -19,19 +21,145 @@ export type Guard_Sense = {
19
21
  notAfterSense: boolean;
20
22
  binder:Guard_Sense_Binder ;
21
23
  };
24
+ export type VariableType = Map<number, Guard_Vriable>;
22
25
 
26
+ export type Guard_Vriable = {
27
+ type: ContextType | OperatorType,
28
+ value?: Uint8Array,
29
+ witness?: Uint8Array,
30
+ }
23
31
  export type Guard_Creation = {
24
32
  description: string;
33
+ variables?: VariableType;
25
34
  senses: Guard_Sense[];
26
35
  }
27
36
 
37
+ // de sense bsc => FutureValueRequest
38
+ export type FutureValueRequest = {
39
+ guardid: string;
40
+ identifier: number;
41
+ type: ContextType | OperatorType,
42
+ witness: string,
43
+ value?: string, // future object address
44
+ }
45
+
46
+
47
+ export const IsValidGuardVirableType = (type:OperatorType | ContextType) : boolean => {
48
+ if (type == OperatorType.TYPE_FUTURE_QUERY || type == ContextType.TYPE_CONTEXT_FUTURE_ID || type == OperatorType.TYPE_QUERY_FROM_CONTEXT ||
49
+ type == ContextType.TYPE_CONTEXT_bool || type ==ContextType.TYPE_CONTEXT_address || type == ContextType.TYPE_CONTEXT_u64 ||
50
+ type == ContextType.TYPE_CONTEXT_u8 || type == ContextType.TYPE_CONTEXT_vec_u8) {
51
+ return true;
52
+ };
53
+ return false;
54
+ }
55
+ export const IsValidIndentifier = (identifier:number) : boolean => {
56
+ if (!IsValidInt(identifier) || identifier > 255) return false;
57
+ return true
58
+ }
59
+ /*
60
+ // called by de-guard or passport
61
+ export function set_futrue_value(variables:VariableType, identifier:number, type:OperatorType | ContextType, value?:any) : boolean {
62
+ if (!IsValidIndentifier(identifier)) return false;
63
+ if (!IsValidGuardVirableType(type)) return false;
64
+ let v = variables.get(identifier);
65
+ if (v) {
66
+ v.value = BCS_CONVERT.ser_address(value);
67
+ return true;
68
+ }
69
+ return false;
70
+ } */
71
+ export function get_variable_value(variables:VariableType, identifier:number, type:OperatorType | ContextType) : Uint8Array | boolean {
72
+ if (variables.has(identifier)) {
73
+ let v = variables.get(identifier);
74
+ if (v?.value && v.type == type) {
75
+ return v.value;
76
+ }
77
+ } return false;
78
+ }
79
+ export function get_variable_witness(variables:VariableType, identifier:number, type:OperatorType | ContextType) : Uint8Array | boolean {
80
+ if (variables.has(identifier)) {
81
+ let v = variables.get(identifier);
82
+ if (v?.witness && v.type == type) {
83
+ return v.witness;
84
+ }
85
+ } return false;
86
+ }
87
+
88
+ export function add_future_variable(variables:VariableType, identifier:number, type:OperatorType | ContextType,
89
+ witness:any, value?:any, bNeedSerialize=true) : boolean {
90
+ if (!IsValidIndentifier(identifier)) return false;
91
+ if (!IsValidGuardVirableType(type)) return false;
92
+ if (!witness && !value) return false;
93
+
94
+ switch (type) {
95
+ case OperatorType.TYPE_FUTURE_QUERY :
96
+ case ContextType.TYPE_CONTEXT_FUTURE_ID :
97
+ if (variables.has(identifier)) {
98
+ let v = (variables.get(identifier) as Guard_Vriable);
99
+ if (bNeedSerialize) {
100
+ v.value = value ? BCS_CONVERT.ser_address(value) : undefined;
101
+ v.witness = witness ? BCS_CONVERT.ser_address(witness) : undefined;
102
+ } else {
103
+ v.value = value ? value : undefined;
104
+ v.witness = witness ? witness : undefined;
105
+ }
106
+ } else {
107
+ if (bNeedSerialize) {
108
+ variables.set(identifier, {type:type, value:value ? BCS_CONVERT.ser_address(value) : undefined, witness:witness ? BCS_CONVERT.ser_address(witness) : undefined})
109
+ } else {
110
+ variables.set(identifier, {type:type, value:value?value:undefined, witness:witness?witness:undefined});
111
+ }
112
+ }
113
+ return true;
114
+ }
115
+ return false;
116
+ }
117
+
118
+ export function add_variable(variables:VariableType, identifier:number, type:OperatorType | ContextType,
119
+ value:any, bNeedSerialize=true) : boolean {
120
+ if (!IsValidIndentifier(identifier)) return false;
121
+ if (!IsValidGuardVirableType(type)) return false;
122
+ if (!value) return false;
123
+
124
+ switch (type) {
125
+ case ContextType.TYPE_CONTEXT_bool:
126
+ bNeedSerialize ? variables.set(identifier, {type:type, value:BCS_CONVERT.ser_bool(value)}) :
127
+ variables.set(identifier, {type:type, value:value})
128
+ return true;
129
+ case ContextType.TYPE_CONTEXT_address:
130
+ case OperatorType.TYPE_QUERY_FROM_CONTEXT:
131
+ bNeedSerialize ? variables.set(identifier, {type:type, value:BCS_CONVERT.ser_address(value)}):
132
+ variables.set(identifier, {type:type, value:value});
133
+ return true;
134
+ case ContextType.TYPE_CONTEXT_u64:
135
+ bNeedSerialize ? variables.set(identifier, {type:type, value:BCS_CONVERT.ser_u64(value)}) :
136
+ variables.set(identifier, {type:type, value:value})
137
+ return true;
138
+ case ContextType.TYPE_CONTEXT_u8:
139
+ bNeedSerialize ? variables.set(identifier, {type:type, value:BCS_CONVERT.ser_u8(value)}) :
140
+ variables.set(identifier, {type:type, value:value})
141
+ return true;
142
+ case ContextType.TYPE_CONTEXT_vec_u8:
143
+ bNeedSerialize ? variables.set(identifier, {type:type, value:BCS_CONVERT.ser_string(value)}) :
144
+ variables.set(identifier, {type:type, value:value})
145
+ return true;
146
+ }
147
+ return false;
148
+ }
149
+
28
150
  export function launch(txb:TransactionBlock, creation:Guard_Creation) : GuardAddress | boolean {
29
151
  if (!IsValidDesription(creation.description)) return false;
30
152
  if (!creation.senses) return false;
153
+
31
154
  let bValid = true;
32
155
  creation.senses.forEach((v) => {
33
156
  if (!v.input || v.input.length == 0) bValid = false;
34
157
  })
158
+ creation?.variables?.forEach((v, k) => {
159
+ if (!IsValidIndentifier(k)) bValid = false;
160
+ if (!IsValidGuardVirableType(v.type)) bValid = false;
161
+ if (!v.value && !v.witness) bValid = false;
162
+ })
35
163
  if (!bValid) return false;
36
164
 
37
165
  let guard = txb.moveCall({
@@ -47,6 +175,23 @@ export function launch(txb:TransactionBlock, creation:Guard_Creation) : GuardAdd
47
175
  ]
48
176
  })
49
177
  });
178
+ creation?.variables?.forEach((v, k) => {
179
+ if (v.type == OperatorType.TYPE_FUTURE_QUERY || v.type == ContextType.TYPE_CONTEXT_FUTURE_ID) {
180
+ if (!v.witness) return false;
181
+ txb.moveCall({
182
+ target:PROTOCOL.GuardFn("variable_add") as FnCallType,
183
+ arguments:[guard, txb.pure(k, BCS.U8), txb.pure(v.type, BCS.U8), txb.pure([].slice.call(v.witness)), txb.pure(true, BCS.BOOL)]
184
+ })
185
+ } else {
186
+ if (!v.value) return false;
187
+
188
+ txb.moveCall({
189
+ target:PROTOCOL.GuardFn("variable_add") as FnCallType,
190
+ arguments:[guard, txb.pure(k, BCS.U8), txb.pure(v.type, BCS.U8), txb.pure([].slice.call(v.value)), txb.pure(true, BCS.BOOL)]
191
+ })
192
+ }
193
+ });
194
+
50
195
  return txb.moveCall({
51
196
  target:PROTOCOL.GuardFn("create") as FnCallType,
52
197
  arguments:[guard]
@@ -206,50 +351,80 @@ export const QUERIES:any = [
206
351
  export class SenseMaker {
207
352
  protected data : Uint8Array[] = [];
208
353
  protected type_validator : Data_Type[] = [];
209
-
210
354
  constructor() { }
355
+
211
356
  // serialize const & data
212
- add_param(type:ValueType | ContextType, param?:any) : boolean {
213
- const bcs = new BCS(getSuiMoveConfig());
357
+ add_param(type:ValueType | ContextType, param?:any, variable?:VariableType) : boolean {
214
358
  switch(type) {
215
359
  case ValueType.TYPE_STATIC_address:
216
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
217
- this.data.push(bcs.ser(BCS.ADDRESS, param).toBytes());
360
+ if (!param) return false
361
+ this.data.push(BCS_CONVERT.ser_u8(type));
362
+ this.data.push(BCS_CONVERT.ser_address(param));
218
363
  this.type_validator.push(type);
219
364
  break;
220
365
  case ValueType.TYPE_STATIC_bool:
221
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
222
- this.data.push(bcs.ser(BCS.BOOL, param).toBytes());
366
+ if (!param) return false
367
+ this.data.push(BCS_CONVERT.ser_u8(type));
368
+ this.data.push(BCS_CONVERT.ser_bool(param));
223
369
  this.type_validator.push(type);
224
370
  break;
225
371
  case ValueType.TYPE_STATIC_u8:
226
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
227
- this.data.push(bcs.ser(BCS.U8, param).toBytes());
372
+ if (!param) return false
373
+ this.data.push(BCS_CONVERT.ser_u8(type));
374
+ this.data.push(BCS_CONVERT.ser_u8(param));
228
375
  this.type_validator.push(type);
229
376
  break;
230
377
  case ValueType.TYPE_STATIC_u64:
231
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
232
- this.data.push(bcs.ser(BCS.U64, param).toBytes());
378
+ if (!param) return false
379
+ this.data.push(BCS_CONVERT.ser_u8(type));
380
+ this.data.push(BCS_CONVERT.ser_u64(param));
233
381
  this.type_validator.push(type);
234
382
  break;
235
383
  case ValueType.TYPE_STATIC_vec_u8:
236
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
237
- this.data.push(bcs.ser(BCS.STRING, param).toBytes());
384
+ if (!param) return false
385
+ this.data.push(BCS_CONVERT.ser_u8(type));
386
+ this.data.push(BCS_CONVERT.ser_string(param));
238
387
  this.type_validator.push(type);
239
388
  // this.data[this.data.length-1].forEach((item : number) => console.log(item))
240
389
  break;
241
390
  case ContextType.TYPE_CONTEXT_SIGNER:
242
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
391
+ this.data.push(BCS_CONVERT.ser_u8(type));
243
392
  this.type_validator.push(ValueType.TYPE_STATIC_address);
244
393
  break;
245
- case ContextType.TYPE_CONTEXT_CURRENT_CLOCK:
246
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
394
+ case ContextType.TYPE_CONTEXT_CLOCK:
395
+ this.data.push(BCS_CONVERT.ser_u8(type));
247
396
  this.type_validator.push(ValueType.TYPE_STATIC_u64);
248
397
  break;
249
- case ContextType.TYPE_CONTEXT_CURRENT_PROGRESS:
250
- this.data.push(bcs.ser(BCS.U8, type).toBytes());
251
- this.type_validator.push(ValueType.TYPE_STATIC_address);
252
- break;
398
+ case ContextType.TYPE_CONTEXT_bool:
399
+ case ContextType.TYPE_CONTEXT_u8:
400
+ case ContextType.TYPE_CONTEXT_u64:
401
+ case ContextType.TYPE_CONTEXT_vec_u8:
402
+ case ContextType.TYPE_CONTEXT_address:
403
+ case ContextType.TYPE_CONTEXT_FUTURE_ID:
404
+ if (!variable || !param) return false;
405
+ if (typeof(param) != 'number') return false;
406
+ if (!IsValidInt(param) || param > 255) return false;
407
+
408
+ var v = variable.get(param);
409
+ if (v?.type == type) {
410
+ this.data.push(BCS_CONVERT.ser_u8(type));
411
+ this.data.push(BCS_CONVERT.ser_u8(param));
412
+ if (type == ContextType.TYPE_CONTEXT_bool) {
413
+ this.type_validator.push(ValueType.TYPE_STATIC_bool);
414
+ } else if (type == ContextType.TYPE_CONTEXT_u8) {
415
+ this.type_validator.push(ValueType.TYPE_STATIC_u8);
416
+ } else if (type == ContextType.TYPE_CONTEXT_u64) {
417
+ this.type_validator.push(ValueType.TYPE_STATIC_u64);
418
+ } else if (type == ContextType.TYPE_CONTEXT_vec_u8) {
419
+ this.type_validator.push(ValueType.TYPE_STATIC_vec_u8);
420
+ } else if (type == ContextType.TYPE_CONTEXT_address) {
421
+ this.type_validator.push(ValueType.TYPE_STATIC_address);
422
+ } else if (type == ContextType.TYPE_CONTEXT_FUTURE_ID) {
423
+ this.type_validator.push(ValueType.TYPE_STATIC_address);
424
+ }
425
+ break;
426
+ };
427
+ return false;
253
428
  default:
254
429
  return false;
255
430
  };
@@ -264,10 +439,41 @@ export class SenseMaker {
264
439
  }
265
440
  return -1;
266
441
  }
267
- // query_index: index(from 0) of array QUERIES
268
- add_query(object_address:string, module:MODULES, query_name:string) : boolean {
442
+ add_future_query(identifier:number, module:MODULES, query_name:string, variable:VariableType) : boolean {
269
443
  let query_index = this.query_index(module, query_name);
270
- if (!object_address || query_index == -1) { return false; }
444
+ if (!IsValidIndentifier(identifier) || query_index == -1) return false;
445
+ if (module != MODULES.order && module != MODULES.progress) return false;
446
+ if (!variable || variable.get(identifier)?.type != OperatorType.TYPE_FUTURE_QUERY) return false;
447
+
448
+ let offset = this.type_validator.length - QUERIES[query_index][3].length;
449
+ if (offset < 0) {
450
+ return false;
451
+ }
452
+
453
+ let types = this.type_validator.slice(offset);
454
+ if (!array_equal(types, QUERIES[query_index][3])) { // type validate
455
+ return false;
456
+ }
457
+
458
+ this.data.push(BCS_CONVERT.ser_u8(OperatorType.TYPE_FUTURE_QUERY)); // TYPE
459
+ this.data.push(BCS_CONVERT.ser_u8(identifier)); // variable identifier
460
+ this.data.push(BCS_CONVERT.ser_u8(QUERIES[query_index][2])); // cmd
461
+
462
+ this.type_validator.splice(offset, QUERIES[query_index][3].length); // delete type stack
463
+ this.type_validator.push(QUERIES[query_index][4]); // add the return value type to type stack
464
+ // console.log(this.type_validator)
465
+ return true;
466
+ }
467
+
468
+ // object_address_from: string for static address; number as identifier for variable
469
+ add_query(module:MODULES, query_name:string, object_address_from:string | number) : boolean {
470
+ let query_index = this.query_index(module, query_name); // query_index: index(from 0) of array QUERIES
471
+ if (query_index == -1) return false;
472
+ if (typeof(object_address_from) == 'number') {
473
+ if (!IsValidIndentifier(object_address_from)) return false;
474
+ } else {
475
+ if (!IsValidAddress(object_address_from)) return false;
476
+ }
271
477
 
272
478
  let offset = this.type_validator.length - QUERIES[query_index][3].length;
273
479
  if (offset < 0) {
@@ -279,16 +485,22 @@ export class SenseMaker {
279
485
  return false;
280
486
  }
281
487
 
282
- const bcs = new BCS(getSuiMoveConfig());
283
- this.data.push(bcs.ser(BCS.U8, OperatorType.TYPE_DYNAMIC_QUERY).toBytes()); // TYPE
284
- this.data.push(bcs.ser(BCS.ADDRESS, object_address).toBytes()); // object address
285
- this.data.push(bcs.ser(BCS.U8, QUERIES[query_index][2]).toBytes()); // cmd
488
+ if (typeof(object_address_from) == 'string') {
489
+ this.data.push(BCS_CONVERT.ser_u8(OperatorType.TYPE_QUERY));// TYPE
490
+ this.data.push(BCS_CONVERT.ser_address(object_address_from)); // object address
491
+ } else {
492
+ this.data.push(BCS_CONVERT.ser_u8(OperatorType.TYPE_QUERY_FROM_CONTEXT));// TYPE
493
+ this.data.push(BCS_CONVERT.ser_u8(object_address_from)); // object identifer in variables
494
+ }
495
+
496
+ this.data.push(BCS_CONVERT.ser_u8(QUERIES[query_index][2])); // cmd
286
497
 
287
498
  this.type_validator.splice(offset, QUERIES[query_index][3].length); // delete type stack
288
499
  this.type_validator.push(QUERIES[query_index][4]); // add the return value type to type stack
289
500
  // console.log(this.type_validator)
290
501
  return true;
291
502
  }
503
+
292
504
  add_logic(type:OperatorType) : boolean {
293
505
  switch (type) {
294
506
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
@@ -307,8 +519,7 @@ export class SenseMaker {
307
519
  default:
308
520
  return false;
309
521
  }
310
- const bcs = new BCS(getSuiMoveConfig());
311
- this.data.push(bcs.ser(BCS.U8, type).toBytes()); // TYPE
522
+ this.data.push(BCS_CONVERT.ser_u8(type)); // TYPE
312
523
  this.type_validator.splice(this.type_validator.length - 2); // delete type stack
313
524
  this.type_validator.push(ValueType.TYPE_STATIC_bool); // add bool to type stack
314
525
  return true;
@@ -318,7 +529,7 @@ export class SenseMaker {
318
529
  //console.log(this.type_validator);
319
530
  //this.data.forEach((value:Uint8Array) => console.log(value));
320
531
  if (this.type_validator.length != 1 || this.type_validator[0] != ValueType.TYPE_STATIC_bool) {
321
- // console.log(this.type_validator)
532
+ console.log(this.type_validator)
322
533
  return false;
323
534
  } // ERROR
324
535
 
@@ -337,30 +548,91 @@ function match_u128(type:number) : boolean {
337
548
  return false;
338
549
  }
339
550
 
340
- export function parse_graphql_senses(senses:any) : string[] {
551
+ export function parse_graphql_senses(guardid:string, senses:any) : string[] {
341
552
  let objects:string[] = [];
342
553
  senses.forEach((s:any) => {
343
- let res = parse_sense_bsc(Uint8Array.from(s.input.bytes));
344
- if (res) {
345
- objects = objects.concat(res as string[]);
346
- }
554
+ let res = parse_sense_bsc(objects, guardid, Uint8Array.from(s.input.bytes));
347
555
  });
348
- return array_unique(objects);
556
+ return objects;
557
+ }
558
+
559
+ export function parse_futures(result:any[], guardid: string, chain_sense_bsc:Uint8Array, variable?:VariableType) : boolean {
560
+ var arr = [].slice.call(chain_sense_bsc.reverse());
561
+ while (arr.length > 0) {
562
+ var type : unknown = arr.shift() ;
563
+ // console.log(type);
564
+ switch (type as Data_Type) {
565
+ case ContextType.TYPE_CONTEXT_SIGNER:
566
+ case ContextType.TYPE_CONTEXT_CLOCK:
567
+ case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
568
+ case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
569
+ case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
570
+ case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
571
+ case OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
572
+ case OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
573
+ case OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
574
+ case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
575
+ break;
576
+ case ContextType.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
577
+ case OperatorType.TYPE_FUTURE_QUERY:
578
+ var identifer = arr.splice(0, 1);
579
+ if (type == OperatorType.TYPE_FUTURE_QUERY) {
580
+ arr.splice(0, 1); // cmd
581
+ }
582
+ if (!variable || variable?.get(identifer[0])?.type != type) return false;
583
+
584
+ let witness = get_variable_witness(variable, identifer[0], type as OperatorType) ;
585
+ if (!witness) return false;
586
+ result.push({guardid:guardid, identifier:identifer[0], type:type,
587
+ witness:'0x' + BCS_CONVERT.de(BCS.ADDRESS, Uint8Array.from(witness as Uint8Array))} as FutureValueRequest);
588
+ break;
589
+ case ContextType.TYPE_CONTEXT_address:
590
+ case ContextType.TYPE_CONTEXT_bool:
591
+ case ContextType.TYPE_CONTEXT_u8:
592
+ case ContextType.TYPE_CONTEXT_u64:
593
+ case ContextType.TYPE_CONTEXT_vec_u8:
594
+ case ValueType.TYPE_STATIC_bool:
595
+ case ValueType.TYPE_STATIC_u8:
596
+ arr.splice(0, 1); // identifier
597
+ break;
598
+ case OperatorType.TYPE_QUERY_FROM_CONTEXT:
599
+ arr.splice(0, 2); // identifer + cmd
600
+ case ValueType.TYPE_STATIC_address:
601
+ arr.splice(0, 32);
602
+ break;
603
+ case ValueType.TYPE_STATIC_u64:
604
+ arr.splice(0, 8);
605
+ break;
606
+ case ValueType.TYPE_STATIC_u128:
607
+ arr.splice(0, 16);
608
+ break;
609
+ case ValueType.TYPE_STATIC_vec_u8:
610
+ let {value, length} = ulebDecode(Uint8Array.from(arr));
611
+ arr.splice(0, value+length);
612
+ break;
613
+ case OperatorType.TYPE_QUERY:
614
+ arr.splice(0, 33); // address + cmd
615
+ break;
616
+ default:
617
+ console.error('parse_sense_bsc:undefined');
618
+ console.log(type as number)
619
+ console.log(arr)
620
+ return false; // error
621
+ }
622
+ }
623
+ return true;
349
624
  }
350
625
 
351
626
  // parse guard senses input bytes of a guard, return [objectids] for 'query_cmd'
352
- export function parse_sense_bsc(chain_sense_bsc:Uint8Array) : boolean | string[] {
627
+ export function parse_sense_bsc(result:any[], guardid: string, chain_sense_bsc:Uint8Array, variable?:VariableType) : boolean {
353
628
  var arr = [].slice.call(chain_sense_bsc.reverse());
354
- const bcs = new BCS(getSuiMoveConfig());
355
- var result = [];
356
629
 
357
630
  while (arr.length > 0) {
358
631
  var type : unknown = arr.shift() ;
359
632
  // console.log(type);
360
633
  switch (type as Data_Type) {
361
634
  case ContextType.TYPE_CONTEXT_SIGNER:
362
- case ContextType.TYPE_CONTEXT_CURRENT_CLOCK:
363
- case ContextType.TYPE_CONTEXT_CURRENT_PROGRESS:
635
+ case ContextType.TYPE_CONTEXT_CLOCK:
364
636
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
365
637
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
366
638
  case OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
@@ -370,6 +642,17 @@ export function parse_sense_bsc(chain_sense_bsc:Uint8Array) : boolean | string[
370
642
  case OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
371
643
  case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
372
644
  break;
645
+ case ContextType.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
646
+ var v = arr.splice(0, 1);
647
+ if (!variable || variable?.get(v[0])?.type != type) return false;
648
+ break;
649
+ case ContextType.TYPE_CONTEXT_address:
650
+ case ContextType.TYPE_CONTEXT_bool:
651
+ case ContextType.TYPE_CONTEXT_u8:
652
+ case ContextType.TYPE_CONTEXT_u64:
653
+ case ContextType.TYPE_CONTEXT_vec_u8:
654
+ arr.splice(0, 1); // identifier
655
+ break;
373
656
  case ValueType.TYPE_STATIC_address:
374
657
  //console.log('0x' + bcs.de(BCS.ADDRESS, Uint8Array.from(array)).toString());
375
658
  arr.splice(0, 32);
@@ -388,10 +671,21 @@ export function parse_sense_bsc(chain_sense_bsc:Uint8Array) : boolean | string[
388
671
  let {value, length} = ulebDecode(Uint8Array.from(arr));
389
672
  arr.splice(0, value+length);
390
673
  break;
391
- case OperatorType.TYPE_DYNAMIC_QUERY:
392
- result.push('0x' + bcs.de(BCS.ADDRESS, Uint8Array.from(arr)).toString());
674
+ case OperatorType.TYPE_QUERY:
675
+ result.push('0x' + BCS_CONVERT.de(BCS.ADDRESS, Uint8Array.from(arr)).toString());
393
676
  arr.splice(0, 33); // address + cmd
394
677
  break;
678
+ case OperatorType.TYPE_QUERY_FROM_CONTEXT:
679
+ case OperatorType.TYPE_FUTURE_QUERY:
680
+ var identifer = arr.splice(0, 1);
681
+ if (variable) {
682
+ let v = get_variable_value(variable, identifer[0], type as OperatorType) ;
683
+ if (v) {
684
+ result.push('0x' + BCS_CONVERT.de(BCS.ADDRESS, Uint8Array.from(v as Uint8Array)).toString());
685
+ arr.splice(0, 1); // splice cmd
686
+ break;
687
+ }
688
+ }; return false
395
689
  default:
396
690
  console.error('parse_sense_bsc:undefined');
397
691
  console.log(type as number)
@@ -399,7 +693,7 @@ export function parse_sense_bsc(chain_sense_bsc:Uint8Array) : boolean | string[
399
693
  return false; // error
400
694
  }
401
695
  }
402
- return result;
696
+ return true;
403
697
  }
404
698
 
405
699
  export const rpc_description_fn = (response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions) => {
@@ -415,18 +709,40 @@ export const rpc_description_fn = (response:SuiObjectResponse, param:Query_Param
415
709
  }
416
710
  }
417
711
 
712
+
418
713
  export const rpc_sense_objects_fn = (response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions) => {
419
714
  if (!response.error) {
420
715
  let c = response?.data?.content as any;
421
716
  let index = OBJECTS_TYPE().findIndex(v => v.includes('guard::Guard') && v == c.type);
422
717
  if (index >= 0 && c.fields.id.id == param.objectid) { // GUARD OBJECT
718
+ if (!param?.variables) {
719
+ let v = new Map<number, Guard_Vriable>();
720
+ for (let i = 0; i < c.fields.variables.length; i ++) {
721
+ let variable = c.fields.variables[i]; let bret ;
722
+ if (variable.type == (OBJECTS_TYPE_PREFIX()[index] + 'Variable')) { // ...::guard::Variable
723
+ if (variable.fields.type == OperatorType.TYPE_FUTURE_QUERY || variable.fields.type == ContextType.TYPE_CONTEXT_FUTURE_ID) {
724
+ bret = add_future_variable(v, variable.fields.identifier, variable.fields.type,
725
+ variable.fields?.value?Uint8Array.from(variable.fields.value):undefined, undefined, false);
726
+ } else {
727
+ bret = add_variable(v, variable.fields.identifier, variable.fields.type,
728
+ variable.fields?.value?Uint8Array.from(variable.fields.value):undefined, false);
729
+ }
730
+ if (!bret) {
731
+ console.log('rpc_sense_objects_fn add_variable error');
732
+ console.log(variable);
733
+ return ;
734
+ }
735
+ }
736
+ }
737
+ param.variables = v;
738
+ }
739
+
423
740
  for (let i = 0; i < c.fields.senses.length; i ++) {
424
741
  let sense = c.fields.senses[i];
425
742
  if (sense.type == (OBJECTS_TYPE_PREFIX()[index] + 'Sense')) { // ...::guard::Sense
426
- let res = parse_sense_bsc(Uint8Array.from(sense.fields.input.fields.bytes));
427
- if (res) {
428
- let ids = res as string[];
429
- param.data = param.data.concat(ids); // DONT array_unique senses
743
+ let result : any[] = [];
744
+ if (param?.parser && param.parser(result, param.objectid, Uint8Array.from(sense.fields.input.fields.bytes), param.variables)) {
745
+ param.data = param.data.concat(result); // DONT array_unique senses
430
746
  }
431
747
  }
432
748
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  export * from './protocol'
2
3
  export * from './passport'
3
4
  export { demand, demand_expand_time, demand_refund, demand_set_description, demand_set_guard, demand_yes, deposit as demand_deposit,
@@ -6,7 +7,7 @@ export { demand, demand_expand_time, demand_refund, demand_set_description, dema
6
7
  export { machine, machine_add_node, machine_add_node2, machine_add_repository, machine_clone, machine_pause, machine_publish,
7
8
  machine_remove_node, machine_remove_repository, machine_set_description, machine_set_endpoint, MachineNodeObject, Machine_Forward,
8
9
  Machine_Node, Machine_Node_Pair, launch as machine_launch, destroy as machine_destroy, change_permission as machine_change_permission,
9
- INITIAL_NODE_NAME, namedOperator_ORDER_PAYER } from './machine'
10
+ INITIAL_NODE_NAME, OPERATOR_ORDER_PAYER } from './machine'
10
11
  export { progress, ProgressNext, ParentProgress, progress_bind_task, progress_parent, progress_set_context_repository, progress_unhold,
11
12
  hold, progress_set_namedOperator, MAX_NAMED_OPERATOR_COUNT, next } from './progress'
12
13
  export { service, service_add_refund_guards, service_add_sale, service_add_stock, service_add_withdraw_guards, service_clone,
package/src/machine.ts CHANGED
@@ -9,7 +9,7 @@ import { IsValidPermissionIndex, PermissionIndexType } from './permission';
9
9
 
10
10
  export type MachineNodeObject = TransactionResult | String;
11
11
  export const INITIAL_NODE_NAME = '';
12
- export const namedOperator_ORDER_PAYER = 'order payer';
12
+ export const OPERATOR_ORDER_PAYER = 'order payer';
13
13
 
14
14
  export type Machine_Forward = {
15
15
  name: string; // foward name
@@ -36,7 +36,6 @@ export function machine_add_node(txb:TransactionBlock, machine:MachineObject, pe
36
36
  let bValid = true;
37
37
  nodes.forEach((node) => {
38
38
  if (!IsValidDesription(node.description) || !IsValidName(node.name)) { bValid = false; }
39
-
40
39
  node.pairs.forEach((p) => {
41
40
  if (!IsValidName_AllowEmpty(p.prior_node)) { bValid = false; }
42
41
  if (p?.threshold && !IsValidInt(p.threshold)) { bValid = false; }