wowok 1.1.5 → 1.2.0
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 +7 -2
- package/dist/demand.d.ts +0 -2
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +0 -8
- package/dist/entity.d.ts +23 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +71 -0
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/guard.d.ts +12 -12
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +65 -52
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/machine.d.ts +0 -2
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +0 -7
- package/dist/passport.d.ts +13 -9
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +60 -55
- package/dist/permission.d.ts +0 -2
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +0 -7
- package/dist/progress.d.ts +0 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +9 -7
- package/dist/protocol.d.ts +15 -8
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +29 -26
- package/dist/repository.d.ts +0 -2
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +10 -9
- package/dist/resource.d.ts +2 -5
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +4 -30
- package/dist/reward.d.ts +0 -2
- package/dist/reward.d.ts.map +1 -1
- package/dist/reward.js +9 -7
- package/dist/service.d.ts +0 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +10 -8
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +10 -0
- package/dist/vote.d.ts +0 -2
- package/dist/vote.d.ts.map +1 -1
- package/dist/vote.js +0 -7
- package/dist/wowok.d.ts +12 -0
- package/dist/wowok.d.ts.map +1 -0
- package/dist/wowok.js +48 -0
- package/package.json +10 -3
- package/src/demand.ts +1 -10
- package/src/entity.ts +27 -1
- package/src/guard.ts +55 -55
- package/src/index.ts +11 -8
- package/src/machine.ts +0 -8
- package/src/passport.ts +69 -65
- package/src/permission.ts +0 -8
- package/src/progress.ts +2 -2
- package/src/protocol.ts +28 -28
- package/src/repository.ts +2 -2
- package/src/resource.ts +3 -35
- package/src/reward.ts +2 -2
- package/src/service.ts +2 -2
- package/src/vote.ts +0 -8
package/src/guard.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
import { BCS } from '@mysten/bcs';
|
|
3
|
-
import { Protocol, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType,
|
|
3
|
+
import { Protocol, GuardAddress, FnCallType, Data_Type, MODULES, ContextType, ValueType, OperatorType, ConstantType, SER_VALUE} from './protocol';
|
|
4
4
|
import { concatenate, array_equal } from './utils';
|
|
5
5
|
import { IsValidDesription, Bcs, IsValidInt, IsValidAddress } from './utils';
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type GuardConstant = Map<number, Guard_Vriable>;
|
|
9
9
|
|
|
10
10
|
export interface Guard_Vriable {
|
|
11
|
-
type:
|
|
11
|
+
type: ConstantType ,
|
|
12
12
|
value?: Uint8Array,
|
|
13
13
|
witness?: Uint8Array,
|
|
14
14
|
}
|
|
@@ -24,18 +24,18 @@ export class Guard {
|
|
|
24
24
|
ERROR(Errors.IsValidDesription)
|
|
25
25
|
}
|
|
26
26
|
let bcs_input = maker.get_input()[0];
|
|
27
|
-
let
|
|
27
|
+
let constants = maker.get_constant();
|
|
28
28
|
if (bcs_input.length == 0 || bcs_input.length > Guard.MAX_INPUT_LENGTH) {
|
|
29
29
|
ERROR(Errors.InvalidParam, 'launch input')
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
let bValid = true;
|
|
33
|
-
|
|
34
|
-
if (!
|
|
33
|
+
constants?.forEach((v, k) => {
|
|
34
|
+
if (!GuardConstantHelper.IsValidIndentifier(k)) bValid = false;
|
|
35
35
|
if (!v.value && !v.witness) bValid = false;
|
|
36
36
|
})
|
|
37
37
|
if (!bValid) {
|
|
38
|
-
ERROR(Errors.InvalidParam, 'launch
|
|
38
|
+
ERROR(Errors.InvalidParam, 'launch constants')
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
let txb = protocol.CurrentSession();
|
|
@@ -47,23 +47,23 @@ export class Guard {
|
|
|
47
47
|
arguments: [txb.pure(description , BCS.STRING), txb.pure([].slice.call(input.reverse()))],
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
constants?.forEach((v, k) => {
|
|
51
51
|
if (v.type == ContextType.TYPE_WITNESS_ID) {
|
|
52
52
|
if (!v.witness) {
|
|
53
|
-
ERROR(Errors.InvalidParam, '
|
|
53
|
+
ERROR(Errors.InvalidParam, 'constants type')
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
txb.moveCall({
|
|
57
|
-
target:protocol.GuardFn("
|
|
57
|
+
target:protocol.GuardFn("constant_add") as FnCallType,
|
|
58
58
|
arguments:[guard, txb.pure(k, BCS.U8), txb.pure(v.type, BCS.U8), txb.pure([].slice.call(v.witness)), txb.pure(true, BCS.BOOL)]
|
|
59
59
|
})
|
|
60
60
|
} else {
|
|
61
61
|
if (!v.value) {
|
|
62
|
-
ERROR(Errors.InvalidParam, '
|
|
62
|
+
ERROR(Errors.InvalidParam, 'constants type')
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
txb.moveCall({
|
|
66
|
-
target:protocol.GuardFn("
|
|
66
|
+
target:protocol.GuardFn("constant_add") as FnCallType,
|
|
67
67
|
arguments:[guard, txb.pure(k, BCS.U8), txb.pure(v.type, BCS.U8), txb.pure([].slice.call(v.value)), txb.pure(true, BCS.BOOL)]
|
|
68
68
|
})
|
|
69
69
|
}
|
|
@@ -231,7 +231,7 @@ export class Guard {
|
|
|
231
231
|
|
|
232
232
|
[MODULES.entity, 'has_entity', 230, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL],
|
|
233
233
|
[MODULES.entity, 'entity_like', 231, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
234
|
-
[MODULES.entity, '
|
|
234
|
+
[MODULES.entity, 'entity_dislike', 232, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
235
235
|
[MODULES.entity, 'entity_infomation', 233, [ValueType.TYPE_ADDRESS], ValueType.TYPE_VEC_U8],
|
|
236
236
|
];
|
|
237
237
|
static BoolCmd = Guard.QUERIES.filter(q => q[4] == ValueType.TYPE_BOOL);
|
|
@@ -241,43 +241,43 @@ export class Guard {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
export class
|
|
244
|
+
export class GuardConstantHelper {
|
|
245
245
|
static IsValidIndentifier = (identifier:number) : boolean => {
|
|
246
246
|
if (!IsValidInt(identifier) || identifier > 255) return false;
|
|
247
247
|
return true
|
|
248
248
|
}
|
|
249
|
-
static
|
|
250
|
-
if (
|
|
251
|
-
let v =
|
|
249
|
+
static get_constant_value(constants:GuardConstant, identifier:number, type:ConstantType) : Uint8Array | undefined {
|
|
250
|
+
if (constants.has(identifier)) {
|
|
251
|
+
let v = constants.get(identifier);
|
|
252
252
|
if (v?.value && v.type == type) {
|
|
253
253
|
return v.value;
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
-
static
|
|
258
|
-
if (
|
|
259
|
-
let v =
|
|
257
|
+
static get_constant_witness(constants:GuardConstant, identifier:number) : Uint8Array | undefined {
|
|
258
|
+
if (constants.has(identifier)) {
|
|
259
|
+
let v = constants.get(identifier);
|
|
260
260
|
if (v?.witness && v.type == ContextType.TYPE_WITNESS_ID) {
|
|
261
261
|
return v.witness;
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
static
|
|
267
|
-
if (!
|
|
266
|
+
static add_future_constant(constants:GuardConstant, identifier:number, witness:any, value?:any, bNeedSerialize=true) {
|
|
267
|
+
if (!GuardConstantHelper.IsValidIndentifier(identifier)) ERROR(Errors.IsValidIndentifier, 'add_future_constant');
|
|
268
268
|
if (!witness && !value) ERROR(Errors.InvalidParam, 'both witness and value invalid');
|
|
269
|
-
let v =
|
|
269
|
+
let v = constants.get(identifier);
|
|
270
270
|
if (!v || v.type == ContextType.TYPE_WITNESS_ID) {
|
|
271
271
|
if (bNeedSerialize) {
|
|
272
|
-
|
|
272
|
+
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value ? Bcs.getInstance().ser_address(value) : undefined, witness:witness ? Bcs.getInstance().ser_address(witness) : undefined})
|
|
273
273
|
} else {
|
|
274
|
-
|
|
274
|
+
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value?value:undefined, witness:witness?witness:undefined});
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
-
static
|
|
280
|
-
if (!
|
|
279
|
+
static add_constant(constants:GuardConstant, identifier:number, type:ValueType, value:any, bNeedSerialize=true) {
|
|
280
|
+
if (!GuardConstantHelper.IsValidIndentifier(identifier)) return false;
|
|
281
281
|
if (!value) return false;
|
|
282
282
|
|
|
283
283
|
switch (type) {
|
|
@@ -300,26 +300,26 @@ export class GuardVariableHelper {
|
|
|
300
300
|
case ValueType.TYPE_VEC_U128:
|
|
301
301
|
case ValueType.TYPE_VEC_U256:
|
|
302
302
|
let ser = SER_VALUE.find(s=>s.type==type);
|
|
303
|
-
if (!ser) ERROR(Errors.Fail, '
|
|
304
|
-
bNeedSerialize ?
|
|
305
|
-
|
|
303
|
+
if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type');
|
|
304
|
+
bNeedSerialize ? constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ser!.name, value)}) :
|
|
305
|
+
constants.set(identifier, {type:type, value:value})
|
|
306
306
|
return
|
|
307
307
|
case ValueType.TYPE_VEC_U8:
|
|
308
308
|
if (typeof(value) === 'string') {
|
|
309
|
-
|
|
309
|
+
constants.set(identifier, {type:type, value:Bcs.getInstance().ser_string(value)})
|
|
310
310
|
} else {
|
|
311
|
-
|
|
311
|
+
constants.set(identifier, {type:type, value:value})
|
|
312
312
|
}
|
|
313
313
|
return;
|
|
314
314
|
default:
|
|
315
|
-
ERROR(Errors.Fail, '
|
|
315
|
+
ERROR(Errors.Fail, 'add_constant serialize not impl yet')
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
export class GuardMaker {
|
|
320
320
|
protected data : Uint8Array[] = [];
|
|
321
321
|
protected type_validator : Data_Type[] = [];
|
|
322
|
-
protected
|
|
322
|
+
protected constant : GuardConstant = new Map();
|
|
323
323
|
|
|
324
324
|
private static index: number = 0;
|
|
325
325
|
private static get_index() {
|
|
@@ -331,13 +331,13 @@ export class GuardMaker {
|
|
|
331
331
|
|
|
332
332
|
constructor() { }
|
|
333
333
|
|
|
334
|
-
|
|
334
|
+
add_constant(type:ConstantType, value:any, bNeedSerialize=true) : number {
|
|
335
335
|
let identifier = GuardMaker.get_index();
|
|
336
336
|
if (type == ContextType.TYPE_WITNESS_ID) {
|
|
337
|
-
// add witness to
|
|
338
|
-
|
|
337
|
+
// add witness to constant
|
|
338
|
+
GuardConstantHelper.add_future_constant(this.constant, identifier, value, undefined, bNeedSerialize);
|
|
339
339
|
} else {
|
|
340
|
-
|
|
340
|
+
GuardConstantHelper.add_constant(this.constant, identifier, type, value, bNeedSerialize);
|
|
341
341
|
}
|
|
342
342
|
return identifier
|
|
343
343
|
}
|
|
@@ -398,7 +398,7 @@ export class GuardMaker {
|
|
|
398
398
|
this.data.push(Bcs.getInstance().ser_address(param));
|
|
399
399
|
this.type_validator.push(ValueType.TYPE_ADDRESS);
|
|
400
400
|
break;
|
|
401
|
-
case ContextType.
|
|
401
|
+
case ContextType.TYPE_CONSTANT:
|
|
402
402
|
if (!param) {
|
|
403
403
|
ERROR(Errors.InvalidParam, 'param invalid');
|
|
404
404
|
}
|
|
@@ -406,8 +406,8 @@ export class GuardMaker {
|
|
|
406
406
|
ERROR(Errors.InvalidParam, 'add_param param');
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
var v = this.
|
|
410
|
-
if (!v) ERROR(Errors.Fail, 'identifier not in
|
|
409
|
+
var v = this.constant.get(param);
|
|
410
|
+
if (!v) ERROR(Errors.Fail, 'identifier not in constant');
|
|
411
411
|
this.type_validator.push(v!.type);
|
|
412
412
|
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
413
413
|
this.data.push(Bcs.getInstance().ser_u8(param));
|
|
@@ -418,7 +418,7 @@ export class GuardMaker {
|
|
|
418
418
|
return this;
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
// object_address_from: string for static address; number as identifier
|
|
421
|
+
// object_address_from: string for static address; number as identifier inconstant
|
|
422
422
|
add_query(module:MODULES, query_name:string, object_address_from:string | number, bWitness:boolean=false) : GuardMaker {
|
|
423
423
|
let query_index = Guard.QUERIES.findIndex((q) => { return q[0] == module && q[1] == query_name})
|
|
424
424
|
if (query_index == -1) {
|
|
@@ -426,7 +426,7 @@ export class GuardMaker {
|
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
if (typeof(object_address_from) == 'number' ) {
|
|
429
|
-
if (!
|
|
429
|
+
if (!GuardConstantHelper.IsValidIndentifier(object_address_from)) {
|
|
430
430
|
ERROR(Errors.InvalidParam, 'object_address_from');
|
|
431
431
|
}
|
|
432
432
|
} else {
|
|
@@ -451,11 +451,11 @@ export class GuardMaker {
|
|
|
451
451
|
this.data.push(Bcs.getInstance().ser_u8(ValueType.TYPE_ADDRESS));
|
|
452
452
|
this.data.push(Bcs.getInstance().ser_address(object_address_from)); // object address
|
|
453
453
|
} else {
|
|
454
|
-
let v = this.
|
|
455
|
-
if (!v) ERROR(Errors.Fail, 'object_address_from not in
|
|
454
|
+
let v = this.constant.get(object_address_from);
|
|
455
|
+
if (!v) ERROR(Errors.Fail, 'object_address_from not in constant');
|
|
456
456
|
if ((bWitness && v?.type == ContextType.TYPE_WITNESS_ID) || (!bWitness && v?.type == ValueType.TYPE_ADDRESS)) {
|
|
457
|
-
this.data.push(Bcs.getInstance().ser_u8(ContextType.
|
|
458
|
-
this.data.push(Bcs.getInstance().ser_u8(object_address_from)); // object identifer in
|
|
457
|
+
this.data.push(Bcs.getInstance().ser_u8(ContextType.TYPE_CONSTANT));
|
|
458
|
+
this.data.push(Bcs.getInstance().ser_u8(object_address_from)); // object identifer in constants
|
|
459
459
|
} else {
|
|
460
460
|
ERROR(Errors.Fail, 'type bWitness not match')
|
|
461
461
|
}
|
|
@@ -523,17 +523,17 @@ export class GuardMaker {
|
|
|
523
523
|
return this.type_validator.length == 1 && this.type_validator[0] == ValueType.TYPE_BOOL && this.data.length == 1;
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
combine(otherBuilt:GuardMaker, bAnd:boolean = true,
|
|
526
|
+
combine(otherBuilt:GuardMaker, bAnd:boolean = true, bCombinConstant=false) : GuardMaker {
|
|
527
527
|
if (!otherBuilt.IsReady() || !this.IsReady()) { ERROR(Errors.Fail, 'both should built yet')};
|
|
528
528
|
let maker = new GuardMaker();
|
|
529
|
-
this.
|
|
530
|
-
maker.
|
|
529
|
+
this.constant.forEach((v, k) => {
|
|
530
|
+
maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
|
|
531
531
|
})
|
|
532
|
-
otherBuilt.
|
|
533
|
-
if (maker.
|
|
534
|
-
ERROR(Errors.Fail, '
|
|
532
|
+
otherBuilt.constant.forEach((v, k) => {
|
|
533
|
+
if (maker.constant.has(k) && !bCombinConstant) {
|
|
534
|
+
ERROR(Errors.Fail, 'constant identifier exist');
|
|
535
535
|
}
|
|
536
|
-
maker.
|
|
536
|
+
maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
|
|
537
537
|
})
|
|
538
538
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
539
539
|
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser_u8(op)));
|
|
@@ -542,7 +542,7 @@ export class GuardMaker {
|
|
|
542
542
|
return maker
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
|
|
545
|
+
get_constant() { return this.constant }
|
|
546
546
|
get_input() { return this.data }
|
|
547
547
|
|
|
548
548
|
static input_combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export * from './demand'
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
2
|
+
export * from './progress'
|
|
3
|
+
export * from './reward'
|
|
4
|
+
export * from './utils'
|
|
5
|
+
export * from './permission'
|
|
6
|
+
export * from './guard'
|
|
7
|
+
export * from './repository'
|
|
8
|
+
export * from './vote'
|
|
9
9
|
export * from './protocol'
|
|
10
10
|
export * from './passport'
|
|
11
11
|
export * from './machine'
|
|
12
12
|
export * from './service'
|
|
13
|
-
export * from './graphql'
|
|
13
|
+
export * from './graphql'
|
|
14
|
+
export * from './entity'
|
|
15
|
+
export * from './wowok'
|
|
16
|
+
export * from './resource'
|
package/src/machine.ts
CHANGED
|
@@ -196,14 +196,6 @@ export class Machine {
|
|
|
196
196
|
})
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
200
|
-
let txb = this.protocol.CurrentSession();
|
|
201
|
-
txb.moveCall({
|
|
202
|
-
target:this.protocol.MachineFn(like) as FnCallType,
|
|
203
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
|
|
207
199
|
set_description(description:string, passport?:PassportObject) {
|
|
208
200
|
if (!IsValidDesription(description)) {
|
|
209
201
|
ERROR(Errors.IsValidDesription)
|
package/src/passport.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type Guard_Query_Object = {
|
|
|
13
13
|
id: string, // object id
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface QueryInfo {
|
|
16
|
+
export interface QueryInfo {
|
|
17
17
|
identifier?: number;
|
|
18
18
|
index: number;
|
|
19
19
|
type: number;
|
|
@@ -23,16 +23,16 @@ interface QueryInfo {
|
|
|
23
23
|
interface GuardInfo {
|
|
24
24
|
id: string;
|
|
25
25
|
query_list: (string | QueryInfo)[]; // object or witness object query
|
|
26
|
-
|
|
26
|
+
constant: QueryInfo[]; // witness in constant & ValueType.TYPE_ADDRESS(for Query)
|
|
27
27
|
input_witness: QueryInfo[]; // witness in input
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
interface
|
|
30
|
+
export interface DeGuardConstant {
|
|
31
31
|
type: number;
|
|
32
32
|
value: any;
|
|
33
33
|
identifier?: number;
|
|
34
34
|
}
|
|
35
|
-
interface DeGuardData {
|
|
35
|
+
export interface DeGuardData {
|
|
36
36
|
type: number;
|
|
37
37
|
value?: any;
|
|
38
38
|
identifier?: number;
|
|
@@ -41,12 +41,12 @@ interface DeGuardData {
|
|
|
41
41
|
ret_type?: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
interface FutrueFill {
|
|
44
|
+
export interface FutrueFill {
|
|
45
45
|
guard: string;
|
|
46
46
|
index: number;
|
|
47
47
|
future: string;
|
|
48
48
|
}
|
|
49
|
-
interface PassportQuery {
|
|
49
|
+
export interface PassportQuery {
|
|
50
50
|
guard: GuardObject[];
|
|
51
51
|
query: Guard_Query_Object[];
|
|
52
52
|
witness: Guard_Query_Object[];
|
|
@@ -64,30 +64,15 @@ export class GuardParser {
|
|
|
64
64
|
}
|
|
65
65
|
guardlist = () => { return this.guard_list }
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let res = await protocol.Query_Raw([guard]);
|
|
74
|
-
if (res.length == 0 || !res[0].data || res[0].data?.objectId != guard) {
|
|
75
|
-
ERROR(Errors.Fail, 'GuardObject query error');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// console.log(res[0].data?.content);
|
|
79
|
-
let content = res[0].data!.content as any;
|
|
80
|
-
if (content?.type != protocol.Package() + '::guard::Guard') {
|
|
81
|
-
ERROR(Errors.Fail, 'GuardObject object invalid')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let variables : DeGuardVariable[] = [];
|
|
85
|
-
content.fields.variables.forEach((v:any) => {
|
|
86
|
-
let value : any;
|
|
87
|
-
switch (v.fields.type) {
|
|
67
|
+
static DeGuardObject_FromData = (guard_constants:any, guard_input_bytes:any) : {object:DeGuardData, constant:DeGuardConstant[]} => {
|
|
68
|
+
let constants : DeGuardConstant[] = [];
|
|
69
|
+
guard_constants.forEach((c:any) => {
|
|
70
|
+
let value : any;
|
|
71
|
+
let v = c?.fields ?? c; // graphql dosnot 'fields', but rpcall has.
|
|
72
|
+
switch (v.type) {
|
|
88
73
|
case ContextType.TYPE_WITNESS_ID:
|
|
89
74
|
case ValueType.TYPE_ADDRESS:
|
|
90
|
-
value = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(v.
|
|
75
|
+
value = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(v.value)).toString();
|
|
91
76
|
break;
|
|
92
77
|
case ValueType.TYPE_BOOL:
|
|
93
78
|
case ValueType.TYPE_U8:
|
|
@@ -107,19 +92,19 @@ export class GuardParser {
|
|
|
107
92
|
case ValueType.TYPE_OPTION_U64:
|
|
108
93
|
case ValueType.TYPE_OPTION_U256:
|
|
109
94
|
case ValueType.TYPE_VEC_U256:
|
|
110
|
-
let de = SER_VALUE.find(s=>s.type==v.
|
|
95
|
+
let de = SER_VALUE.find(s=>s.type==v.type);
|
|
111
96
|
if (!de) ERROR(Errors.Fail, 'GuardObject de error')
|
|
112
|
-
value = Bcs.getInstance().de(de!.name, Uint8Array.from(v.
|
|
97
|
+
value = Bcs.getInstance().de(de!.name, Uint8Array.from(v.value));
|
|
113
98
|
break;
|
|
114
99
|
|
|
115
100
|
default:
|
|
116
|
-
ERROR(Errors.Fail, 'GuardObject
|
|
101
|
+
ERROR(Errors.Fail, 'GuardObject constant type invalid')
|
|
117
102
|
}
|
|
118
|
-
|
|
103
|
+
constants.push({identifier:v.identifier, type:v.type, value:value});
|
|
119
104
|
});
|
|
120
|
-
// console.log(
|
|
121
|
-
|
|
122
|
-
let arr = [].slice.call(
|
|
105
|
+
// console.log(constants)
|
|
106
|
+
let bytes = Uint8Array.from(guard_input_bytes);
|
|
107
|
+
let arr = [].slice.call(bytes.reverse());
|
|
123
108
|
let data : DeGuardData[] = [];
|
|
124
109
|
while (arr.length > 0) {
|
|
125
110
|
let type : unknown = arr.shift() ;
|
|
@@ -139,10 +124,10 @@ export class GuardParser {
|
|
|
139
124
|
case OperatorType.TYPE_LOGIC_AND:
|
|
140
125
|
case OperatorType.TYPE_LOGIC_OR:
|
|
141
126
|
break;
|
|
142
|
-
case ContextType.
|
|
127
|
+
case ContextType.TYPE_CONSTANT:
|
|
143
128
|
identifier = arr.shift()! as number; // identifier
|
|
144
129
|
break;
|
|
145
|
-
case ContextType.TYPE_WITNESS_ID: // add to
|
|
130
|
+
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
146
131
|
case ValueType.TYPE_ADDRESS:
|
|
147
132
|
value = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(arr)).toString();
|
|
148
133
|
arr.splice(0, 32); // address
|
|
@@ -210,16 +195,16 @@ export class GuardParser {
|
|
|
210
195
|
arr.splice(0, 32); // address
|
|
211
196
|
value = addr;
|
|
212
197
|
cmd = arr.shift()! as number; // cmd
|
|
213
|
-
} else if (t[0] == ContextType.
|
|
198
|
+
} else if (t[0] == ContextType.TYPE_CONSTANT) {
|
|
214
199
|
let id = arr.splice(0, 1); // key
|
|
215
|
-
let v =
|
|
200
|
+
let v = constants.find((v) =>
|
|
216
201
|
(v.identifier == id[0]) &&
|
|
217
202
|
((v.type == ValueType.TYPE_ADDRESS) || (v.type == ContextType.TYPE_WITNESS_ID)));
|
|
218
|
-
if (!v) { ERROR(Errors.Fail, 'GuardObject: indentifier not in
|
|
203
|
+
if (!v) { ERROR(Errors.Fail, 'GuardObject: indentifier not in constant')}
|
|
219
204
|
identifier = id[0];
|
|
220
205
|
cmd = arr.shift()! as number; // cmd
|
|
221
206
|
} else {
|
|
222
|
-
ERROR(Errors.Fail, 'GuardObject:
|
|
207
|
+
ERROR(Errors.Fail, 'GuardObject: constant type invalid');
|
|
223
208
|
}
|
|
224
209
|
break;
|
|
225
210
|
case ValueType.TYPE_OPTION_ADDRESS:
|
|
@@ -262,17 +247,36 @@ export class GuardParser {
|
|
|
262
247
|
if (!data || data.length == 0) ERROR(Errors.Fail, 'GuardObject: data parsed error');
|
|
263
248
|
let stack: DeGuardData[] = [];
|
|
264
249
|
data.forEach((d) => {
|
|
265
|
-
this.ResolveData(
|
|
250
|
+
this.ResolveData(constants, stack, d);
|
|
266
251
|
})
|
|
267
252
|
|
|
268
253
|
if (stack.length != 1) {
|
|
269
254
|
ERROR(Errors.Fail, 'GuardObject: parse error');
|
|
270
255
|
}
|
|
271
256
|
|
|
272
|
-
return {object:stack.pop()!,
|
|
257
|
+
return {object:stack.pop()!, constant:constants};
|
|
258
|
+
}
|
|
259
|
+
/// convert guard-on-chain to js object
|
|
260
|
+
static DeGuardObject = async (protocol: Protocol, guard: string) : Promise<{object:DeGuardData, constant:DeGuardConstant[]}> => {
|
|
261
|
+
if (!IsValidAddress(guard)) {
|
|
262
|
+
ERROR(Errors.IsValidAddress, 'GuardObject guard')
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
let res = await protocol.Query_Raw([guard]);
|
|
266
|
+
if (res.length == 0 || !res[0].data || res[0].data?.objectId != guard) {
|
|
267
|
+
ERROR(Errors.Fail, 'GuardObject query error');
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// console.log(res[0].data?.content);
|
|
271
|
+
let content = res[0].data!.content as any;
|
|
272
|
+
if (content?.type != protocol.Package() + '::guard::Guard') {
|
|
273
|
+
ERROR(Errors.Fail, 'GuardObject object invalid')
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return GuardParser.DeGuardObject_FromData(content.fields.constants, content.fields.input.fields.bytes);
|
|
273
277
|
}
|
|
274
278
|
|
|
275
|
-
static ResolveData = (
|
|
279
|
+
static ResolveData = (constants: DeGuardConstant[], stack:DeGuardData[], current: DeGuardData) => {
|
|
276
280
|
switch (current.type) {
|
|
277
281
|
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
278
282
|
current.ret_type = ValueType.TYPE_BOOL;
|
|
@@ -393,8 +397,8 @@ export class GuardParser {
|
|
|
393
397
|
current.ret_type = ValueType.TYPE_ADDRESS;
|
|
394
398
|
stack.push(current);
|
|
395
399
|
return;
|
|
396
|
-
case ContextType.
|
|
397
|
-
let v =
|
|
400
|
+
case ContextType.TYPE_CONSTANT:
|
|
401
|
+
let v = constants.find((e) => e.identifier == current?.identifier);
|
|
398
402
|
if (!v) ERROR(Errors.Fail, 'OperateParamCount: identifier invalid ' + current.type);
|
|
399
403
|
|
|
400
404
|
current.ret_type = v?.type;
|
|
@@ -426,8 +430,8 @@ export class GuardParser {
|
|
|
426
430
|
let index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => {return v.includes('guard::Guard') && v == c.type});
|
|
427
431
|
if (index == -1) return;
|
|
428
432
|
|
|
429
|
-
let info:GuardInfo = {id: c.fields.id.id, query_list:[],
|
|
430
|
-
me.
|
|
433
|
+
let info:GuardInfo = {id: c.fields.id.id, query_list:[], constant:[], input_witness:[]};
|
|
434
|
+
me.parse_constant(info, c.fields.constants);
|
|
431
435
|
if (c.fields.input.type == (protocol.Package() + '::bcs::BCS')) {
|
|
432
436
|
me.parse_bcs(info, Uint8Array.from(c.fields.input.fields.bytes));
|
|
433
437
|
}
|
|
@@ -436,12 +440,12 @@ export class GuardParser {
|
|
|
436
440
|
return me
|
|
437
441
|
}
|
|
438
442
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (v.type == (this.protocol.Package() + '::guard::
|
|
443
|
+
parse_constant = (info:GuardInfo, constants:any) => {
|
|
444
|
+
constants.forEach((v:any) => {
|
|
445
|
+
if (v.type == (this.protocol.Package() + '::guard::Constant')) {
|
|
442
446
|
// ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for using
|
|
443
447
|
if (v.fields.type == ContextType.TYPE_WITNESS_ID || v.fields.type == ValueType.TYPE_ADDRESS) {
|
|
444
|
-
info.
|
|
448
|
+
info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:v.fields.type,
|
|
445
449
|
value_or_witness:'0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(v.fields.value))});
|
|
446
450
|
}
|
|
447
451
|
}
|
|
@@ -468,10 +472,10 @@ export class GuardParser {
|
|
|
468
472
|
case OperatorType.TYPE_LOGIC_AND:
|
|
469
473
|
case OperatorType.TYPE_LOGIC_OR:
|
|
470
474
|
break;
|
|
471
|
-
case ContextType.
|
|
472
|
-
arr.splice(0, 1); // identifier of
|
|
475
|
+
case ContextType.TYPE_CONSTANT:
|
|
476
|
+
arr.splice(0, 1); // identifier of constant
|
|
473
477
|
break;
|
|
474
|
-
case ContextType.TYPE_WITNESS_ID: // add to
|
|
478
|
+
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
475
479
|
let addr = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(arr)).toString();
|
|
476
480
|
arr.splice(0, 32); // address
|
|
477
481
|
info.input_witness.push({index:this.get_index(), type:ContextType.TYPE_WITNESS_ID, value_or_witness:addr})
|
|
@@ -506,19 +510,19 @@ export class GuardParser {
|
|
|
506
510
|
} else if (type[0] == ContextType.TYPE_WITNESS_ID){
|
|
507
511
|
info.query_list.push({index:this.get_index(), type:type[0], value_or_witness:addr});
|
|
508
512
|
}
|
|
509
|
-
} else if (type[0] == ContextType.
|
|
513
|
+
} else if (type[0] == ContextType.TYPE_CONSTANT) {
|
|
510
514
|
let identifer = arr.splice(0, 2); // key + cmd
|
|
511
|
-
let
|
|
515
|
+
let constant = info.constant.find((v) =>
|
|
512
516
|
(v.identifier == identifer[0]) &&
|
|
513
517
|
((v.type == ValueType.TYPE_ADDRESS) || (v.type == ContextType.TYPE_WITNESS_ID)));
|
|
514
|
-
if (!
|
|
515
|
-
if (
|
|
516
|
-
info.query_list.push(
|
|
517
|
-
} else if (
|
|
518
|
-
info.query_list.push({identifier:identifer[0], type:
|
|
518
|
+
if (!constant) { ERROR(Errors.Fail, 'indentifier not in constant')}
|
|
519
|
+
if (constant?.type == ValueType.TYPE_ADDRESS) {
|
|
520
|
+
info.query_list.push(constant.value_or_witness);
|
|
521
|
+
} else if (constant?.type == ContextType.TYPE_WITNESS_ID) {
|
|
522
|
+
info.query_list.push({identifier:identifer[0], type:constant.type, value_or_witness:constant.value_or_witness, index:this.get_index()});
|
|
519
523
|
}
|
|
520
524
|
} else {
|
|
521
|
-
ERROR(Errors.Fail, '
|
|
525
|
+
ERROR(Errors.Fail, 'constant type invalid');
|
|
522
526
|
}
|
|
523
527
|
|
|
524
528
|
break;
|
|
@@ -543,7 +547,7 @@ export class GuardParser {
|
|
|
543
547
|
done = async (fill?:FutrueFill[]) : Promise<PassportQuery>=> {
|
|
544
548
|
let objects: string[] = [];
|
|
545
549
|
this.guard_list.forEach((g) => {
|
|
546
|
-
g.
|
|
550
|
+
g.constant.filter(v => v.type == ContextType.TYPE_WITNESS_ID).forEach((q) => {
|
|
547
551
|
objects.push(this.get_object(g.id, q, fill));
|
|
548
552
|
})
|
|
549
553
|
let list = g.query_list.map((q) => {
|
|
@@ -575,7 +579,7 @@ export class GuardParser {
|
|
|
575
579
|
query.push(object!);
|
|
576
580
|
})
|
|
577
581
|
res.forEach(q => {
|
|
578
|
-
let r1 = g.
|
|
582
|
+
let r1 = g.constant.find(v => v.future == q.data?.objectId);
|
|
579
583
|
let r2 = g.input_witness.find(v => v.future == q.data?.objectId)
|
|
580
584
|
// not match r1 || r2 means query-cmd, not witness-cmd
|
|
581
585
|
if (r1 || r2) {
|
package/src/permission.ts
CHANGED
|
@@ -143,14 +143,6 @@ export class Permission {
|
|
|
143
143
|
})
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
147
|
-
let txb = this.protocol.CurrentSession();
|
|
148
|
-
txb.moveCall({
|
|
149
|
-
target:this.protocol.PermissionFn(like) as FnCallType,
|
|
150
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
|
|
154
146
|
add_entity(entities:Permission_Entity[]) {
|
|
155
147
|
if (!entities) {
|
|
156
148
|
ERROR(Errors.InvalidParam, 'entities');
|
package/src/progress.ts
CHANGED
|
@@ -86,7 +86,7 @@ export class Progress {
|
|
|
86
86
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
87
87
|
})
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
/* move to: Entity.mark
|
|
90
90
|
mark(like:'like' | 'unlike', resource:Resource) {
|
|
91
91
|
let txb = this.protocol.CurrentSession();
|
|
92
92
|
txb.moveCall({
|
|
@@ -94,7 +94,7 @@ export class Progress {
|
|
|
94
94
|
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
95
95
|
})
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
*/
|
|
98
98
|
set_namedOperator(name:string, addresses:string[], passport?:PassportObject) {
|
|
99
99
|
if (!IsValidName(name)) {
|
|
100
100
|
ERROR(Errors.IsValidName, 'name')
|