wowok 1.1.4 → 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 +6 -6
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +38 -38
- 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 +66 -58
- 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.map +1 -1
- package/dist/machine.js +1 -1
- package/dist/passport.d.ts +16 -9
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +69 -59
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +1 -1
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +10 -1
- package/dist/protocol.d.ts +19 -8
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +31 -26
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +11 -1
- package/dist/resource.d.ts +16 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +83 -0
- package/dist/reward.d.ts.map +1 -1
- package/dist/reward.js +10 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +11 -1
- 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.map +1 -1
- package/dist/vote.js +1 -1
- 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 +42 -42
- package/src/entity.ts +83 -0
- package/src/exception.ts +1 -0
- package/src/guard.ts +71 -57
- package/src/index.ts +11 -8
- package/src/machine.ts +3 -2
- package/src/passport.ts +70 -65
- package/src/permission.ts +5 -4
- package/src/progress.ts +11 -3
- package/src/protocol.ts +41 -31
- package/src/repository.ts +12 -2
- package/src/resource.ts +90 -0
- package/src/reward.ts +11 -2
- package/src/service.ts +12 -1
- package/src/utils.ts +12 -1
- package/src/vote.ts +2 -1
- package/src/wowok.ts +56 -0
package/src/entity.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { BCS } from '@mysten/bcs';
|
|
2
|
+
import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject, ResourceObject} from './protocol';
|
|
3
|
+
import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, } from './utils';
|
|
4
|
+
import { ERROR, Errors } from './exception';
|
|
5
|
+
import { Resource } from './resource';
|
|
6
|
+
|
|
7
|
+
export interface Entity_Info {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
avatar?: string;
|
|
11
|
+
twitter?: string;
|
|
12
|
+
discord?: string;
|
|
13
|
+
homepage?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Entity {
|
|
17
|
+
|
|
18
|
+
protected object:TxbObject;
|
|
19
|
+
protected protocol;
|
|
20
|
+
|
|
21
|
+
get_object() { return this.object }
|
|
22
|
+
private constructor(protocol:Protocol) {
|
|
23
|
+
this.protocol = protocol;
|
|
24
|
+
this.object = '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static From(protocol:Protocol) : Entity {
|
|
28
|
+
let r = new Entity(protocol);
|
|
29
|
+
r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), protocol.EntityObject());
|
|
30
|
+
return r
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
mark(resource:Resource, address:string, like:'like' | 'dislike') {
|
|
34
|
+
if (!IsValidAddress(address)) ERROR(Errors.IsValidAddress, like);
|
|
35
|
+
|
|
36
|
+
let txb = this.protocol.CurrentSession();
|
|
37
|
+
txb.moveCall({
|
|
38
|
+
target:this.protocol.EntityFn(like) as FnCallType,
|
|
39
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, resource.get_object()), txb.pure(address, BCS.ADDRESS)]
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
update(info: Entity_Info) {
|
|
44
|
+
if (!IsValidName(info.name)) ERROR(Errors.IsValidName, 'update');
|
|
45
|
+
if (info?.description && !IsValidDesription(info.description)) ERROR(Errors.IsValidDesription, 'update');
|
|
46
|
+
if (info?.avatar && !isValidHttpUrl(info.avatar)) ERROR(Errors.isValidHttpUrl, 'update:avatar');
|
|
47
|
+
if (info?.twitter && !IsValidName(info.twitter)) ERROR(Errors.IsValidName, 'update:twitter');
|
|
48
|
+
if (info?.homepage && !isValidHttpUrl(info.homepage)) ERROR(Errors.isValidHttpUrl, 'update:homepage');
|
|
49
|
+
if (info?.discord && !IsValidName(info.discord)) ERROR(Errors.IsValidName, 'update:discord');
|
|
50
|
+
|
|
51
|
+
let txb = this.protocol.CurrentSession();
|
|
52
|
+
txb.moveCall({
|
|
53
|
+
target:this.protocol.EntityFn('avatar_update') as FnCallType,
|
|
54
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(JSON.stringify(info), BCS.STRING)]
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
create_resource(description:string) : ResourceAddress {
|
|
59
|
+
if (!IsValidDesription(description)) ERROR(Errors.IsValidDesription, 'create_resource');
|
|
60
|
+
let txb = this.protocol.CurrentSession();
|
|
61
|
+
return txb.moveCall({
|
|
62
|
+
target:this.protocol.EntityFn('resource_create') as FnCallType,
|
|
63
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(description, BCS.STRING)]
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
destroy_resource(resource:Resource) {
|
|
68
|
+
let txb = this.protocol.CurrentSession();
|
|
69
|
+
return txb.moveCall({
|
|
70
|
+
target:this.protocol.EntityFn('resource_destroy') as FnCallType,
|
|
71
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, resource.get_object())]
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
transfer_resource(resource:Resource, new_address:string) {
|
|
76
|
+
if (!IsValidAddress(new_address)) ERROR(Errors.IsValidAddress, 'transfer_resource');
|
|
77
|
+
let txb = this.protocol.CurrentSession();
|
|
78
|
+
return txb.moveCall({
|
|
79
|
+
target:this.protocol.EntityFn('resource_transfer') as FnCallType,
|
|
80
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, resource.get_object()), txb.pure(new_address, BCS.ADDRESS)]
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/exception.ts
CHANGED
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
|
}
|
|
@@ -88,6 +88,7 @@ export class Guard {
|
|
|
88
88
|
arguments: []
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
+
|
|
91
92
|
static QUERIES:any[] = [
|
|
92
93
|
// module, 'name', 'id', [input], output
|
|
93
94
|
[MODULES.permission, 'builder', 1, [], ValueType.TYPE_ADDRESS],
|
|
@@ -217,53 +218,66 @@ export class Guard {
|
|
|
217
218
|
[MODULES.vote, 'top1_count', 190, [], ValueType.TYPE_U64],
|
|
218
219
|
[MODULES.vote, 'top1_name_by_votes', 191, [], ValueType.TYPE_VEC_U8],
|
|
219
220
|
[MODULES.vote, 'top1_votes', 192, [], ValueType.TYPE_U64],
|
|
221
|
+
|
|
222
|
+
[MODULES.wowok, 'initor', 210, [], ValueType.TYPE_ADDRESS],
|
|
223
|
+
[MODULES.wowok, 'everyone_guard', 211, [], ValueType.TYPE_ADDRESS],
|
|
224
|
+
[MODULES.wowok, 'entities', 212, [], ValueType.TYPE_ADDRESS],
|
|
225
|
+
[MODULES.wowok, 'grantor_count', 213, [], ValueType.TYPE_U64],
|
|
226
|
+
[MODULES.wowok, 'has_grantor', 214, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL],
|
|
227
|
+
[MODULES.wowok, 'grantor_name', 215, [ValueType.TYPE_ADDRESS], ValueType.TYPE_VEC_U8],
|
|
228
|
+
[MODULES.wowok, 'grantor_register_time', 216, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
229
|
+
[MODULES.wowok, 'grantor_expired_time', 217, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
230
|
+
[MODULES.wowok, 'grantor_grantee', 218, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS],
|
|
231
|
+
|
|
232
|
+
[MODULES.entity, 'has_entity', 230, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL],
|
|
233
|
+
[MODULES.entity, 'entity_like', 231, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
234
|
+
[MODULES.entity, 'entity_dislike', 232, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
235
|
+
[MODULES.entity, 'entity_infomation', 233, [ValueType.TYPE_ADDRESS], ValueType.TYPE_VEC_U8],
|
|
220
236
|
];
|
|
221
237
|
static BoolCmd = Guard.QUERIES.filter(q => q[4] == ValueType.TYPE_BOOL);
|
|
222
238
|
static IsBoolCmd = (cmd:number) : boolean => { return Guard.BoolCmd.includes((q:any) => {return q[2] == cmd}) }
|
|
223
239
|
static GetCmd = (cmd:number) : any => {
|
|
224
|
-
|
|
225
|
-
if (!r) { ERROR(Errors.Fail, 'CmdParamCount: not found')};
|
|
226
|
-
return r;
|
|
240
|
+
return Guard.QUERIES.find((q:any) => {return q[2] == cmd}) ;
|
|
227
241
|
}
|
|
228
242
|
}
|
|
229
243
|
|
|
230
|
-
export class
|
|
244
|
+
export class GuardConstantHelper {
|
|
231
245
|
static IsValidIndentifier = (identifier:number) : boolean => {
|
|
232
246
|
if (!IsValidInt(identifier) || identifier > 255) return false;
|
|
233
247
|
return true
|
|
234
248
|
}
|
|
235
|
-
static
|
|
236
|
-
if (
|
|
237
|
-
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);
|
|
238
252
|
if (v?.value && v.type == type) {
|
|
239
253
|
return v.value;
|
|
240
254
|
}
|
|
241
255
|
}
|
|
242
256
|
}
|
|
243
|
-
static
|
|
244
|
-
if (
|
|
245
|
-
let v =
|
|
257
|
+
static get_constant_witness(constants:GuardConstant, identifier:number) : Uint8Array | undefined {
|
|
258
|
+
if (constants.has(identifier)) {
|
|
259
|
+
let v = constants.get(identifier);
|
|
246
260
|
if (v?.witness && v.type == ContextType.TYPE_WITNESS_ID) {
|
|
247
261
|
return v.witness;
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
264
|
}
|
|
251
265
|
|
|
252
|
-
static
|
|
253
|
-
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');
|
|
254
268
|
if (!witness && !value) ERROR(Errors.InvalidParam, 'both witness and value invalid');
|
|
255
|
-
let v =
|
|
269
|
+
let v = constants.get(identifier);
|
|
256
270
|
if (!v || v.type == ContextType.TYPE_WITNESS_ID) {
|
|
257
271
|
if (bNeedSerialize) {
|
|
258
|
-
|
|
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})
|
|
259
273
|
} else {
|
|
260
|
-
|
|
274
|
+
constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value?value:undefined, witness:witness?witness:undefined});
|
|
261
275
|
}
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
278
|
|
|
265
|
-
static
|
|
266
|
-
if (!
|
|
279
|
+
static add_constant(constants:GuardConstant, identifier:number, type:ValueType, value:any, bNeedSerialize=true) {
|
|
280
|
+
if (!GuardConstantHelper.IsValidIndentifier(identifier)) return false;
|
|
267
281
|
if (!value) return false;
|
|
268
282
|
|
|
269
283
|
switch (type) {
|
|
@@ -286,26 +300,26 @@ export class GuardVariableHelper {
|
|
|
286
300
|
case ValueType.TYPE_VEC_U128:
|
|
287
301
|
case ValueType.TYPE_VEC_U256:
|
|
288
302
|
let ser = SER_VALUE.find(s=>s.type==type);
|
|
289
|
-
if (!ser) ERROR(Errors.Fail, '
|
|
290
|
-
bNeedSerialize ?
|
|
291
|
-
|
|
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})
|
|
292
306
|
return
|
|
293
307
|
case ValueType.TYPE_VEC_U8:
|
|
294
308
|
if (typeof(value) === 'string') {
|
|
295
|
-
|
|
309
|
+
constants.set(identifier, {type:type, value:Bcs.getInstance().ser_string(value)})
|
|
296
310
|
} else {
|
|
297
|
-
|
|
311
|
+
constants.set(identifier, {type:type, value:value})
|
|
298
312
|
}
|
|
299
313
|
return;
|
|
300
314
|
default:
|
|
301
|
-
ERROR(Errors.Fail, '
|
|
315
|
+
ERROR(Errors.Fail, 'add_constant serialize not impl yet')
|
|
302
316
|
}
|
|
303
317
|
}
|
|
304
318
|
}
|
|
305
319
|
export class GuardMaker {
|
|
306
320
|
protected data : Uint8Array[] = [];
|
|
307
321
|
protected type_validator : Data_Type[] = [];
|
|
308
|
-
protected
|
|
322
|
+
protected constant : GuardConstant = new Map();
|
|
309
323
|
|
|
310
324
|
private static index: number = 0;
|
|
311
325
|
private static get_index() {
|
|
@@ -317,13 +331,13 @@ export class GuardMaker {
|
|
|
317
331
|
|
|
318
332
|
constructor() { }
|
|
319
333
|
|
|
320
|
-
|
|
334
|
+
add_constant(type:ConstantType, value:any, bNeedSerialize=true) : number {
|
|
321
335
|
let identifier = GuardMaker.get_index();
|
|
322
336
|
if (type == ContextType.TYPE_WITNESS_ID) {
|
|
323
|
-
// add witness to
|
|
324
|
-
|
|
337
|
+
// add witness to constant
|
|
338
|
+
GuardConstantHelper.add_future_constant(this.constant, identifier, value, undefined, bNeedSerialize);
|
|
325
339
|
} else {
|
|
326
|
-
|
|
340
|
+
GuardConstantHelper.add_constant(this.constant, identifier, type, value, bNeedSerialize);
|
|
327
341
|
}
|
|
328
342
|
return identifier
|
|
329
343
|
}
|
|
@@ -384,7 +398,7 @@ export class GuardMaker {
|
|
|
384
398
|
this.data.push(Bcs.getInstance().ser_address(param));
|
|
385
399
|
this.type_validator.push(ValueType.TYPE_ADDRESS);
|
|
386
400
|
break;
|
|
387
|
-
case ContextType.
|
|
401
|
+
case ContextType.TYPE_CONSTANT:
|
|
388
402
|
if (!param) {
|
|
389
403
|
ERROR(Errors.InvalidParam, 'param invalid');
|
|
390
404
|
}
|
|
@@ -392,8 +406,8 @@ export class GuardMaker {
|
|
|
392
406
|
ERROR(Errors.InvalidParam, 'add_param param');
|
|
393
407
|
}
|
|
394
408
|
|
|
395
|
-
var v = this.
|
|
396
|
-
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');
|
|
397
411
|
this.type_validator.push(v!.type);
|
|
398
412
|
this.data.push(Bcs.getInstance().ser_u8(type));
|
|
399
413
|
this.data.push(Bcs.getInstance().ser_u8(param));
|
|
@@ -404,7 +418,7 @@ export class GuardMaker {
|
|
|
404
418
|
return this;
|
|
405
419
|
}
|
|
406
420
|
|
|
407
|
-
// object_address_from: string for static address; number as identifier
|
|
421
|
+
// object_address_from: string for static address; number as identifier inconstant
|
|
408
422
|
add_query(module:MODULES, query_name:string, object_address_from:string | number, bWitness:boolean=false) : GuardMaker {
|
|
409
423
|
let query_index = Guard.QUERIES.findIndex((q) => { return q[0] == module && q[1] == query_name})
|
|
410
424
|
if (query_index == -1) {
|
|
@@ -412,7 +426,7 @@ export class GuardMaker {
|
|
|
412
426
|
}
|
|
413
427
|
|
|
414
428
|
if (typeof(object_address_from) == 'number' ) {
|
|
415
|
-
if (!
|
|
429
|
+
if (!GuardConstantHelper.IsValidIndentifier(object_address_from)) {
|
|
416
430
|
ERROR(Errors.InvalidParam, 'object_address_from');
|
|
417
431
|
}
|
|
418
432
|
} else {
|
|
@@ -437,11 +451,11 @@ export class GuardMaker {
|
|
|
437
451
|
this.data.push(Bcs.getInstance().ser_u8(ValueType.TYPE_ADDRESS));
|
|
438
452
|
this.data.push(Bcs.getInstance().ser_address(object_address_from)); // object address
|
|
439
453
|
} else {
|
|
440
|
-
let v = this.
|
|
441
|
-
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');
|
|
442
456
|
if ((bWitness && v?.type == ContextType.TYPE_WITNESS_ID) || (!bWitness && v?.type == ValueType.TYPE_ADDRESS)) {
|
|
443
|
-
this.data.push(Bcs.getInstance().ser_u8(ContextType.
|
|
444
|
-
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
|
|
445
459
|
} else {
|
|
446
460
|
ERROR(Errors.Fail, 'type bWitness not match')
|
|
447
461
|
}
|
|
@@ -509,17 +523,17 @@ export class GuardMaker {
|
|
|
509
523
|
return this.type_validator.length == 1 && this.type_validator[0] == ValueType.TYPE_BOOL && this.data.length == 1;
|
|
510
524
|
}
|
|
511
525
|
|
|
512
|
-
combine(otherBuilt:GuardMaker, bAnd:boolean = true,
|
|
526
|
+
combine(otherBuilt:GuardMaker, bAnd:boolean = true, bCombinConstant=false) : GuardMaker {
|
|
513
527
|
if (!otherBuilt.IsReady() || !this.IsReady()) { ERROR(Errors.Fail, 'both should built yet')};
|
|
514
528
|
let maker = new GuardMaker();
|
|
515
|
-
this.
|
|
516
|
-
maker.
|
|
529
|
+
this.constant.forEach((v, k) => {
|
|
530
|
+
maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
|
|
517
531
|
})
|
|
518
|
-
otherBuilt.
|
|
519
|
-
if (maker.
|
|
520
|
-
ERROR(Errors.Fail, '
|
|
532
|
+
otherBuilt.constant.forEach((v, k) => {
|
|
533
|
+
if (maker.constant.has(k) && !bCombinConstant) {
|
|
534
|
+
ERROR(Errors.Fail, 'constant identifier exist');
|
|
521
535
|
}
|
|
522
|
-
maker.
|
|
536
|
+
maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
|
|
523
537
|
})
|
|
524
538
|
let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
|
|
525
539
|
maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser_u8(op)));
|
|
@@ -528,7 +542,7 @@ export class GuardMaker {
|
|
|
528
542
|
return maker
|
|
529
543
|
}
|
|
530
544
|
|
|
531
|
-
|
|
545
|
+
get_constant() { return this.constant }
|
|
532
546
|
get_input() { return this.data }
|
|
533
547
|
|
|
534
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
|
@@ -5,6 +5,7 @@ import { IsValidInt, IsValidUint, Bcs, array_unique, IsValidArray, IsValidAddres
|
|
|
5
5
|
IsValidEndpoint, OptionNone, IsValidDesription} from './utils'
|
|
6
6
|
import { Permission, PermissionIndexType } from './permission';
|
|
7
7
|
import { Errors, ERROR} from './exception'
|
|
8
|
+
import { Resource } from './resource';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
export type MachineNodeObject = TransactionResult | String;
|
|
@@ -46,8 +47,6 @@ export class Machine {
|
|
|
46
47
|
this.object = '';
|
|
47
48
|
}
|
|
48
49
|
static New(protocol:Protocol, permission:PermissionObject, description:string, endpoint?:string, passport?:PassportObject) : Machine {
|
|
49
|
-
let m = new Machine(protocol, permission);
|
|
50
|
-
|
|
51
50
|
if (!Protocol.IsValidObjects([permission])) {
|
|
52
51
|
ERROR(Errors.IsValidObjects, 'permission')
|
|
53
52
|
}
|
|
@@ -57,6 +56,8 @@ export class Machine {
|
|
|
57
56
|
if (endpoint && !IsValidEndpoint(endpoint)) {
|
|
58
57
|
ERROR(Errors.IsValidEndpoint)
|
|
59
58
|
}
|
|
59
|
+
|
|
60
|
+
let m = new Machine(protocol, permission);
|
|
60
61
|
let txb = protocol.CurrentSession();
|
|
61
62
|
let ep = endpoint? txb.pure(Bcs.getInstance().ser_option_string(endpoint)) : OptionNone(txb);
|
|
62
63
|
|