wowok 1.0.7 → 1.0.9
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 +3 -2
- package/dist/demand.js +4 -4
- package/dist/guard.js +367 -67
- package/dist/index.js +2 -2
- package/dist/machine.js +2 -2
- package/dist/passport.js +49 -29
- package/dist/permission.js +4 -4
- package/dist/progress.js +2 -2
- package/dist/protocol.js +51 -30
- package/dist/service.js +4 -4
- package/dist/utils.js +44 -1
- package/package.json +3 -3
- package/src/demand.ts +4 -4
- package/src/guard.ts +361 -70
- package/src/index.ts +1 -1
- package/src/machine.ts +1 -2
- package/src/passport.ts +60 -37
- package/src/permission.ts +4 -4
- package/src/progress.ts +2 -2
- package/src/protocol.ts +52 -30
- package/src/utils.ts +48 -2
package/README.md
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
AI-oriented web3 collaboration protocol, driving innovaion and making it more likely to happen.
|
|
5
5
|
|
|
6
|
-
[
|
|
6
|
+
Github: [https://github.com/wowok-ai/sdk](https://github.com/wowok-ai/sdk)
|
|
7
|
+
Examples: [https://github.com/wowok-ai/sdk-examples](https://github.com/wowok-ai/sdk-examples)
|
|
7
8
|
|
|
8
9
|
### Installation
|
|
9
10
|
|
|
10
11
|
```
|
|
11
|
-
$ npm
|
|
12
|
+
$ npm i wowok
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
### Documentation
|
package/dist/demand.js
CHANGED
|
@@ -161,24 +161,24 @@ function demand_set_description(earnest_type, txb, demand, permission, descripti
|
|
|
161
161
|
return true;
|
|
162
162
|
}
|
|
163
163
|
exports.demand_set_description = demand_set_description;
|
|
164
|
-
function demand_yes(earnest_type, txb, demand, permission,
|
|
164
|
+
function demand_yes(earnest_type, txb, demand, permission, service_id, passport) {
|
|
165
165
|
if (!(0, protocol_1.IsValidObjects)([demand, permission]))
|
|
166
166
|
return false;
|
|
167
167
|
if (!(0, protocol_1.IsValidArgType)(earnest_type))
|
|
168
168
|
return false;
|
|
169
|
-
if (!(0, protocol_1.IsValidAddress)(
|
|
169
|
+
if (!(0, protocol_1.IsValidAddress)(service_id))
|
|
170
170
|
return false;
|
|
171
171
|
if (passport) {
|
|
172
172
|
txb.moveCall({
|
|
173
173
|
target: protocol_1.PROTOCOL.DemandFn('yes_with_passport'),
|
|
174
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, demand), txb.pure(
|
|
174
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, demand), txb.pure(service_id, bcs_1.BCS.ADDRESS), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
175
175
|
typeArguments: [earnest_type],
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
178
|
else {
|
|
179
179
|
txb.moveCall({
|
|
180
180
|
target: protocol_1.PROTOCOL.DemandFn('yes'),
|
|
181
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, demand), txb.pure(
|
|
181
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, demand), txb.pure(service_id, bcs_1.BCS.ADDRESS), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
182
182
|
typeArguments: [earnest_type],
|
|
183
183
|
});
|
|
184
184
|
}
|
package/dist/guard.js
CHANGED
|
@@ -1,15 +1,131 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc_sense_objects_fn = exports.rpc_description_fn = exports.parse_sense_bsc = exports.parse_graphql_senses = exports.SenseMaker = exports.QUERIES = exports.everyone_guard = exports.signer_guard = exports.launch = exports.Guard_Sense_Binder = exports.MAX_SENSE_COUNT = void 0;
|
|
3
|
+
exports.rpc_sense_objects_fn = exports.rpc_description_fn = exports.parse_sense_bsc = exports.parse_futures = exports.parse_graphql_senses = exports.SenseMaker = exports.QUERIES = exports.everyone_guard = exports.signer_guard = exports.launch = exports.add_variable = exports.add_future_variable = exports.get_variable_witness = exports.get_variable_value = exports.IsValidIndentifier = exports.IsValidGuardVirableType = exports.Guard_Sense_Binder = exports.MAX_SENSE_COUNT = void 0;
|
|
4
4
|
const bcs_1 = require("@mysten/bcs");
|
|
5
5
|
const protocol_1 = require("./protocol");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const utils_2 = require("./utils");
|
|
7
8
|
exports.MAX_SENSE_COUNT = 16;
|
|
8
9
|
var Guard_Sense_Binder;
|
|
9
10
|
(function (Guard_Sense_Binder) {
|
|
10
11
|
Guard_Sense_Binder[Guard_Sense_Binder["AND"] = 0] = "AND";
|
|
11
12
|
Guard_Sense_Binder[Guard_Sense_Binder["OR"] = 1] = "OR";
|
|
12
13
|
})(Guard_Sense_Binder || (exports.Guard_Sense_Binder = Guard_Sense_Binder = {}));
|
|
14
|
+
const IsValidGuardVirableType = (type) => {
|
|
15
|
+
if (type == protocol_1.OperatorType.TYPE_FUTURE_QUERY || type == protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID || type == protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT ||
|
|
16
|
+
type == protocol_1.ContextType.TYPE_CONTEXT_bool || type == protocol_1.ContextType.TYPE_CONTEXT_address || type == protocol_1.ContextType.TYPE_CONTEXT_u64 ||
|
|
17
|
+
type == protocol_1.ContextType.TYPE_CONTEXT_u8 || type == protocol_1.ContextType.TYPE_CONTEXT_vec_u8) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
;
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
exports.IsValidGuardVirableType = IsValidGuardVirableType;
|
|
24
|
+
const IsValidIndentifier = (identifier) => {
|
|
25
|
+
if (!(0, protocol_1.IsValidInt)(identifier) || identifier > 255)
|
|
26
|
+
return false;
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
exports.IsValidIndentifier = IsValidIndentifier;
|
|
30
|
+
/*
|
|
31
|
+
// called by de-guard or passport
|
|
32
|
+
export function set_futrue_value(variables:VariableType, identifier:number, type:OperatorType | ContextType, value?:any) : boolean {
|
|
33
|
+
if (!IsValidIndentifier(identifier)) return false;
|
|
34
|
+
if (!IsValidGuardVirableType(type)) return false;
|
|
35
|
+
let v = variables.get(identifier);
|
|
36
|
+
if (v) {
|
|
37
|
+
v.value = BCS_CONVERT.ser_address(value);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
} */
|
|
42
|
+
function get_variable_value(variables, identifier, type) {
|
|
43
|
+
if (variables.has(identifier)) {
|
|
44
|
+
let v = variables.get(identifier);
|
|
45
|
+
if (v?.value && v.type == type) {
|
|
46
|
+
return v.value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
exports.get_variable_value = get_variable_value;
|
|
52
|
+
function get_variable_witness(variables, identifier, type) {
|
|
53
|
+
if (variables.has(identifier)) {
|
|
54
|
+
let v = variables.get(identifier);
|
|
55
|
+
if (v?.witness && v.type == type) {
|
|
56
|
+
return v.witness;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
exports.get_variable_witness = get_variable_witness;
|
|
62
|
+
function add_future_variable(variables, identifier, type, witness, value, bNeedSerialize = true) {
|
|
63
|
+
if (!(0, exports.IsValidIndentifier)(identifier))
|
|
64
|
+
return false;
|
|
65
|
+
if (!(0, exports.IsValidGuardVirableType)(type))
|
|
66
|
+
return false;
|
|
67
|
+
if (!witness && !value)
|
|
68
|
+
return false;
|
|
69
|
+
switch (type) {
|
|
70
|
+
case protocol_1.OperatorType.TYPE_FUTURE_QUERY:
|
|
71
|
+
case protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID:
|
|
72
|
+
if (variables.has(identifier)) {
|
|
73
|
+
let v = variables.get(identifier);
|
|
74
|
+
if (bNeedSerialize) {
|
|
75
|
+
v.value = value ? utils_2.BCS_CONVERT.ser_address(value) : undefined;
|
|
76
|
+
v.witness = witness ? utils_2.BCS_CONVERT.ser_address(witness) : undefined;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
v.value = value ? value : undefined;
|
|
80
|
+
v.witness = witness ? witness : undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (bNeedSerialize) {
|
|
85
|
+
variables.set(identifier, { type: type, value: value ? utils_2.BCS_CONVERT.ser_address(value) : undefined, witness: witness ? utils_2.BCS_CONVERT.ser_address(witness) : undefined });
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
variables.set(identifier, { type: type, value: value ? value : undefined, witness: witness ? witness : undefined });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
exports.add_future_variable = add_future_variable;
|
|
96
|
+
function add_variable(variables, identifier, type, value, bNeedSerialize = true) {
|
|
97
|
+
if (!(0, exports.IsValidIndentifier)(identifier))
|
|
98
|
+
return false;
|
|
99
|
+
if (!(0, exports.IsValidGuardVirableType)(type))
|
|
100
|
+
return false;
|
|
101
|
+
if (!value)
|
|
102
|
+
return false;
|
|
103
|
+
switch (type) {
|
|
104
|
+
case protocol_1.ContextType.TYPE_CONTEXT_bool:
|
|
105
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: utils_2.BCS_CONVERT.ser_bool(value) }) :
|
|
106
|
+
variables.set(identifier, { type: type, value: value });
|
|
107
|
+
return true;
|
|
108
|
+
case protocol_1.ContextType.TYPE_CONTEXT_address:
|
|
109
|
+
case protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
110
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: utils_2.BCS_CONVERT.ser_address(value) }) :
|
|
111
|
+
variables.set(identifier, { type: type, value: value });
|
|
112
|
+
return true;
|
|
113
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u64:
|
|
114
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: utils_2.BCS_CONVERT.ser_u64(value) }) :
|
|
115
|
+
variables.set(identifier, { type: type, value: value });
|
|
116
|
+
return true;
|
|
117
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u8:
|
|
118
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: utils_2.BCS_CONVERT.ser_u8(value) }) :
|
|
119
|
+
variables.set(identifier, { type: type, value: value });
|
|
120
|
+
return true;
|
|
121
|
+
case protocol_1.ContextType.TYPE_CONTEXT_vec_u8:
|
|
122
|
+
bNeedSerialize ? variables.set(identifier, { type: type, value: utils_2.BCS_CONVERT.ser_string(value) }) :
|
|
123
|
+
variables.set(identifier, { type: type, value: value });
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
exports.add_variable = add_variable;
|
|
13
129
|
function launch(txb, creation) {
|
|
14
130
|
if (!(0, protocol_1.IsValidDesription)(creation.description))
|
|
15
131
|
return false;
|
|
@@ -20,6 +136,14 @@ function launch(txb, creation) {
|
|
|
20
136
|
if (!v.input || v.input.length == 0)
|
|
21
137
|
bValid = false;
|
|
22
138
|
});
|
|
139
|
+
creation?.variables?.forEach((v, k) => {
|
|
140
|
+
if (!(0, exports.IsValidIndentifier)(k))
|
|
141
|
+
bValid = false;
|
|
142
|
+
if (!(0, exports.IsValidGuardVirableType)(v.type))
|
|
143
|
+
bValid = false;
|
|
144
|
+
if (!v.value && !v.witness)
|
|
145
|
+
bValid = false;
|
|
146
|
+
});
|
|
23
147
|
if (!bValid)
|
|
24
148
|
return false;
|
|
25
149
|
let guard = txb.moveCall({
|
|
@@ -35,6 +159,24 @@ function launch(txb, creation) {
|
|
|
35
159
|
]
|
|
36
160
|
});
|
|
37
161
|
});
|
|
162
|
+
creation?.variables?.forEach((v, k) => {
|
|
163
|
+
if (v.type == protocol_1.OperatorType.TYPE_FUTURE_QUERY || v.type == protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID) {
|
|
164
|
+
if (!v.witness)
|
|
165
|
+
return false;
|
|
166
|
+
txb.moveCall({
|
|
167
|
+
target: protocol_1.PROTOCOL.GuardFn("variable_add"),
|
|
168
|
+
arguments: [guard, txb.pure(k, bcs_1.BCS.U8), txb.pure(v.type, bcs_1.BCS.U8), txb.pure([].slice.call(v.witness)), txb.pure(true, bcs_1.BCS.BOOL)]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if (!v.value)
|
|
173
|
+
return false;
|
|
174
|
+
txb.moveCall({
|
|
175
|
+
target: protocol_1.PROTOCOL.GuardFn("variable_add"),
|
|
176
|
+
arguments: [guard, txb.pure(k, bcs_1.BCS.U8), txb.pure(v.type, bcs_1.BCS.U8), txb.pure([].slice.call(v.value)), txb.pure(true, bcs_1.BCS.BOOL)]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
38
180
|
return txb.moveCall({
|
|
39
181
|
target: protocol_1.PROTOCOL.GuardFn("create"),
|
|
40
182
|
arguments: [guard]
|
|
@@ -179,48 +321,90 @@ class SenseMaker {
|
|
|
179
321
|
type_validator = [];
|
|
180
322
|
constructor() { }
|
|
181
323
|
// serialize const & data
|
|
182
|
-
add_param(type, param) {
|
|
183
|
-
const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
|
|
324
|
+
add_param(type, param, variable) {
|
|
184
325
|
switch (type) {
|
|
185
326
|
case protocol_1.ValueType.TYPE_STATIC_address:
|
|
186
|
-
|
|
187
|
-
|
|
327
|
+
if (!param)
|
|
328
|
+
return false;
|
|
329
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
330
|
+
this.data.push(utils_2.BCS_CONVERT.ser_address(param));
|
|
188
331
|
this.type_validator.push(type);
|
|
189
332
|
break;
|
|
190
333
|
case protocol_1.ValueType.TYPE_STATIC_bool:
|
|
191
|
-
|
|
192
|
-
|
|
334
|
+
if (!param)
|
|
335
|
+
return false;
|
|
336
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
337
|
+
this.data.push(utils_2.BCS_CONVERT.ser_bool(param));
|
|
193
338
|
this.type_validator.push(type);
|
|
194
339
|
break;
|
|
195
340
|
case protocol_1.ValueType.TYPE_STATIC_u8:
|
|
196
|
-
|
|
197
|
-
|
|
341
|
+
if (!param)
|
|
342
|
+
return false;
|
|
343
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
344
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(param));
|
|
198
345
|
this.type_validator.push(type);
|
|
199
346
|
break;
|
|
200
347
|
case protocol_1.ValueType.TYPE_STATIC_u64:
|
|
201
|
-
|
|
202
|
-
|
|
348
|
+
if (!param)
|
|
349
|
+
return false;
|
|
350
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
351
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u64(param));
|
|
203
352
|
this.type_validator.push(type);
|
|
204
353
|
break;
|
|
205
354
|
case protocol_1.ValueType.TYPE_STATIC_vec_u8:
|
|
206
|
-
|
|
207
|
-
|
|
355
|
+
if (!param)
|
|
356
|
+
return false;
|
|
357
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
358
|
+
this.data.push(utils_2.BCS_CONVERT.ser_string(param));
|
|
208
359
|
this.type_validator.push(type);
|
|
209
360
|
// this.data[this.data.length-1].forEach((item : number) => console.log(item))
|
|
210
361
|
break;
|
|
211
362
|
case protocol_1.ContextType.TYPE_CONTEXT_SIGNER:
|
|
212
|
-
this.data.push(
|
|
363
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
213
364
|
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_address);
|
|
214
365
|
break;
|
|
215
366
|
case protocol_1.ContextType.TYPE_CONTEXT_CLOCK:
|
|
216
|
-
this.data.push(
|
|
367
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
217
368
|
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_u64);
|
|
218
369
|
break;
|
|
370
|
+
case protocol_1.ContextType.TYPE_CONTEXT_bool:
|
|
371
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u8:
|
|
372
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u64:
|
|
373
|
+
case protocol_1.ContextType.TYPE_CONTEXT_vec_u8:
|
|
374
|
+
case protocol_1.ContextType.TYPE_CONTEXT_address:
|
|
219
375
|
case protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
376
|
+
if (!variable || !param)
|
|
377
|
+
return false;
|
|
378
|
+
if (typeof (param) != 'number')
|
|
379
|
+
return false;
|
|
380
|
+
if (!(0, protocol_1.IsValidInt)(param) || param > 255)
|
|
381
|
+
return false;
|
|
382
|
+
var v = variable.get(param);
|
|
383
|
+
if (v?.type == type) {
|
|
384
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type));
|
|
385
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(param));
|
|
386
|
+
if (type == protocol_1.ContextType.TYPE_CONTEXT_bool) {
|
|
387
|
+
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_bool);
|
|
388
|
+
}
|
|
389
|
+
else if (type == protocol_1.ContextType.TYPE_CONTEXT_u8) {
|
|
390
|
+
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_u8);
|
|
391
|
+
}
|
|
392
|
+
else if (type == protocol_1.ContextType.TYPE_CONTEXT_u64) {
|
|
393
|
+
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_u64);
|
|
394
|
+
}
|
|
395
|
+
else if (type == protocol_1.ContextType.TYPE_CONTEXT_vec_u8) {
|
|
396
|
+
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_vec_u8);
|
|
397
|
+
}
|
|
398
|
+
else if (type == protocol_1.ContextType.TYPE_CONTEXT_address) {
|
|
399
|
+
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_address);
|
|
400
|
+
}
|
|
401
|
+
else if (type == protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID) {
|
|
402
|
+
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_address);
|
|
403
|
+
}
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
;
|
|
407
|
+
return false;
|
|
224
408
|
default:
|
|
225
409
|
return false;
|
|
226
410
|
}
|
|
@@ -235,18 +419,43 @@ class SenseMaker {
|
|
|
235
419
|
}
|
|
236
420
|
return -1;
|
|
237
421
|
}
|
|
238
|
-
|
|
239
|
-
// TYPE_FUTURE_ORDER_DYNAMIC_QUERY: object_address: service/machine id; module:order/progress
|
|
240
|
-
add_query(type, object_address, module, query_name) {
|
|
422
|
+
add_future_query(identifier, module, query_name, variable) {
|
|
241
423
|
let query_index = this.query_index(module, query_name);
|
|
242
|
-
if (!
|
|
424
|
+
if (!(0, exports.IsValidIndentifier)(identifier) || query_index == -1)
|
|
425
|
+
return false;
|
|
426
|
+
if (module != protocol_1.MODULES.order && module != protocol_1.MODULES.progress)
|
|
427
|
+
return false;
|
|
428
|
+
if (!variable || variable.get(identifier)?.type != protocol_1.OperatorType.TYPE_FUTURE_QUERY)
|
|
429
|
+
return false;
|
|
430
|
+
let offset = this.type_validator.length - exports.QUERIES[query_index][3].length;
|
|
431
|
+
if (offset < 0) {
|
|
243
432
|
return false;
|
|
244
433
|
}
|
|
245
|
-
|
|
246
|
-
if (
|
|
434
|
+
let types = this.type_validator.slice(offset);
|
|
435
|
+
if (!(0, utils_1.array_equal)(types, exports.QUERIES[query_index][3])) { // type validate
|
|
247
436
|
return false;
|
|
248
|
-
|
|
437
|
+
}
|
|
438
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(protocol_1.OperatorType.TYPE_FUTURE_QUERY)); // TYPE
|
|
439
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(identifier)); // variable identifier
|
|
440
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(exports.QUERIES[query_index][2])); // cmd
|
|
441
|
+
this.type_validator.splice(offset, exports.QUERIES[query_index][3].length); // delete type stack
|
|
442
|
+
this.type_validator.push(exports.QUERIES[query_index][4]); // add the return value type to type stack
|
|
443
|
+
// console.log(this.type_validator)
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
// object_address_from: string for static address; number as identifier for variable
|
|
447
|
+
add_query(module, query_name, object_address_from) {
|
|
448
|
+
let query_index = this.query_index(module, query_name); // query_index: index(from 0) of array QUERIES
|
|
449
|
+
if (query_index == -1)
|
|
249
450
|
return false;
|
|
451
|
+
if (typeof (object_address_from) == 'number') {
|
|
452
|
+
if (!(0, exports.IsValidIndentifier)(object_address_from))
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
if (!(0, protocol_1.IsValidAddress)(object_address_from))
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
250
459
|
let offset = this.type_validator.length - exports.QUERIES[query_index][3].length;
|
|
251
460
|
if (offset < 0) {
|
|
252
461
|
return false;
|
|
@@ -255,10 +464,15 @@ class SenseMaker {
|
|
|
255
464
|
if (!(0, utils_1.array_equal)(types, exports.QUERIES[query_index][3])) { // type validate
|
|
256
465
|
return false;
|
|
257
466
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
467
|
+
if (typeof (object_address_from) == 'string') {
|
|
468
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(protocol_1.OperatorType.TYPE_QUERY)); // TYPE
|
|
469
|
+
this.data.push(utils_2.BCS_CONVERT.ser_address(object_address_from)); // object address
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT)); // TYPE
|
|
473
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(object_address_from)); // object identifer in variables
|
|
474
|
+
}
|
|
475
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(exports.QUERIES[query_index][2])); // cmd
|
|
262
476
|
this.type_validator.splice(offset, exports.QUERIES[query_index][3].length); // delete type stack
|
|
263
477
|
this.type_validator.push(exports.QUERIES[query_index][4]); // add the return value type to type stack
|
|
264
478
|
// console.log(this.type_validator)
|
|
@@ -290,8 +504,7 @@ class SenseMaker {
|
|
|
290
504
|
default:
|
|
291
505
|
return false;
|
|
292
506
|
}
|
|
293
|
-
|
|
294
|
-
this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes()); // TYPE
|
|
507
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type)); // TYPE
|
|
295
508
|
this.type_validator.splice(this.type_validator.length - 2); // delete type stack
|
|
296
509
|
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_bool); // add bool to type stack
|
|
297
510
|
return true;
|
|
@@ -300,7 +513,7 @@ class SenseMaker {
|
|
|
300
513
|
//console.log(this.type_validator);
|
|
301
514
|
//this.data.forEach((value:Uint8Array) => console.log(value));
|
|
302
515
|
if (this.type_validator.length != 1 || this.type_validator[0] != protocol_1.ValueType.TYPE_STATIC_bool) {
|
|
303
|
-
|
|
516
|
+
console.log(this.type_validator);
|
|
304
517
|
return false;
|
|
305
518
|
} // ERROR
|
|
306
519
|
let input = (0, utils_1.concatenate)(Uint8Array, ...this.data);
|
|
@@ -317,22 +530,16 @@ function match_u128(type) {
|
|
|
317
530
|
}
|
|
318
531
|
return false;
|
|
319
532
|
}
|
|
320
|
-
function parse_graphql_senses(senses) {
|
|
533
|
+
function parse_graphql_senses(guardid, senses) {
|
|
321
534
|
let objects = [];
|
|
322
535
|
senses.forEach((s) => {
|
|
323
|
-
let res = parse_sense_bsc(Uint8Array.from(s.input.bytes));
|
|
324
|
-
if (res) {
|
|
325
|
-
objects = objects.concat(res);
|
|
326
|
-
}
|
|
536
|
+
let res = parse_sense_bsc(objects, guardid, Uint8Array.from(s.input.bytes));
|
|
327
537
|
});
|
|
328
|
-
return
|
|
538
|
+
return objects;
|
|
329
539
|
}
|
|
330
540
|
exports.parse_graphql_senses = parse_graphql_senses;
|
|
331
|
-
|
|
332
|
-
function parse_sense_bsc(chain_sense_bsc, future_order, future_progress) {
|
|
541
|
+
function parse_futures(result, guardid, chain_sense_bsc, variable) {
|
|
333
542
|
var arr = [].slice.call(chain_sense_bsc.reverse());
|
|
334
|
-
const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
|
|
335
|
-
var result = [];
|
|
336
543
|
while (arr.length > 0) {
|
|
337
544
|
var type = arr.shift();
|
|
338
545
|
// console.log(type);
|
|
@@ -349,8 +556,86 @@ function parse_sense_bsc(chain_sense_bsc, future_order, future_progress) {
|
|
|
349
556
|
case protocol_1.OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
350
557
|
break;
|
|
351
558
|
case protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
|
|
559
|
+
case protocol_1.OperatorType.TYPE_FUTURE_QUERY:
|
|
560
|
+
var identifer = arr.splice(0, 1);
|
|
561
|
+
if (type == protocol_1.OperatorType.TYPE_FUTURE_QUERY) {
|
|
562
|
+
arr.splice(0, 1); // cmd
|
|
563
|
+
}
|
|
564
|
+
if (!variable || variable?.get(identifer[0])?.type != type)
|
|
565
|
+
return false;
|
|
566
|
+
let witness = get_variable_witness(variable, identifer[0], type);
|
|
567
|
+
if (!witness)
|
|
568
|
+
return false;
|
|
569
|
+
result.push({ guardid: guardid, identifier: identifer[0], type: type,
|
|
570
|
+
witness: '0x' + utils_2.BCS_CONVERT.de(bcs_1.BCS.ADDRESS, Uint8Array.from(witness)) });
|
|
571
|
+
break;
|
|
572
|
+
case protocol_1.ContextType.TYPE_CONTEXT_address:
|
|
573
|
+
case protocol_1.ContextType.TYPE_CONTEXT_bool:
|
|
574
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u8:
|
|
575
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u64:
|
|
576
|
+
case protocol_1.ContextType.TYPE_CONTEXT_vec_u8:
|
|
577
|
+
case protocol_1.ValueType.TYPE_STATIC_bool:
|
|
578
|
+
case protocol_1.ValueType.TYPE_STATIC_u8:
|
|
579
|
+
arr.splice(0, 1); // identifier
|
|
580
|
+
break;
|
|
581
|
+
case protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
582
|
+
arr.splice(0, 2); // identifer + cmd
|
|
583
|
+
case protocol_1.ValueType.TYPE_STATIC_address:
|
|
352
584
|
arr.splice(0, 32);
|
|
353
585
|
break;
|
|
586
|
+
case protocol_1.ValueType.TYPE_STATIC_u64:
|
|
587
|
+
arr.splice(0, 8);
|
|
588
|
+
break;
|
|
589
|
+
case protocol_1.ValueType.TYPE_STATIC_u128:
|
|
590
|
+
arr.splice(0, 16);
|
|
591
|
+
break;
|
|
592
|
+
case protocol_1.ValueType.TYPE_STATIC_vec_u8:
|
|
593
|
+
let { value, length } = (0, utils_1.ulebDecode)(Uint8Array.from(arr));
|
|
594
|
+
arr.splice(0, value + length);
|
|
595
|
+
break;
|
|
596
|
+
case protocol_1.OperatorType.TYPE_QUERY:
|
|
597
|
+
arr.splice(0, 33); // address + cmd
|
|
598
|
+
break;
|
|
599
|
+
default:
|
|
600
|
+
console.error('parse_sense_bsc:undefined');
|
|
601
|
+
console.log(type);
|
|
602
|
+
console.log(arr);
|
|
603
|
+
return false; // error
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
exports.parse_futures = parse_futures;
|
|
609
|
+
// parse guard senses input bytes of a guard, return [objectids] for 'query_cmd'
|
|
610
|
+
function parse_sense_bsc(result, guardid, chain_sense_bsc, variable) {
|
|
611
|
+
var arr = [].slice.call(chain_sense_bsc.reverse());
|
|
612
|
+
while (arr.length > 0) {
|
|
613
|
+
var type = arr.shift();
|
|
614
|
+
// console.log(type);
|
|
615
|
+
switch (type) {
|
|
616
|
+
case protocol_1.ContextType.TYPE_CONTEXT_SIGNER:
|
|
617
|
+
case protocol_1.ContextType.TYPE_CONTEXT_CLOCK:
|
|
618
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
|
|
619
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
|
|
620
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
|
|
621
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
|
|
622
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
|
|
623
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
|
|
624
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
|
|
625
|
+
case protocol_1.OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
626
|
+
break;
|
|
627
|
+
case protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
|
|
628
|
+
var v = arr.splice(0, 1);
|
|
629
|
+
if (!variable || variable?.get(v[0])?.type != type)
|
|
630
|
+
return false;
|
|
631
|
+
break;
|
|
632
|
+
case protocol_1.ContextType.TYPE_CONTEXT_address:
|
|
633
|
+
case protocol_1.ContextType.TYPE_CONTEXT_bool:
|
|
634
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u8:
|
|
635
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u64:
|
|
636
|
+
case protocol_1.ContextType.TYPE_CONTEXT_vec_u8:
|
|
637
|
+
arr.splice(0, 1); // identifier
|
|
638
|
+
break;
|
|
354
639
|
case protocol_1.ValueType.TYPE_STATIC_address:
|
|
355
640
|
//console.log('0x' + bcs.de(BCS.ADDRESS, Uint8Array.from(array)).toString());
|
|
356
641
|
arr.splice(0, 32);
|
|
@@ -369,28 +654,23 @@ function parse_sense_bsc(chain_sense_bsc, future_order, future_progress) {
|
|
|
369
654
|
let { value, length } = (0, utils_1.ulebDecode)(Uint8Array.from(arr));
|
|
370
655
|
arr.splice(0, value + length);
|
|
371
656
|
break;
|
|
372
|
-
case protocol_1.OperatorType.
|
|
373
|
-
result.push('0x' +
|
|
657
|
+
case protocol_1.OperatorType.TYPE_QUERY:
|
|
658
|
+
result.push('0x' + utils_2.BCS_CONVERT.de(bcs_1.BCS.ADDRESS, Uint8Array.from(arr)).toString());
|
|
374
659
|
arr.splice(0, 33); // address + cmd
|
|
375
660
|
break;
|
|
376
|
-
case protocol_1.OperatorType.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (!future_order) {
|
|
387
|
-
console.error('OperatorType.TYPE_FUTURE_ORDER_DYNAMIC_QUERY need object');
|
|
388
|
-
console.log(arr);
|
|
389
|
-
return false; // error
|
|
661
|
+
case protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
662
|
+
case protocol_1.OperatorType.TYPE_FUTURE_QUERY:
|
|
663
|
+
var identifer = arr.splice(0, 1);
|
|
664
|
+
if (variable) {
|
|
665
|
+
let v = get_variable_value(variable, identifer[0], type);
|
|
666
|
+
if (v) {
|
|
667
|
+
result.push('0x' + utils_2.BCS_CONVERT.de(bcs_1.BCS.ADDRESS, Uint8Array.from(v)).toString());
|
|
668
|
+
arr.splice(0, 1); // splice cmd
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
390
671
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
break;
|
|
672
|
+
;
|
|
673
|
+
return false;
|
|
394
674
|
default:
|
|
395
675
|
console.error('parse_sense_bsc:undefined');
|
|
396
676
|
console.log(type);
|
|
@@ -398,7 +678,7 @@ function parse_sense_bsc(chain_sense_bsc, future_order, future_progress) {
|
|
|
398
678
|
return false; // error
|
|
399
679
|
}
|
|
400
680
|
}
|
|
401
|
-
return
|
|
681
|
+
return true;
|
|
402
682
|
}
|
|
403
683
|
exports.parse_sense_bsc = parse_sense_bsc;
|
|
404
684
|
const rpc_description_fn = (response, param, option) => {
|
|
@@ -418,13 +698,33 @@ const rpc_sense_objects_fn = (response, param, option) => {
|
|
|
418
698
|
let c = response?.data?.content;
|
|
419
699
|
let index = (0, protocol_1.OBJECTS_TYPE)().findIndex(v => v.includes('guard::Guard') && v == c.type);
|
|
420
700
|
if (index >= 0 && c.fields.id.id == param.objectid) { // GUARD OBJECT
|
|
701
|
+
if (!param?.variables) {
|
|
702
|
+
let v = new Map();
|
|
703
|
+
for (let i = 0; i < c.fields.variables.length; i++) {
|
|
704
|
+
let variable = c.fields.variables[i];
|
|
705
|
+
let bret;
|
|
706
|
+
if (variable.type == ((0, protocol_1.OBJECTS_TYPE_PREFIX)()[index] + 'Variable')) { // ...::guard::Variable
|
|
707
|
+
if (variable.fields.type == protocol_1.OperatorType.TYPE_FUTURE_QUERY || variable.fields.type == protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID) {
|
|
708
|
+
bret = add_future_variable(v, variable.fields.identifier, variable.fields.type, variable.fields?.value ? Uint8Array.from(variable.fields.value) : undefined, undefined, false);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
bret = add_variable(v, variable.fields.identifier, variable.fields.type, variable.fields?.value ? Uint8Array.from(variable.fields.value) : undefined, false);
|
|
712
|
+
}
|
|
713
|
+
if (!bret) {
|
|
714
|
+
console.log('rpc_sense_objects_fn add_variable error');
|
|
715
|
+
console.log(variable);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
param.variables = v;
|
|
721
|
+
}
|
|
421
722
|
for (let i = 0; i < c.fields.senses.length; i++) {
|
|
422
723
|
let sense = c.fields.senses[i];
|
|
423
724
|
if (sense.type == ((0, protocol_1.OBJECTS_TYPE_PREFIX)()[index] + 'Sense')) { // ...::guard::Sense
|
|
424
|
-
let
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
param.data = param.data.concat(ids); // DONT array_unique senses
|
|
725
|
+
let result = [];
|
|
726
|
+
if (param?.parser && param.parser(result, param.objectid, Uint8Array.from(sense.fields.input.fields.bytes), param.variables)) {
|
|
727
|
+
param.data = param.data.concat(result); // DONT array_unique senses
|
|
428
728
|
}
|
|
429
729
|
}
|
|
430
730
|
}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.service_publish = exports.service_pause = exports.service_discount_transfer = exports.service_remove_customer_required = exports.service_change_required_pubkey = exports.service_change_order_required_pubkey = exports.service_clone = exports.service_add_withdraw_guards = exports.service_add_stock = exports.service_add_sale = exports.service_add_refund_guards = exports.service = exports.next = exports.MAX_NAMED_OPERATOR_COUNT = exports.progress_set_namedOperator = exports.hold = exports.progress_unhold = exports.progress_set_context_repository = exports.progress_parent = exports.progress_bind_task = exports.progress = exports.
|
|
17
|
+
exports.service_publish = exports.service_pause = exports.service_discount_transfer = exports.service_remove_customer_required = exports.service_change_required_pubkey = exports.service_change_order_required_pubkey = exports.service_clone = exports.service_add_withdraw_guards = exports.service_add_stock = exports.service_add_sale = exports.service_add_refund_guards = exports.service = exports.next = exports.MAX_NAMED_OPERATOR_COUNT = exports.progress_set_namedOperator = exports.hold = exports.progress_unhold = exports.progress_set_context_repository = exports.progress_parent = exports.progress_bind_task = exports.progress = exports.OPERATOR_ORDER_PAYER = exports.INITIAL_NODE_NAME = exports.machine_change_permission = exports.machine_destroy = exports.machine_launch = exports.machine_set_endpoint = exports.machine_set_description = exports.machine_remove_repository = exports.machine_remove_node = exports.machine_publish = exports.machine_pause = exports.machine_clone = exports.machine_add_repository = exports.machine_add_node2 = exports.machine_add_node = exports.machine = exports.MAX_PRESENTERS_COUNT = exports.MAX_EARNEST_COUNT = exports.demand_change_permission = exports.present = exports.demand_launch = exports.demand_destroy = exports.demand_deposit = exports.demand_yes = exports.demand_set_guard = exports.demand_set_description = exports.demand_refund = exports.demand_expand_time = exports.demand = void 0;
|
|
18
18
|
exports.remove_entity = exports.remove_admin = exports.add_entity = exports.add_admin = exports.MAX_PERMISSION_INDEX_COUNT = exports.IsValidPermissionIndex = exports.PermissionIndex = exports.permission = exports.stringToUint8Array = exports.objectids_from_response = exports.Object_Type_Extra = exports.Bcs = exports.concatenate = exports.array_equal = exports.array_unique = exports.reward_change_permission = exports.MAX_PORTIONS_COUNT = exports.reward_deposit = exports.reward_destroy = exports.reward_launch = exports.reward_set_description = exports.reward_remove_guard = exports.reward_refund = exports.reward_lock_guards = exports.reward_expand_time = exports.reward_add_guard = exports.reward = exports.MAX_DISCOUNT_COUNT_ONCE = exports.MAX_DISCOUNT_RECEIVER_COUNT = exports.service_launch = exports.update_order_required_info = exports.service_change_permission = exports.buy = exports.order_bind_service_machine = exports.Service_Discount_Type = exports.service_withdraw = exports.service_set_stock = exports.service_set_price = exports.service_set_payee = exports.service_set_machine = exports.service_set_endpoint = exports.service_set_description = exports.service_set_customer_required = exports.service_set_buy_guard = exports.service_repository_remove = exports.service_repository_add = exports.service_remove_withdraw_guards = exports.service_remove_sales = exports.service_remove_refund_guards = exports.service_reduce_stock = void 0;
|
|
19
19
|
exports.vote_change_permission = exports.vote_destroy = exports.vote_launch = exports.vote_set_reference = exports.vote_set_max_choice_count = exports.vote_set_description = exports.vote_remove_option = exports.vote_remove_guard = exports.vote_open_voting = exports.vote_lock_guard = exports.vote_lock_deadline = exports.vote_expand_deadline = exports.vote_add_option = exports.vote_add_guard = exports.vote = exports.repository_change_permission = exports.Repository_Policy_Mode = exports.repository_destroy = exports.repository_launch = exports.repository_set_policy_permission = exports.repository_set_policy_mode = exports.repository_set_policy_description = exports.repository_set_description = exports.repository_remove_policies = exports.repository_add_policies = exports.remove = exports.repository = exports.QUERIES = exports.guard_launch = exports.Guard_Sense_Binder = exports.permission_launch = exports.permission_destroy = exports.change_owner = exports.MAX_ENTITY_COUNT = exports.MAX_ADMIN_COUNT = exports.remove_index = void 0;
|
|
20
20
|
__exportStar(require("./protocol"), exports);
|
|
@@ -49,7 +49,7 @@ Object.defineProperty(exports, "machine_launch", { enumerable: true, get: functi
|
|
|
49
49
|
Object.defineProperty(exports, "machine_destroy", { enumerable: true, get: function () { return machine_1.destroy; } });
|
|
50
50
|
Object.defineProperty(exports, "machine_change_permission", { enumerable: true, get: function () { return machine_1.change_permission; } });
|
|
51
51
|
Object.defineProperty(exports, "INITIAL_NODE_NAME", { enumerable: true, get: function () { return machine_1.INITIAL_NODE_NAME; } });
|
|
52
|
-
Object.defineProperty(exports, "
|
|
52
|
+
Object.defineProperty(exports, "OPERATOR_ORDER_PAYER", { enumerable: true, get: function () { return machine_1.OPERATOR_ORDER_PAYER; } });
|
|
53
53
|
var progress_1 = require("./progress");
|
|
54
54
|
Object.defineProperty(exports, "progress", { enumerable: true, get: function () { return progress_1.progress; } });
|
|
55
55
|
Object.defineProperty(exports, "progress_bind_task", { enumerable: true, get: function () { return progress_1.progress_bind_task; } });
|