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/README.md +1 -1
- package/dist/demand.js +4 -4
- package/dist/guard.js +377 -51
- package/dist/index.js +122 -2
- package/dist/machine.js +10 -10
- package/dist/passport.js +53 -27
- package/dist/permission.js +5 -5
- package/dist/progress.js +5 -5
- package/dist/protocol.js +53 -30
- package/dist/repository.js +5 -5
- package/dist/reward.js +5 -5
- package/dist/service.js +92 -56
- package/dist/utils.js +201 -0
- package/dist/vote.js +10 -10
- package/package.json +20 -4
- package/src/demand.ts +4 -4
- package/src/guard.ts +366 -50
- package/src/index.ts +2 -1
- package/src/machine.ts +1 -2
- package/src/passport.ts +64 -31
- package/src/progress.ts +2 -2
- package/src/protocol.ts +52 -28
- package/src/service.ts +62 -36
- package/src/utils.ts +48 -2
package/README.md
CHANGED
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
|
-
const
|
|
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,47 +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
|
-
case protocol_1.ContextType.
|
|
216
|
-
this.data.push(
|
|
366
|
+
case protocol_1.ContextType.TYPE_CONTEXT_CLOCK:
|
|
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;
|
|
219
|
-
case protocol_1.ContextType.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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:
|
|
375
|
+
case protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID:
|
|
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;
|
|
223
408
|
default:
|
|
224
409
|
return false;
|
|
225
410
|
}
|
|
@@ -234,24 +419,60 @@ class SenseMaker {
|
|
|
234
419
|
}
|
|
235
420
|
return -1;
|
|
236
421
|
}
|
|
237
|
-
|
|
238
|
-
add_query(object_address, module, query_name) {
|
|
422
|
+
add_future_query(identifier, module, query_name, variable) {
|
|
239
423
|
let query_index = this.query_index(module, query_name);
|
|
240
|
-
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) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
let types = this.type_validator.slice(offset);
|
|
435
|
+
if (!(0, utils_1.array_equal)(types, exports.QUERIES[query_index][3])) { // type validate
|
|
241
436
|
return false;
|
|
242
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)
|
|
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
|
+
}
|
|
243
459
|
let offset = this.type_validator.length - exports.QUERIES[query_index][3].length;
|
|
244
460
|
if (offset < 0) {
|
|
245
461
|
return false;
|
|
246
462
|
}
|
|
247
463
|
let types = this.type_validator.slice(offset);
|
|
248
|
-
if (!(0,
|
|
464
|
+
if (!(0, utils_1.array_equal)(types, exports.QUERIES[query_index][3])) { // type validate
|
|
249
465
|
return false;
|
|
250
466
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
|
255
476
|
this.type_validator.splice(offset, exports.QUERIES[query_index][3].length); // delete type stack
|
|
256
477
|
this.type_validator.push(exports.QUERIES[query_index][4]); // add the return value type to type stack
|
|
257
478
|
// console.log(this.type_validator)
|
|
@@ -283,8 +504,7 @@ class SenseMaker {
|
|
|
283
504
|
default:
|
|
284
505
|
return false;
|
|
285
506
|
}
|
|
286
|
-
|
|
287
|
-
this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes()); // TYPE
|
|
507
|
+
this.data.push(utils_2.BCS_CONVERT.ser_u8(type)); // TYPE
|
|
288
508
|
this.type_validator.splice(this.type_validator.length - 2); // delete type stack
|
|
289
509
|
this.type_validator.push(protocol_1.ValueType.TYPE_STATIC_bool); // add bool to type stack
|
|
290
510
|
return true;
|
|
@@ -296,7 +516,7 @@ class SenseMaker {
|
|
|
296
516
|
// console.log(this.type_validator)
|
|
297
517
|
return false;
|
|
298
518
|
} // ERROR
|
|
299
|
-
let input = (0,
|
|
519
|
+
let input = (0, utils_1.concatenate)(Uint8Array, ...this.data);
|
|
300
520
|
const sense = { input: input, notAfterSense: bNotAfterSense, binder: binder };
|
|
301
521
|
return sense;
|
|
302
522
|
}
|
|
@@ -310,29 +530,90 @@ function match_u128(type) {
|
|
|
310
530
|
}
|
|
311
531
|
return false;
|
|
312
532
|
}
|
|
313
|
-
function parse_graphql_senses(senses) {
|
|
533
|
+
function parse_graphql_senses(guardid, senses) {
|
|
314
534
|
let objects = [];
|
|
315
535
|
senses.forEach((s) => {
|
|
316
|
-
let res = parse_sense_bsc(Uint8Array.from(s.input.bytes));
|
|
317
|
-
if (res) {
|
|
318
|
-
objects = objects.concat(res);
|
|
319
|
-
}
|
|
536
|
+
let res = parse_sense_bsc(objects, guardid, Uint8Array.from(s.input.bytes));
|
|
320
537
|
});
|
|
321
|
-
return
|
|
538
|
+
return objects;
|
|
322
539
|
}
|
|
323
540
|
exports.parse_graphql_senses = parse_graphql_senses;
|
|
541
|
+
function parse_futures(result, guardid, chain_sense_bsc, variable) {
|
|
542
|
+
var arr = [].slice.call(chain_sense_bsc.reverse());
|
|
543
|
+
while (arr.length > 0) {
|
|
544
|
+
var type = arr.shift();
|
|
545
|
+
// console.log(type);
|
|
546
|
+
switch (type) {
|
|
547
|
+
case protocol_1.ContextType.TYPE_CONTEXT_SIGNER:
|
|
548
|
+
case protocol_1.ContextType.TYPE_CONTEXT_CLOCK:
|
|
549
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
|
|
550
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
|
|
551
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
|
|
552
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
|
|
553
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_EQUAL:
|
|
554
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_EQUAL:
|
|
555
|
+
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
|
|
556
|
+
case protocol_1.OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
557
|
+
break;
|
|
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, witness: Uint8Array.from(witness) });
|
|
570
|
+
break;
|
|
571
|
+
case protocol_1.ContextType.TYPE_CONTEXT_address:
|
|
572
|
+
case protocol_1.ContextType.TYPE_CONTEXT_bool:
|
|
573
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u8:
|
|
574
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u64:
|
|
575
|
+
case protocol_1.ContextType.TYPE_CONTEXT_vec_u8:
|
|
576
|
+
case protocol_1.ValueType.TYPE_STATIC_bool:
|
|
577
|
+
case protocol_1.ValueType.TYPE_STATIC_u8:
|
|
578
|
+
arr.splice(0, 1); // identifier
|
|
579
|
+
break;
|
|
580
|
+
case protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
581
|
+
arr.splice(0, 2); // identifer + cmd
|
|
582
|
+
case protocol_1.ValueType.TYPE_STATIC_address:
|
|
583
|
+
arr.splice(0, 32);
|
|
584
|
+
break;
|
|
585
|
+
case protocol_1.ValueType.TYPE_STATIC_u64:
|
|
586
|
+
arr.splice(0, 8);
|
|
587
|
+
break;
|
|
588
|
+
case protocol_1.ValueType.TYPE_STATIC_u128:
|
|
589
|
+
arr.splice(0, 16);
|
|
590
|
+
break;
|
|
591
|
+
case protocol_1.ValueType.TYPE_STATIC_vec_u8:
|
|
592
|
+
let { value, length } = (0, utils_1.ulebDecode)(Uint8Array.from(arr));
|
|
593
|
+
arr.splice(0, value + length);
|
|
594
|
+
break;
|
|
595
|
+
case protocol_1.OperatorType.TYPE_QUERY:
|
|
596
|
+
arr.splice(0, 33); // address + cmd
|
|
597
|
+
break;
|
|
598
|
+
default:
|
|
599
|
+
console.error('parse_sense_bsc:undefined');
|
|
600
|
+
console.log(type);
|
|
601
|
+
console.log(arr);
|
|
602
|
+
return false; // error
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
exports.parse_futures = parse_futures;
|
|
324
608
|
// parse guard senses input bytes of a guard, return [objectids] for 'query_cmd'
|
|
325
|
-
function parse_sense_bsc(chain_sense_bsc) {
|
|
609
|
+
function parse_sense_bsc(result, guardid, chain_sense_bsc, variable) {
|
|
326
610
|
var arr = [].slice.call(chain_sense_bsc.reverse());
|
|
327
|
-
const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
|
|
328
|
-
var result = [];
|
|
329
611
|
while (arr.length > 0) {
|
|
330
612
|
var type = arr.shift();
|
|
331
613
|
// console.log(type);
|
|
332
614
|
switch (type) {
|
|
333
615
|
case protocol_1.ContextType.TYPE_CONTEXT_SIGNER:
|
|
334
|
-
case protocol_1.ContextType.
|
|
335
|
-
case protocol_1.ContextType.TYPE_CONTEXT_CURRENT_PROGRESS:
|
|
616
|
+
case protocol_1.ContextType.TYPE_CONTEXT_CLOCK:
|
|
336
617
|
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER:
|
|
337
618
|
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
|
|
338
619
|
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_U128_LESSER:
|
|
@@ -342,6 +623,18 @@ function parse_sense_bsc(chain_sense_bsc) {
|
|
|
342
623
|
case protocol_1.OperatorType.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
|
|
343
624
|
case protocol_1.OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
344
625
|
break;
|
|
626
|
+
case protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID: // MACHINE-ID
|
|
627
|
+
var v = arr.splice(0, 1);
|
|
628
|
+
if (!variable || variable?.get(v[0])?.type != type)
|
|
629
|
+
return false;
|
|
630
|
+
break;
|
|
631
|
+
case protocol_1.ContextType.TYPE_CONTEXT_address:
|
|
632
|
+
case protocol_1.ContextType.TYPE_CONTEXT_bool:
|
|
633
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u8:
|
|
634
|
+
case protocol_1.ContextType.TYPE_CONTEXT_u64:
|
|
635
|
+
case protocol_1.ContextType.TYPE_CONTEXT_vec_u8:
|
|
636
|
+
arr.splice(0, 1); // identifier
|
|
637
|
+
break;
|
|
345
638
|
case protocol_1.ValueType.TYPE_STATIC_address:
|
|
346
639
|
//console.log('0x' + bcs.de(BCS.ADDRESS, Uint8Array.from(array)).toString());
|
|
347
640
|
arr.splice(0, 32);
|
|
@@ -357,13 +650,26 @@ function parse_sense_bsc(chain_sense_bsc) {
|
|
|
357
650
|
arr.splice(0, 16);
|
|
358
651
|
break;
|
|
359
652
|
case protocol_1.ValueType.TYPE_STATIC_vec_u8:
|
|
360
|
-
let { value, length } = (0,
|
|
653
|
+
let { value, length } = (0, utils_1.ulebDecode)(Uint8Array.from(arr));
|
|
361
654
|
arr.splice(0, value + length);
|
|
362
655
|
break;
|
|
363
|
-
case protocol_1.OperatorType.
|
|
364
|
-
result.push('0x' +
|
|
656
|
+
case protocol_1.OperatorType.TYPE_QUERY:
|
|
657
|
+
result.push('0x' + utils_2.BCS_CONVERT.de(bcs_1.BCS.ADDRESS, Uint8Array.from(arr)).toString());
|
|
365
658
|
arr.splice(0, 33); // address + cmd
|
|
366
659
|
break;
|
|
660
|
+
case protocol_1.OperatorType.TYPE_QUERY_FROM_CONTEXT:
|
|
661
|
+
case protocol_1.OperatorType.TYPE_FUTURE_QUERY:
|
|
662
|
+
var identifer = arr.splice(0, 1);
|
|
663
|
+
if (variable) {
|
|
664
|
+
let v = get_variable_value(variable, identifer[0], type);
|
|
665
|
+
if (v) {
|
|
666
|
+
result.push('0x' + utils_2.BCS_CONVERT.de(bcs_1.BCS.ADDRESS, Uint8Array.from(v)).toString());
|
|
667
|
+
arr.splice(0, 1); // splice cmd
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
;
|
|
672
|
+
return false;
|
|
367
673
|
default:
|
|
368
674
|
console.error('parse_sense_bsc:undefined');
|
|
369
675
|
console.log(type);
|
|
@@ -371,7 +677,7 @@ function parse_sense_bsc(chain_sense_bsc) {
|
|
|
371
677
|
return false; // error
|
|
372
678
|
}
|
|
373
679
|
}
|
|
374
|
-
return
|
|
680
|
+
return true;
|
|
375
681
|
}
|
|
376
682
|
exports.parse_sense_bsc = parse_sense_bsc;
|
|
377
683
|
const rpc_description_fn = (response, param, option) => {
|
|
@@ -391,13 +697,33 @@ const rpc_sense_objects_fn = (response, param, option) => {
|
|
|
391
697
|
let c = response?.data?.content;
|
|
392
698
|
let index = (0, protocol_1.OBJECTS_TYPE)().findIndex(v => v.includes('guard::Guard') && v == c.type);
|
|
393
699
|
if (index >= 0 && c.fields.id.id == param.objectid) { // GUARD OBJECT
|
|
700
|
+
if (!param?.variables) {
|
|
701
|
+
let v = new Map();
|
|
702
|
+
for (let i = 0; i < c.fields.variables.length; i++) {
|
|
703
|
+
let variable = c.fields.variables[i];
|
|
704
|
+
let bret;
|
|
705
|
+
if (variable.type == ((0, protocol_1.OBJECTS_TYPE_PREFIX)()[index] + 'Variable')) { // ...::guard::Variable
|
|
706
|
+
if (variable.fields.type == protocol_1.OperatorType.TYPE_FUTURE_QUERY || variable.fields.type == protocol_1.ContextType.TYPE_CONTEXT_FUTURE_ID) {
|
|
707
|
+
bret = add_future_variable(v, variable.fields.identifier, variable.fields.type, variable.fields?.value, undefined, false);
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
bret = add_variable(v, variable.fields.identifier, variable.fields.type, variable.fields?.value, false);
|
|
711
|
+
}
|
|
712
|
+
if (!bret) {
|
|
713
|
+
console.log('rpc_sense_objects_fn add_variable error');
|
|
714
|
+
console.log(variable);
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
param.variables = v;
|
|
720
|
+
}
|
|
394
721
|
for (let i = 0; i < c.fields.senses.length; i++) {
|
|
395
722
|
let sense = c.fields.senses[i];
|
|
396
723
|
if (sense.type == ((0, protocol_1.OBJECTS_TYPE_PREFIX)()[index] + 'Sense')) { // ...::guard::Sense
|
|
397
|
-
let
|
|
398
|
-
if (
|
|
399
|
-
|
|
400
|
-
param.data = param.data.concat(ids); // DONT array_unique senses
|
|
724
|
+
let result = [];
|
|
725
|
+
if (param?.parser && param.parser(result, param.objectid, Uint8Array.from(sense.fields.input.fields.bytes), param.variables)) {
|
|
726
|
+
param.data = param.data.concat(result); // DONT array_unique senses
|
|
401
727
|
}
|
|
402
728
|
}
|
|
403
729
|
}
|