wowok 1.7.13 → 1.7.16
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/dist/arbitration.d.ts.map +1 -1
- package/dist/arbitration.js +21 -32
- package/dist/arbitration.js.map +1 -1
- package/dist/entity.d.ts +1 -0
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +12 -6
- package/dist/entity.js.map +1 -1
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/exception.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +8 -4
- package/dist/guard.js.map +1 -1
- package/dist/payment.d.ts +2 -2
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +2 -2
- package/dist/payment.js.map +1 -1
- package/dist/protocol.d.ts +21 -19
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +211 -58
- package/dist/protocol.js.map +1 -1
- package/dist/service.d.ts +2 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +5 -6
- package/dist/service.js.map +1 -1
- package/package.json +5 -2
- package/src/arbitration.ts +0 -551
- package/src/demand.ts +0 -300
- package/src/entity.ts +0 -171
- package/src/exception.ts +0 -37
- package/src/guard.ts +0 -810
- package/src/index.ts +0 -40
- package/src/machine.ts +0 -542
- package/src/passport.ts +0 -777
- package/src/payment.ts +0 -94
- package/src/permission.ts +0 -550
- package/src/progress.ts +0 -367
- package/src/protocol.ts +0 -549
- package/src/repository.ts +0 -680
- package/src/resource.ts +0 -155
- package/src/service.ts +0 -1349
- package/src/treasury.ts +0 -425
- package/src/utils.ts +0 -660
- package/src/wowok.ts +0 -70
- package/tsconfig.json +0 -30
- package/tsconfig.tsbuildinfo +0 -1
- package/webpack.config.cjs +0 -23
package/src/passport.ts
DELETED
|
@@ -1,777 +0,0 @@
|
|
|
1
|
-
import { type TransactionObjectInput, Inputs, Transaction as TransactionBlock, TransactionResult, CallArg} from '@mysten/sui/transactions';
|
|
2
|
-
import { SuiObjectResponse } from '@mysten/sui/client';
|
|
3
|
-
import { FnCallType, GuardObject, Protocol, ContextType, OperatorType, Data_Type,
|
|
4
|
-
ValueType, SER_VALUE, IsValidOperatorType } from './protocol.js';
|
|
5
|
-
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, insertAtHead, readOption, readOptionString, deepCopy } from './utils.js';
|
|
6
|
-
import { ERROR, Errors } from './exception.js';
|
|
7
|
-
import { CMD_CHECK_GUARD, Guard, GuardMaker } from './guard.js';
|
|
8
|
-
import { bcs } from '@mysten/sui/bcs';
|
|
9
|
-
|
|
10
|
-
export type Guard_Query_Object = {
|
|
11
|
-
target: FnCallType, // object fnCall
|
|
12
|
-
object: TransactionObjectInput | string, // object
|
|
13
|
-
types: string[], // object type
|
|
14
|
-
id: string, // object id
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface GuardInfo {
|
|
18
|
-
id: string; // guard id
|
|
19
|
-
digest?: string;
|
|
20
|
-
version?: string | number;
|
|
21
|
-
input: DeGuardInput[]; // object or witness object query
|
|
22
|
-
constant: DeGuardConstant[]; // witness in constant & ValueType.TYPE_ADDRESS(for Query)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface DeGuardConstant {
|
|
26
|
-
type: number; //
|
|
27
|
-
value: any; //
|
|
28
|
-
bWitness: boolean;
|
|
29
|
-
identifier: number; // ID
|
|
30
|
-
}
|
|
31
|
-
export interface DeGuardInput {
|
|
32
|
-
type: number; //
|
|
33
|
-
value?: any; //
|
|
34
|
-
identifier?: number; // ID
|
|
35
|
-
cmd?: number; //
|
|
36
|
-
}
|
|
37
|
-
export interface DeGuardData extends DeGuardInput {
|
|
38
|
-
child: DeGuardData[];
|
|
39
|
-
ret_type?: number;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface WitnessFill {
|
|
43
|
-
guard: string;
|
|
44
|
-
witness?: any;
|
|
45
|
-
cmd: number[];
|
|
46
|
-
cited: number;
|
|
47
|
-
type: ValueType;
|
|
48
|
-
identifier: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface PassportQuery {
|
|
52
|
-
query: Guard_Query_Object[];
|
|
53
|
-
info: GuardInfo[];
|
|
54
|
-
}
|
|
55
|
-
export class GuardParser {
|
|
56
|
-
protected guard_list: GuardInfo[] = [];
|
|
57
|
-
protected guards: string[];
|
|
58
|
-
|
|
59
|
-
private constructor(guards: string[]) {
|
|
60
|
-
this.guards = guards;
|
|
61
|
-
}
|
|
62
|
-
guardlist = () => { return this.guard_list }
|
|
63
|
-
|
|
64
|
-
static DeGuardObject_FromData = (guard_constants:any, guard_input_bytes:any) : {object:DeGuardData, constant:DeGuardConstant[]} => {
|
|
65
|
-
let constants : DeGuardConstant[] = GuardParser.parse_constant(guard_constants);
|
|
66
|
-
// console.log(constants)
|
|
67
|
-
|
|
68
|
-
let inputs : DeGuardInput[] = GuardParser.parse_bcs(constants, guard_input_bytes);
|
|
69
|
-
if (!inputs || inputs.length == 0) ERROR(Errors.Fail, 'GuardObject: data parsed error');
|
|
70
|
-
let stack: DeGuardData[] = [];
|
|
71
|
-
inputs.forEach((d) => {
|
|
72
|
-
GuardParser.ResolveData(constants, stack, {...d, child:[]});
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
if (stack.length != 1) {
|
|
76
|
-
ERROR(Errors.Fail, 'GuardObject: parse error');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return {object:stack.pop()!, constant:constants};
|
|
80
|
-
}
|
|
81
|
-
/// convert guard-on-chain to js object
|
|
82
|
-
static DeGuardObject = async (protocol: Protocol, guard: string) : Promise<{object:DeGuardData, constant:DeGuardConstant[]}> => {
|
|
83
|
-
if (!IsValidAddress(guard)) {
|
|
84
|
-
ERROR(Errors.IsValidAddress, 'GuardObject guard')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let res = await protocol.query_raw([guard]);
|
|
88
|
-
if (res.length == 0 || !res[0].data || res[0].data?.objectId != guard) {
|
|
89
|
-
ERROR(Errors.Fail, 'GuardObject query error');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// console.log(res[0].data?.content);
|
|
93
|
-
let content = res[0].data!.content as any;
|
|
94
|
-
if (content?.type != protocol.package('base') + '::guard::Guard') {
|
|
95
|
-
ERROR(Errors.Fail, 'GuardObject object invalid')
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return GuardParser.DeGuardObject_FromData(content.fields.constants, content.fields.input.fields.bytes);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static ResolveData = (constants: DeGuardConstant[], stack:DeGuardData[], current: DeGuardData) => {
|
|
102
|
-
switch (current.type) {
|
|
103
|
-
case OperatorType.TYPE_LOGIC_NOT:
|
|
104
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
105
|
-
if (stack.length < 1) ERROR(Errors.Fail, `ResolveData: TYPE_LOGIC_NOT`);
|
|
106
|
-
|
|
107
|
-
var param = stack.pop() as DeGuardData;
|
|
108
|
-
if (!param.ret_type || param.ret_type != ValueType.TYPE_BOOL) {
|
|
109
|
-
ERROR(Errors.Fail, 'ResolveData: TYPE_LOGIC_NOT type invalid');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
current.child.push(param);
|
|
113
|
-
stack.push(current);
|
|
114
|
-
return;
|
|
115
|
-
case OperatorType.TYPE_NUMBER_ADDRESS:
|
|
116
|
-
current.ret_type = ValueType.TYPE_ADDRESS;
|
|
117
|
-
if (stack.length < 1) ERROR(Errors.Fail, 'ResolveData: TYPE_NUMBER_ADDRESS');
|
|
118
|
-
|
|
119
|
-
var param = stack.pop() as DeGuardData;
|
|
120
|
-
if (!param.ret_type || !GuardMaker.match_u256(param.ret_type)) {
|
|
121
|
-
ERROR(Errors.Fail, 'ResolveData: TYPE_NUMBER_ADDRESS type invalid');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
current.child.push(param);
|
|
125
|
-
stack.push(current);
|
|
126
|
-
return;
|
|
127
|
-
case OperatorType.TYPE_STRING_LOWERCASE:
|
|
128
|
-
current.ret_type = ValueType.TYPE_STRING;
|
|
129
|
-
if (stack.length < 1) ERROR(Errors.Fail, 'ResolveData: TYPE_STRING_LOWERCASE');
|
|
130
|
-
|
|
131
|
-
var param = stack.pop() as DeGuardData;
|
|
132
|
-
if (!param.ret_type || param.ret_type !== ValueType.TYPE_STRING) {
|
|
133
|
-
ERROR(Errors.Fail, 'ResolveData: TYPE_STRING_LOWERCASE type invalid');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
current.child.push(param);
|
|
137
|
-
stack.push(current);
|
|
138
|
-
return;
|
|
139
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
|
|
140
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL:
|
|
141
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
142
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
143
|
-
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
144
|
-
case OperatorType.TYPE_NUMBER_ADD:
|
|
145
|
-
case OperatorType.TYPE_NUMBER_DEVIDE:
|
|
146
|
-
case OperatorType.TYPE_NUMBER_MOD:
|
|
147
|
-
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
148
|
-
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
149
|
-
if (current.type === OperatorType.TYPE_LOGIC_AS_U256_GREATER || current.type === OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL ||
|
|
150
|
-
current.type === OperatorType.TYPE_LOGIC_AS_U256_LESSER || current.type === OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL ||
|
|
151
|
-
current.type === OperatorType.TYPE_LOGIC_AS_U256_EQUAL) {
|
|
152
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
153
|
-
} else {
|
|
154
|
-
current.ret_type = ValueType.TYPE_U256;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
158
|
-
for (let i = 0; i < current.value; ++i) {
|
|
159
|
-
var p = stack.pop() as DeGuardData;
|
|
160
|
-
if (!p.ret_type || !GuardMaker.match_u256(p.ret_type)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
161
|
-
current.child.push(p);
|
|
162
|
-
}
|
|
163
|
-
stack.push(current);
|
|
164
|
-
return
|
|
165
|
-
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
166
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
167
|
-
if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
168
|
-
var p0 = stack.pop() as DeGuardData;
|
|
169
|
-
current.child.push(p0);
|
|
170
|
-
for (let i = 1; i < current.value; ++i) {
|
|
171
|
-
var p = stack.pop() as DeGuardData;
|
|
172
|
-
if (!p.ret_type || (p.ret_type != p0.ret_type)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
173
|
-
current.child.push(p);
|
|
174
|
-
}
|
|
175
|
-
stack.push(current);
|
|
176
|
-
return
|
|
177
|
-
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
178
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
179
|
-
if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
180
|
-
for (let i = 0; i < current.value; ++i) {
|
|
181
|
-
var p = stack.pop() as DeGuardData;
|
|
182
|
-
if (!p.ret_type || (p.ret_type != ValueType.TYPE_STRING)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
183
|
-
current.child.push(p);
|
|
184
|
-
}
|
|
185
|
-
stack.push(current);
|
|
186
|
-
return
|
|
187
|
-
case OperatorType.TYPE_LOGIC_AND:
|
|
188
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
189
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
190
|
-
if (stack.length < current.value || current.value < 2) ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
191
|
-
for (let i = 0; i < current.value; ++i) {
|
|
192
|
-
var p = stack.pop() as DeGuardData;
|
|
193
|
-
if (!p.ret_type || (p.ret_type != ValueType.TYPE_BOOL)) ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
194
|
-
current.child.push(p);
|
|
195
|
-
}
|
|
196
|
-
stack.push(current);
|
|
197
|
-
return
|
|
198
|
-
case OperatorType.TYPE_QUERY:
|
|
199
|
-
if (!current?.cmd) ERROR(Errors.Fail, 'OperateParamCount: cmd invalid ' + current.type);
|
|
200
|
-
let r = Guard.GetCmd(current.cmd!);
|
|
201
|
-
if (!r) ERROR(Errors.Fail, 'OperateParamCount: cmd not supported ' + current.type);
|
|
202
|
-
current.ret_type = r?.return;
|
|
203
|
-
|
|
204
|
-
if (stack.length < r!.parameters.length) ERROR(Errors.Fail, 'OperateParamCount: cmd param lost ' + current.type);
|
|
205
|
-
r!.parameters.forEach((e:number) => {
|
|
206
|
-
let d = stack.pop() as DeGuardData;
|
|
207
|
-
if (!d?.ret_type || d.ret_type != e) {
|
|
208
|
-
ERROR(Errors.Fail, 'OperateParamCount: cmd param not match ' + current.type);
|
|
209
|
-
}
|
|
210
|
-
current.child.push(d)
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
stack.push(current);
|
|
214
|
-
return
|
|
215
|
-
case ValueType.TYPE_ADDRESS:
|
|
216
|
-
case ValueType.TYPE_BOOL:
|
|
217
|
-
case ValueType.TYPE_U128:
|
|
218
|
-
case ValueType.TYPE_U256:
|
|
219
|
-
case ValueType.TYPE_U64:
|
|
220
|
-
case ValueType.TYPE_U8:
|
|
221
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
222
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
223
|
-
case ValueType.TYPE_VEC_U128:
|
|
224
|
-
case ValueType.TYPE_VEC_U256:
|
|
225
|
-
case ValueType.TYPE_VEC_U64:
|
|
226
|
-
case ValueType.TYPE_VEC_U8:
|
|
227
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
228
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
229
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
230
|
-
case ValueType.TYPE_OPTION_U128:
|
|
231
|
-
case ValueType.TYPE_OPTION_U256:
|
|
232
|
-
case ValueType.TYPE_OPTION_U64:
|
|
233
|
-
case ValueType.TYPE_OPTION_U8:
|
|
234
|
-
case ValueType.TYPE_STRING:
|
|
235
|
-
current.ret_type = current.type;
|
|
236
|
-
stack.push(current);
|
|
237
|
-
return;
|
|
238
|
-
case ContextType.TYPE_CLOCK:
|
|
239
|
-
current.ret_type = ValueType.TYPE_U64;
|
|
240
|
-
stack.push(current);
|
|
241
|
-
return;
|
|
242
|
-
case ContextType.TYPE_SIGNER:
|
|
243
|
-
current.ret_type = ValueType.TYPE_ADDRESS;
|
|
244
|
-
stack.push(current);
|
|
245
|
-
return;
|
|
246
|
-
case ContextType.TYPE_GUARD:
|
|
247
|
-
current.ret_type = ValueType.TYPE_ADDRESS;
|
|
248
|
-
stack.push(current);
|
|
249
|
-
return;
|
|
250
|
-
case ContextType.TYPE_CONSTANT:
|
|
251
|
-
let v = constants.find((e) => e.identifier == current?.identifier);
|
|
252
|
-
if (!v) ERROR(Errors.Fail, 'OperateParamCount: identifier invalid ' + current.type);
|
|
253
|
-
|
|
254
|
-
current.ret_type = v?.type;
|
|
255
|
-
stack.push(current);
|
|
256
|
-
return;
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
ERROR(Errors.Fail, 'OperateParamCount: type invalid ' + current.type);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
private static Parse_Guard_Helper(guards: string[], res:SuiObjectResponse[]) : GuardParser{
|
|
263
|
-
const protocol = Protocol.Instance();
|
|
264
|
-
const me = new GuardParser(guards);
|
|
265
|
-
|
|
266
|
-
res.forEach((r) => {
|
|
267
|
-
const c = r.data?.content as any;
|
|
268
|
-
if (!c) ERROR(Errors.Fail, 'Parse_Guard_Helper invalid content');
|
|
269
|
-
const index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => {return v.includes('guard::Guard') && v == c.type});
|
|
270
|
-
if (index === -1) ERROR(Errors.Fail, 'Parse_Guard_Helper invalid type: ' + c.type);
|
|
271
|
-
|
|
272
|
-
if (c.fields.input.type === (protocol.package('base') + '::bcs::BCS')) {
|
|
273
|
-
const constants = GuardParser.parse_constant(c.fields.constants); // MUST first
|
|
274
|
-
const inputs = GuardParser.parse_bcs(constants, Uint8Array.from(c.fields.input.fields.bytes));
|
|
275
|
-
me.guard_list.push({id: c.fields.id.id, input:[...inputs], constant:[...constants], digest:r.data?.digest??'', version:r.data?.version ?? ''});
|
|
276
|
-
} else {
|
|
277
|
-
ERROR(Errors.Fail, 'Parse_Guard_Helper invalid package: '+c.fields.input.type);
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
return me
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
static Create = async (guards: string[]) : Promise<GuardParser | undefined> => {
|
|
284
|
-
if (!IsValidArray(guards, IsValidAddress)) {
|
|
285
|
-
ERROR(Errors.InvalidParam, 'GuardParser.Create: guards invalid');
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
let guard_list = array_unique(guards);
|
|
289
|
-
let check_guards = [...guard_list];
|
|
290
|
-
let i = 0; const parsers : GuardParser[] = [];
|
|
291
|
-
|
|
292
|
-
for (;i < GuardParser.MAX_REPOSITORY_DEPTH; ++i) {
|
|
293
|
-
const res = await Protocol.Instance().query_raw(check_guards);
|
|
294
|
-
const p = GuardParser.Parse_Guard_Helper(guards, res);
|
|
295
|
-
|
|
296
|
-
const repositories: string[] = [];
|
|
297
|
-
p.guardlist().forEach((g) => {
|
|
298
|
-
g.input.forEach((i) => {
|
|
299
|
-
if (i.cmd !== undefined && CMD_CHECK_GUARD.includes(i.cmd)) {
|
|
300
|
-
if (i.identifier !== undefined) {
|
|
301
|
-
const id = g.constant.find((c) => c.identifier === i.identifier);
|
|
302
|
-
if (id && id.value) {
|
|
303
|
-
repositories.push(id.value);
|
|
304
|
-
}
|
|
305
|
-
} else if (i.value) {
|
|
306
|
-
repositories.push(i.value as string);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
parsers.push(p);
|
|
313
|
-
if (repositories.length === 0) {
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
check_guards = await GuardParser.RepositoryGuards(repositories);
|
|
318
|
-
if (check_guards.length === 0) {
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (i >= GuardParser.MAX_REPOSITORY_DEPTH) {
|
|
324
|
-
ERROR(Errors.Fail, `GuardParser.Create: Retrieve guards from the Repository with a maximum depth of more than ${GuardParser.MAX_REPOSITORY_DEPTH} levels.`);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// concatenate all parsers
|
|
328
|
-
for (let i = 1; i < parsers.length; ++i) {
|
|
329
|
-
parsers[0].guard_list = parsers[0].guard_list.concat(deepCopy(parsers[i].guard_list));
|
|
330
|
-
parsers[0].guards = parsers[0].guards.concat(parsers[i].guards);
|
|
331
|
-
}
|
|
332
|
-
if (parsers.length > 0) {
|
|
333
|
-
return parsers[0];
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// fetch repository guards
|
|
338
|
-
static RepositoryGuards = async (repositories: string[]) : Promise<string[]> => {
|
|
339
|
-
const res = await Protocol.Instance().query_raw(repositories);
|
|
340
|
-
const guards : string[] = [];
|
|
341
|
-
for (let i=0; i < res.length; ++i) {
|
|
342
|
-
if ((res[i].data?.content as any)?.fields?.guard) {
|
|
343
|
-
guards.push((res[i].data?.content as any).fields.guard);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return guards;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
future_fills = () : WitnessFill[] => {
|
|
350
|
-
const ret : WitnessFill[] = [];
|
|
351
|
-
this.guard_list.forEach((g) => {
|
|
352
|
-
// cmd already in query_list, so filter it out.
|
|
353
|
-
//console.log(g.constant); console.log(g.input)
|
|
354
|
-
g.constant.filter((i)=>i.bWitness).forEach((v) => {
|
|
355
|
-
const cmd = g.input.filter((k)=>k.identifier === v.identifier && k.cmd !== undefined).map((k)=>k.cmd!);
|
|
356
|
-
let cited = 0;
|
|
357
|
-
g.input.forEach((k) => {
|
|
358
|
-
if (k.identifier === v.identifier) cited ++;
|
|
359
|
-
})
|
|
360
|
-
ret.push({guard:g.id, witness:undefined, identifier:v.identifier, type:v.type, cmd:cmd??[], cited:cited});
|
|
361
|
-
})
|
|
362
|
-
}); return ret;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
static parse_constant = (constants:any) : DeGuardConstant[] => {
|
|
366
|
-
let ret : DeGuardConstant[] = [];
|
|
367
|
-
constants.forEach((c:any) => {
|
|
368
|
-
let v = c?.fields ?? c; // graphql dosnot 'fields', but rpcall has.
|
|
369
|
-
const data:Uint8Array = Uint8Array.from(v.value);
|
|
370
|
-
const type = data.slice(0, 1)[0];
|
|
371
|
-
|
|
372
|
-
if (v.bWitness) { //@ witness
|
|
373
|
-
ret.push({identifier:v.identifier, type:type, bWitness:v.bWitness, value:undefined});
|
|
374
|
-
return
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
var value : any = data.slice(1);
|
|
378
|
-
switch (type) {
|
|
379
|
-
case ValueType.TYPE_ADDRESS:
|
|
380
|
-
value = Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(value)).toString();
|
|
381
|
-
break;
|
|
382
|
-
case ValueType.TYPE_BOOL:
|
|
383
|
-
case ValueType.TYPE_U8:
|
|
384
|
-
case ValueType.TYPE_U64:
|
|
385
|
-
case ValueType.TYPE_U128:
|
|
386
|
-
case ValueType.TYPE_U256:
|
|
387
|
-
case ValueType.TYPE_VEC_U8:
|
|
388
|
-
case ValueType.TYPE_VEC_U64:
|
|
389
|
-
case ValueType.TYPE_VEC_U128:
|
|
390
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
391
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
392
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
393
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
394
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
395
|
-
case ValueType.TYPE_OPTION_U128:
|
|
396
|
-
case ValueType.TYPE_OPTION_U8:
|
|
397
|
-
case ValueType.TYPE_OPTION_U64:
|
|
398
|
-
case ValueType.TYPE_OPTION_U256:
|
|
399
|
-
case ValueType.TYPE_VEC_U256:
|
|
400
|
-
case ValueType.TYPE_STRING:
|
|
401
|
-
case ValueType.TYPE_OPTION_STRING:
|
|
402
|
-
case ValueType.TYPE_OPTION_VEC_U8:
|
|
403
|
-
case ValueType.TYPE_VEC_STRING:
|
|
404
|
-
let de = SER_VALUE.find(s=>s.type==type);
|
|
405
|
-
if (!de) ERROR(Errors.Fail, 'GuardObject de error')
|
|
406
|
-
value = Bcs.getInstance().de(type as number, Uint8Array.from(value));
|
|
407
|
-
break;
|
|
408
|
-
|
|
409
|
-
default:
|
|
410
|
-
ERROR(Errors.Fail, 'GuardObject constant type invalid:' +type)
|
|
411
|
-
}
|
|
412
|
-
ret.push({identifier:v.identifier, type:type, bWitness:v.bWitness, value:value});
|
|
413
|
-
});
|
|
414
|
-
return ret;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
static parse_bcs = (constants: DeGuardConstant[], chain_bytes: Uint8Array) : DeGuardInput[] => {
|
|
418
|
-
let bytes = Uint8Array.from(chain_bytes);
|
|
419
|
-
let arr = [].slice.call(bytes.reverse());
|
|
420
|
-
let data : DeGuardInput[] = [];
|
|
421
|
-
while (arr.length > 0) {
|
|
422
|
-
let type : unknown = arr.shift() ;
|
|
423
|
-
let value:any; let cmd:any; let identifier:any;
|
|
424
|
-
switch (type as Data_Type) {
|
|
425
|
-
case ContextType.TYPE_SIGNER:
|
|
426
|
-
case ContextType.TYPE_CLOCK:
|
|
427
|
-
case ContextType.TYPE_GUARD:
|
|
428
|
-
case OperatorType.TYPE_LOGIC_NOT:
|
|
429
|
-
case OperatorType.TYPE_NUMBER_ADDRESS:
|
|
430
|
-
case OperatorType.TYPE_STRING_LOWERCASE:
|
|
431
|
-
break;
|
|
432
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
|
|
433
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL:
|
|
434
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
435
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
436
|
-
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
437
|
-
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
438
|
-
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
439
|
-
case OperatorType.TYPE_NUMBER_ADD:
|
|
440
|
-
case OperatorType.TYPE_NUMBER_DEVIDE:
|
|
441
|
-
case OperatorType.TYPE_NUMBER_MOD:
|
|
442
|
-
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
443
|
-
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
444
|
-
case OperatorType.TYPE_LOGIC_AND: //@ with logics count
|
|
445
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
446
|
-
value = arr.shift()! as number;
|
|
447
|
-
break;
|
|
448
|
-
case ContextType.TYPE_CONSTANT:
|
|
449
|
-
identifier = arr.shift()! as number; // identifier
|
|
450
|
-
break;
|
|
451
|
-
case ValueType.TYPE_ADDRESS:
|
|
452
|
-
value = Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
453
|
-
arr.splice(0, 32); // address
|
|
454
|
-
break;
|
|
455
|
-
case ValueType.TYPE_BOOL:
|
|
456
|
-
case ValueType.TYPE_U8:
|
|
457
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as number;
|
|
458
|
-
arr.shift();
|
|
459
|
-
break;
|
|
460
|
-
case ValueType.TYPE_U64:
|
|
461
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as number;
|
|
462
|
-
arr.splice(0, 8);
|
|
463
|
-
break;
|
|
464
|
-
case ValueType.TYPE_U128:
|
|
465
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as bigint;
|
|
466
|
-
arr.splice(0, 16);
|
|
467
|
-
break;
|
|
468
|
-
case ValueType.TYPE_U256:
|
|
469
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as bigint;
|
|
470
|
-
arr.splice(0, 32);
|
|
471
|
-
break;
|
|
472
|
-
case ValueType.TYPE_VEC_U8:
|
|
473
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
474
|
-
case ValueType.TYPE_STRING:
|
|
475
|
-
let r = ulebDecode(Uint8Array.from(arr));
|
|
476
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
477
|
-
arr.splice(0, r.value+r.length);
|
|
478
|
-
break;
|
|
479
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
480
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
481
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
482
|
-
arr.splice(0, r.value*32+r.length);
|
|
483
|
-
break;
|
|
484
|
-
case ValueType.TYPE_VEC_U128:
|
|
485
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
486
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
487
|
-
arr.splice(0, r.value*16+r.length);
|
|
488
|
-
break;
|
|
489
|
-
case ValueType.TYPE_VEC_U256:
|
|
490
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
491
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
492
|
-
arr.splice(0, r.value*32+r.length);
|
|
493
|
-
break;
|
|
494
|
-
case ValueType.TYPE_VEC_U64:
|
|
495
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
496
|
-
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
497
|
-
arr.splice(0, r.value*8+r.length);
|
|
498
|
-
break;
|
|
499
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
500
|
-
case ValueType.TYPE_VEC_STRING:
|
|
501
|
-
r = ulebDecode(Uint8Array.from(arr)); arr.splice(0, r.length);
|
|
502
|
-
let res = [];
|
|
503
|
-
for (let i = 0; i < r.value; i++) {
|
|
504
|
-
let r2 = ulebDecode(Uint8Array.from(arr));
|
|
505
|
-
res.push(Bcs.getInstance().de(ValueType.TYPE_VEC_U8, Uint8Array.from(arr)));
|
|
506
|
-
arr.splice(0, r2.length+r2.value);
|
|
507
|
-
}
|
|
508
|
-
value = res;
|
|
509
|
-
break;
|
|
510
|
-
case OperatorType.TYPE_QUERY:
|
|
511
|
-
let t = arr.splice(0, 1); // data-type
|
|
512
|
-
if (t[0] == ValueType.TYPE_ADDRESS) {
|
|
513
|
-
let addr = Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
514
|
-
arr.splice(0, 32); // address
|
|
515
|
-
value = addr;
|
|
516
|
-
cmd = bcs.u16().parse(Uint8Array.from(arr.splice(0, 2))) as number; // cmd(u16)
|
|
517
|
-
} else if (t[0] == ContextType.TYPE_CONSTANT) {
|
|
518
|
-
let id = arr.splice(0, 1); // key
|
|
519
|
-
let v = constants.find((v) =>
|
|
520
|
-
(v.identifier == id[0]) &&
|
|
521
|
-
((v.type == ValueType.TYPE_ADDRESS)));
|
|
522
|
-
if (!v) { ERROR(Errors.Fail, 'GuardObject: indentifier not in constant')}
|
|
523
|
-
identifier = id[0];
|
|
524
|
-
cmd = bcs.u16().parse(Uint8Array.from(arr.splice(0, 2))) as number; // cmd(u16)
|
|
525
|
-
} else {
|
|
526
|
-
ERROR(Errors.Fail, 'GuardObject: constant type invalid');
|
|
527
|
-
}
|
|
528
|
-
break;
|
|
529
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
530
|
-
let read = readOption(arr, ValueType.TYPE_ADDRESS);
|
|
531
|
-
value = read.value;
|
|
532
|
-
if (!read.bNone) arr.splice(0, 32);
|
|
533
|
-
break;
|
|
534
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
535
|
-
read = readOption(arr, ValueType.TYPE_BOOL);
|
|
536
|
-
value = read.value;
|
|
537
|
-
if (!read.bNone) arr.splice(0, 1);
|
|
538
|
-
break;
|
|
539
|
-
case ValueType.TYPE_OPTION_U8:
|
|
540
|
-
read = readOption(arr, ValueType.TYPE_U8);
|
|
541
|
-
value = read.value;
|
|
542
|
-
if (!read.bNone) arr.splice(0, 1);
|
|
543
|
-
break;
|
|
544
|
-
case ValueType.TYPE_OPTION_U128:
|
|
545
|
-
read = readOption(arr, ValueType.TYPE_U128);
|
|
546
|
-
value = read.value;
|
|
547
|
-
if (!read.bNone) arr.splice(0, 16);
|
|
548
|
-
break;
|
|
549
|
-
case ValueType.TYPE_OPTION_U256:
|
|
550
|
-
read = readOption(arr, ValueType.TYPE_U256);
|
|
551
|
-
value = read.value;
|
|
552
|
-
if (!read.bNone) arr.splice(0, 32);
|
|
553
|
-
break;
|
|
554
|
-
case ValueType.TYPE_OPTION_U64:
|
|
555
|
-
read = readOption(arr, ValueType.TYPE_U64);
|
|
556
|
-
value = read.value;
|
|
557
|
-
if (!read.bNone) arr.splice(0, 8);
|
|
558
|
-
break;
|
|
559
|
-
case ValueType.TYPE_OPTION_STRING:
|
|
560
|
-
read = readOptionString(arr); // splice in it
|
|
561
|
-
value = read.value;
|
|
562
|
-
break;
|
|
563
|
-
default:
|
|
564
|
-
ERROR(Errors.Fail, 'GuardObject: parse_bcs types ' + type)
|
|
565
|
-
}
|
|
566
|
-
data.push({type:type as number, value:value, cmd:cmd, identifier:identifier});
|
|
567
|
-
}
|
|
568
|
-
return data;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
done = async (fill?:WitnessFill[], onPassportQueryReady?:(passport:PassportQuery | undefined)=>void) : Promise<PassportQuery | undefined>=> {
|
|
572
|
-
let objects: string[] = [];
|
|
573
|
-
// check all witness and get all objects to query.
|
|
574
|
-
this.guard_list.forEach((g) => {
|
|
575
|
-
g.constant.forEach((v) => {
|
|
576
|
-
if (v.bWitness) {
|
|
577
|
-
const value = fill?.find((i)=>i.identifier === v.identifier);
|
|
578
|
-
if (!value) {
|
|
579
|
-
ERROR(Errors.Fail, 'done: invalid witness '+v.identifier);
|
|
580
|
-
} else {
|
|
581
|
-
v.value = value.witness;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
})
|
|
585
|
-
g.input.filter((v)=>v.cmd !== undefined).forEach((i)=> {
|
|
586
|
-
if (i.identifier !== undefined) {
|
|
587
|
-
const value = g.constant.find((c)=>c.identifier === i.identifier && c.type === ValueType.TYPE_ADDRESS);
|
|
588
|
-
if (!value || !IsValidAddress(value.value as string)) ERROR(Errors.Fail, 'done: invalid identifier '+i.identifier);
|
|
589
|
-
objects.push(value!.value);
|
|
590
|
-
} else {
|
|
591
|
-
objects.push(i.value);
|
|
592
|
-
}
|
|
593
|
-
})
|
|
594
|
-
})
|
|
595
|
-
|
|
596
|
-
if (onPassportQueryReady) {
|
|
597
|
-
if (objects.length === 0) {
|
|
598
|
-
onPassportQueryReady(this.done_helper([]));
|
|
599
|
-
return
|
|
600
|
-
}
|
|
601
|
-
Protocol.Instance().query_raw(array_unique(objects), {showType:true}).then((res) => {
|
|
602
|
-
onPassportQueryReady(this.done_helper(res));
|
|
603
|
-
}).catch(e => {
|
|
604
|
-
console.log(e);
|
|
605
|
-
onPassportQueryReady(undefined);
|
|
606
|
-
})
|
|
607
|
-
return undefined;
|
|
608
|
-
} else {
|
|
609
|
-
let res:any[] = [];
|
|
610
|
-
if (objects.length > 0) {
|
|
611
|
-
res = await Protocol.Instance().query_raw(array_unique(objects), {showType:true});
|
|
612
|
-
}
|
|
613
|
-
return this.done_helper(res);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
private done_helper(res:SuiObjectResponse[]) {
|
|
618
|
-
let query: Guard_Query_Object[] = [];
|
|
619
|
-
let guards: TransactionObjectInput[] = [];
|
|
620
|
-
this.guard_list.forEach(g => {
|
|
621
|
-
guards.push(g.id);
|
|
622
|
-
g.input.filter((v)=>v.cmd !== undefined).forEach(q => { // query list
|
|
623
|
-
let id = q.value;
|
|
624
|
-
if (!id && q.identifier !== undefined) {
|
|
625
|
-
id = g.constant.find((i)=>i.identifier == q.identifier)?.value;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
let r = res.find(r => r.data?.objectId == id);
|
|
629
|
-
if (!r) { ERROR(Errors.Fail, 'query object not match')}
|
|
630
|
-
let object = this.object_query(r!.data); // build passport query objects
|
|
631
|
-
if (!object) { ERROR(Errors.Fail, 'query object fail')}
|
|
632
|
-
query.push(object!);
|
|
633
|
-
})
|
|
634
|
-
})
|
|
635
|
-
|
|
636
|
-
return {query:query, info:this.guard_list} as PassportQuery;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// create onchain query for objects : object, movecall-types, id
|
|
640
|
-
private object_query = (data: any, method:'guard_query'|'witness'='guard_query') : Guard_Query_Object | undefined=> {
|
|
641
|
-
for (let k = 0; k < Protocol.Instance().WOWOK_OBJECTS_TYPE().length; k++) {
|
|
642
|
-
if (data.type.includes(Protocol.Instance().WOWOK_OBJECTS_TYPE()[k]) ) { // type: pack::m::Object<...>
|
|
643
|
-
return { target:Protocol.Instance().WOWOK_OBJECTS_PREFIX_TYPE()[k] + method as FnCallType,
|
|
644
|
-
object:Inputs.SharedObjectRef({
|
|
645
|
-
objectId: data.objectId,
|
|
646
|
-
mutable: false,
|
|
647
|
-
initialSharedVersion: data.version,
|
|
648
|
-
}) as TransactionObjectInput,
|
|
649
|
-
types:parse_object_type(data.type as string),
|
|
650
|
-
id: data.objectId,
|
|
651
|
-
} as Guard_Query_Object;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
static MAX_REPOSITORY_DEPTH = 3;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
export class Passport {
|
|
659
|
-
static MAX_GUARD_COUNT = 8;
|
|
660
|
-
protected passport;
|
|
661
|
-
protected txb;
|
|
662
|
-
|
|
663
|
-
get_object () { return this.passport }
|
|
664
|
-
// return passport object used
|
|
665
|
-
// bObject(true) in cmd env; (false) in service env
|
|
666
|
-
constructor (txb:TransactionBlock, query:PassportQuery) {
|
|
667
|
-
if (query.info.length === 0 || query.info.length > Passport.MAX_GUARD_COUNT) {
|
|
668
|
-
ERROR(Errors.InvalidParam, 'guards' )
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
this.txb = txb; //console.log(query)
|
|
672
|
-
this.passport = this.txb.moveCall({
|
|
673
|
-
target:Protocol.Instance().passportFn('new') as FnCallType,
|
|
674
|
-
arguments: []
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
// add others guards, if any
|
|
678
|
-
query.info.forEach((g) => {
|
|
679
|
-
const ids = g.constant.filter((i)=>i.bWitness).map((v)=>v.identifier);
|
|
680
|
-
const values = g.constant.filter((i)=>i.bWitness).map((v)=> {
|
|
681
|
-
const bcs = Bcs.getInstance().ser(v.type, v.value);
|
|
682
|
-
let r = new Uint8Array(bcs.length + 1);
|
|
683
|
-
r.set([v.type], 0); r.set(bcs, 1);
|
|
684
|
-
return [].slice.call(r)
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
const guard = g.version !== undefined && g.digest !== undefined ?
|
|
688
|
-
txb.objectRef({objectId:g.id, version:g.version, digest:g.digest}) :
|
|
689
|
-
txb.object(g.id);
|
|
690
|
-
//console.log(ids); console.log(values)
|
|
691
|
-
this.txb.moveCall({ //@ vec vec u8
|
|
692
|
-
target:Protocol.Instance().passportFn('guard_add') as FnCallType,
|
|
693
|
-
arguments:[this.passport, guard, this.txb.pure.vector('u8', [].slice.call(ids)),
|
|
694
|
-
this.txb.pure(bcs.vector(bcs.vector(bcs.u8())).serialize([...values]).toBytes())]
|
|
695
|
-
});
|
|
696
|
-
})
|
|
697
|
-
|
|
698
|
-
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
699
|
-
// rules: 'verify' & 'query' in turns; 'verify' at final end.
|
|
700
|
-
query?.query.forEach((q) => {
|
|
701
|
-
this.txb.moveCall({
|
|
702
|
-
target: Protocol.Instance().passportFn('passport_verify') as FnCallType,
|
|
703
|
-
arguments: [ this.passport, this.txb.object(clock)]
|
|
704
|
-
});
|
|
705
|
-
this.txb.moveCall({
|
|
706
|
-
target: q.target as FnCallType,
|
|
707
|
-
arguments: [ this.txb.object(q.id), this.passport],
|
|
708
|
-
typeArguments: q.types,
|
|
709
|
-
})
|
|
710
|
-
})
|
|
711
|
-
this.txb.moveCall({
|
|
712
|
-
target: Protocol.Instance().passportFn('passport_verify') as FnCallType,
|
|
713
|
-
arguments: [ this.passport, this.txb.object(clock) ]
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
destroy() {
|
|
718
|
-
this.txb.moveCall({
|
|
719
|
-
target: Protocol.Instance().passportFn('destroy') as FnCallType,
|
|
720
|
-
arguments: [ this.passport ]
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
freeze() {
|
|
725
|
-
this.txb.moveCall({
|
|
726
|
-
target: Protocol.Instance().passportFn('freezen') as FnCallType,
|
|
727
|
-
arguments: [ this.passport ]
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
query_result(sender:string, handleResult:OnQueryPassportResult) {
|
|
732
|
-
this.txb.moveCall({
|
|
733
|
-
target: Protocol.Instance().passportFn('query_result') as FnCallType,
|
|
734
|
-
arguments: [ this.passport ]
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:this.txb}).then((res) => {
|
|
738
|
-
const r = Passport.ResolveQueryRes(this.txb, res);
|
|
739
|
-
if (r) handleResult(r);
|
|
740
|
-
}).catch(e=>{
|
|
741
|
-
console.log(e);
|
|
742
|
-
})
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
query_result_async = async (sender:string) : Promise<QueryPassportResult | undefined> => {
|
|
746
|
-
this.txb.moveCall({
|
|
747
|
-
target: Protocol.Instance().passportFn('query_result') as FnCallType,
|
|
748
|
-
arguments: [ this.passport ]
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
const res = await Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:this.txb});
|
|
752
|
-
return Passport.ResolveQueryRes(this.txb, res);
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
private static ResolveQueryRes(txb:TransactionBlock, res:any) : QueryPassportResult | undefined {
|
|
756
|
-
for (let i = 0; i < res.results?.length; ++ i) {
|
|
757
|
-
const v = res.results[i];
|
|
758
|
-
if (v?.returnValues && v.returnValues.length === 2 &&
|
|
759
|
-
v.returnValues[0][1] === 'bool' && v.returnValues[1][1] === 'vector<address>') { // (bool, vector<address>)
|
|
760
|
-
const result = bcs.bool().parse(Uint8Array.from(v.returnValues[0][0]));
|
|
761
|
-
const guards = bcs.vector(bcs.Address).parse(Uint8Array.from(v.returnValues[1][0])).map((v:string)=>'0x'+v);
|
|
762
|
-
return {txb:txb, result:result, guards:guards}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
return undefined
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
export interface QueryPassportResult {
|
|
770
|
-
txb: TransactionBlock;
|
|
771
|
-
result: boolean;
|
|
772
|
-
guards: string[];
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
export type OnQueryPassportResult = (result:QueryPassportResult) => void;
|
|
776
|
-
|
|
777
|
-
|