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/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 stack.pop()
|
|
257
|
+
return {object:stack.pop()!, constant:constants};
|
|
273
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
|
+
}
|
|
274
264
|
|
|
275
|
-
|
|
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);
|
|
277
|
+
}
|
|
278
|
+
|
|
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;
|
|
@@ -404,6 +408,7 @@ export class GuardParser {
|
|
|
404
408
|
|
|
405
409
|
stack.push(current);
|
|
406
410
|
return;
|
|
411
|
+
|
|
407
412
|
}
|
|
408
413
|
ERROR(Errors.Fail, 'OperateParamCount: type invalid ' + current.type);
|
|
409
414
|
}
|
|
@@ -425,8 +430,8 @@ export class GuardParser {
|
|
|
425
430
|
let index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => {return v.includes('guard::Guard') && v == c.type});
|
|
426
431
|
if (index == -1) return;
|
|
427
432
|
|
|
428
|
-
let info:GuardInfo = {id: c.fields.id.id, query_list:[],
|
|
429
|
-
me.
|
|
433
|
+
let info:GuardInfo = {id: c.fields.id.id, query_list:[], constant:[], input_witness:[]};
|
|
434
|
+
me.parse_constant(info, c.fields.constants);
|
|
430
435
|
if (c.fields.input.type == (protocol.Package() + '::bcs::BCS')) {
|
|
431
436
|
me.parse_bcs(info, Uint8Array.from(c.fields.input.fields.bytes));
|
|
432
437
|
}
|
|
@@ -435,12 +440,12 @@ export class GuardParser {
|
|
|
435
440
|
return me
|
|
436
441
|
}
|
|
437
442
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
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')) {
|
|
441
446
|
// ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for using
|
|
442
447
|
if (v.fields.type == ContextType.TYPE_WITNESS_ID || v.fields.type == ValueType.TYPE_ADDRESS) {
|
|
443
|
-
info.
|
|
448
|
+
info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:v.fields.type,
|
|
444
449
|
value_or_witness:'0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(v.fields.value))});
|
|
445
450
|
}
|
|
446
451
|
}
|
|
@@ -467,10 +472,10 @@ export class GuardParser {
|
|
|
467
472
|
case OperatorType.TYPE_LOGIC_AND:
|
|
468
473
|
case OperatorType.TYPE_LOGIC_OR:
|
|
469
474
|
break;
|
|
470
|
-
case ContextType.
|
|
471
|
-
arr.splice(0, 1); // identifier of
|
|
475
|
+
case ContextType.TYPE_CONSTANT:
|
|
476
|
+
arr.splice(0, 1); // identifier of constant
|
|
472
477
|
break;
|
|
473
|
-
case ContextType.TYPE_WITNESS_ID: // add to
|
|
478
|
+
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
474
479
|
let addr = '0x' + Bcs.getInstance().de(BCS.ADDRESS, Uint8Array.from(arr)).toString();
|
|
475
480
|
arr.splice(0, 32); // address
|
|
476
481
|
info.input_witness.push({index:this.get_index(), type:ContextType.TYPE_WITNESS_ID, value_or_witness:addr})
|
|
@@ -505,19 +510,19 @@ export class GuardParser {
|
|
|
505
510
|
} else if (type[0] == ContextType.TYPE_WITNESS_ID){
|
|
506
511
|
info.query_list.push({index:this.get_index(), type:type[0], value_or_witness:addr});
|
|
507
512
|
}
|
|
508
|
-
} else if (type[0] == ContextType.
|
|
513
|
+
} else if (type[0] == ContextType.TYPE_CONSTANT) {
|
|
509
514
|
let identifer = arr.splice(0, 2); // key + cmd
|
|
510
|
-
let
|
|
515
|
+
let constant = info.constant.find((v) =>
|
|
511
516
|
(v.identifier == identifer[0]) &&
|
|
512
517
|
((v.type == ValueType.TYPE_ADDRESS) || (v.type == ContextType.TYPE_WITNESS_ID)));
|
|
513
|
-
if (!
|
|
514
|
-
if (
|
|
515
|
-
info.query_list.push(
|
|
516
|
-
} else if (
|
|
517
|
-
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()});
|
|
518
523
|
}
|
|
519
524
|
} else {
|
|
520
|
-
ERROR(Errors.Fail, '
|
|
525
|
+
ERROR(Errors.Fail, 'constant type invalid');
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
break;
|
|
@@ -542,7 +547,7 @@ export class GuardParser {
|
|
|
542
547
|
done = async (fill?:FutrueFill[]) : Promise<PassportQuery>=> {
|
|
543
548
|
let objects: string[] = [];
|
|
544
549
|
this.guard_list.forEach((g) => {
|
|
545
|
-
g.
|
|
550
|
+
g.constant.filter(v => v.type == ContextType.TYPE_WITNESS_ID).forEach((q) => {
|
|
546
551
|
objects.push(this.get_object(g.id, q, fill));
|
|
547
552
|
})
|
|
548
553
|
let list = g.query_list.map((q) => {
|
|
@@ -574,7 +579,7 @@ export class GuardParser {
|
|
|
574
579
|
query.push(object!);
|
|
575
580
|
})
|
|
576
581
|
res.forEach(q => {
|
|
577
|
-
let r1 = g.
|
|
582
|
+
let r1 = g.constant.find(v => v.future == q.data?.objectId);
|
|
578
583
|
let r2 = g.input_witness.find(v => v.future == q.data?.objectId)
|
|
579
584
|
// not match r1 || r2 means query-cmd, not witness-cmd
|
|
580
585
|
if (r1 || r2) {
|
package/src/permission.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { BCS } from '@mysten/bcs';
|
|
|
2
2
|
import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
|
|
3
3
|
import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs} from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
+
import { Resource } from './resource';
|
|
5
6
|
|
|
6
7
|
export enum PermissionIndex {
|
|
7
8
|
repository = 100,
|
|
@@ -113,12 +114,11 @@ export class Permission {
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
static New(protocol:Protocol, description:string) : Permission {
|
|
116
|
-
let p = new Permission(protocol);
|
|
117
|
-
|
|
118
117
|
if (!IsValidDesription(description)) {
|
|
119
118
|
ERROR(Errors.IsValidDesription)
|
|
120
119
|
}
|
|
121
120
|
|
|
121
|
+
let p = new Permission(protocol);
|
|
122
122
|
let txb = protocol.CurrentSession();
|
|
123
123
|
p.object = txb.moveCall({
|
|
124
124
|
target: protocol.PermissionFn('new') as FnCallType,
|
|
@@ -134,14 +134,15 @@ export class Permission {
|
|
|
134
134
|
arguments:[ Protocol.TXB_OBJECT(txb, this.object) ]
|
|
135
135
|
})
|
|
136
136
|
}
|
|
137
|
+
|
|
137
138
|
destroy() {
|
|
138
139
|
let txb = this.protocol.CurrentSession();
|
|
139
140
|
txb.moveCall({
|
|
140
141
|
target:this.protocol.PermissionFn('destroy') as FnCallType,
|
|
141
142
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
142
|
-
})
|
|
143
|
-
|
|
143
|
+
})
|
|
144
144
|
}
|
|
145
|
+
|
|
145
146
|
add_entity(entities:Permission_Entity[]) {
|
|
146
147
|
if (!entities) {
|
|
147
148
|
ERROR(Errors.InvalidParam, 'entities');
|
package/src/progress.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { FnCallType, PermissionObject, RepositoryObject, PassportObject, Machine
|
|
|
4
4
|
TxbObject} from './protocol';
|
|
5
5
|
import { Bcs, array_unique,IsValidName, IsValidAddress, IsValidArray, OptionNone, IsValidInt } from './utils'
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
7
|
+
import { Resource } from './resource';
|
|
7
8
|
|
|
8
9
|
export type ProgressNext = {
|
|
9
10
|
next_node_name: string;
|
|
@@ -34,12 +35,11 @@ export class Progress {
|
|
|
34
35
|
return p
|
|
35
36
|
}
|
|
36
37
|
static New(protocol:Protocol, machine:MachineObject, permission:PermissionObject, passport?:PassportObject) : Progress {
|
|
37
|
-
let p = new Progress(protocol, machine, permission);
|
|
38
|
-
|
|
39
38
|
if (!Protocol.IsValidObjects([machine, permission])) {
|
|
40
39
|
ERROR(Errors.IsValidObjects, 'machine & permission')
|
|
41
40
|
}
|
|
42
41
|
|
|
42
|
+
let p = new Progress(protocol, machine, permission);
|
|
43
43
|
let txb = protocol.CurrentSession();
|
|
44
44
|
|
|
45
45
|
if (passport) {
|
|
@@ -86,7 +86,15 @@ export class Progress {
|
|
|
86
86
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
87
87
|
})
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
/* move to: Entity.mark
|
|
90
|
+
mark(like:'like' | 'unlike', resource:Resource) {
|
|
91
|
+
let txb = this.protocol.CurrentSession();
|
|
92
|
+
txb.moveCall({
|
|
93
|
+
target:this.protocol.ProgressFn(like) as FnCallType,
|
|
94
|
+
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
*/
|
|
90
98
|
set_namedOperator(name:string, addresses:string[], passport?:PassportObject) {
|
|
91
99
|
if (!IsValidName(name)) {
|
|
92
100
|
ERROR(Errors.IsValidName, 'name')
|
package/src/protocol.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
|
4
4
|
import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
|
|
5
5
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
6
6
|
import { capitalize, IsValidArray } from './utils'
|
|
7
|
-
import {
|
|
7
|
+
import { GuardConstant } from './guard';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
export enum MODULES {
|
|
@@ -21,6 +21,8 @@ export enum MODULES {
|
|
|
21
21
|
order = 'order',
|
|
22
22
|
reward = 'reward',
|
|
23
23
|
service = 'service',
|
|
24
|
+
resource = 'resource',
|
|
25
|
+
entity = 'entity',
|
|
24
26
|
wowok = 'wowok',
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -47,9 +49,13 @@ export type DiscountObject = TransactionResult | string;
|
|
|
47
49
|
export type CoinObject = TransactionResult | string;
|
|
48
50
|
export type VoteObject = TransactionResult | string;
|
|
49
51
|
export type VoteAddress = TransactionResult;
|
|
52
|
+
export type ResourceObject = TransactionResult | string;
|
|
53
|
+
export type ResourceAddress = TransactionResult;
|
|
54
|
+
export type EntityObject = TransactionResult | string;
|
|
55
|
+
export type EntityAddress = TransactionResult;
|
|
50
56
|
|
|
51
57
|
export type TxbObject = string | TransactionResult | GuardObject | RepositoryObject | PermissionObject | MachineObject | PassportObject |
|
|
52
|
-
DemandObject | ServiceObject | RewardObject | OrderObject | DiscountObject | VoteObject | DemandObject;
|
|
58
|
+
DemandObject | ServiceObject | RewardObject | OrderObject | DiscountObject | VoteObject | DemandObject | ResourceObject | EntityObject;
|
|
53
59
|
|
|
54
60
|
export type WowokObject = TransactionResult;
|
|
55
61
|
export type FnCallType = `${string}::${string}::${string}`;
|
|
@@ -100,38 +106,39 @@ export const IsValidValueType = (type:number) => { return ValueTypeArray.include
|
|
|
100
106
|
interface ValueTypeString {
|
|
101
107
|
type: ValueType;
|
|
102
108
|
name: string;
|
|
109
|
+
description: string;
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
export const SER_VALUE: ValueTypeString[] = [
|
|
106
|
-
{type: ValueType.TYPE_BOOL, name: 'bool'},
|
|
107
|
-
{type: ValueType.TYPE_ADDRESS, name: 'address'},
|
|
108
|
-
{type: ValueType.TYPE_U64, name: '
|
|
109
|
-
{type: ValueType.TYPE_U8, name: '
|
|
110
|
-
{type: ValueType.TYPE_VEC_U8, name: '
|
|
111
|
-
{type: ValueType.TYPE_U128, name: '
|
|
112
|
-
{type: ValueType.TYPE_VEC_ADDRESS, name: '
|
|
113
|
-
{type: ValueType.TYPE_VEC_BOOL, name: '
|
|
114
|
-
{type: ValueType.TYPE_VEC_VEC_U8, name: '
|
|
115
|
-
{type: ValueType.TYPE_VEC_U64, name: '
|
|
116
|
-
{type: ValueType.TYPE_VEC_U128, name: '
|
|
117
|
-
{type: ValueType.TYPE_OPTION_ADDRESS, name: '
|
|
118
|
-
{type: ValueType.TYPE_OPTION_BOOL, name: '
|
|
119
|
-
{type: ValueType.TYPE_OPTION_U8, name: '
|
|
120
|
-
{type: ValueType.TYPE_OPTION_U64, name: '
|
|
121
|
-
{type: ValueType.TYPE_OPTION_U128, name: '
|
|
122
|
-
{type: ValueType.TYPE_OPTION_U256, name: '
|
|
123
|
-
{type: ValueType.TYPE_VEC_U256, name: '
|
|
124
|
-
{type: ValueType.TYPE_U256, name: '
|
|
113
|
+
{type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false'},
|
|
114
|
+
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af'},
|
|
115
|
+
{type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233'},
|
|
116
|
+
{type: ValueType.TYPE_U8, name: 'number', description:'unsigned-8 number. eg:255'},
|
|
117
|
+
{type: ValueType.TYPE_VEC_U8, name: '[number]', description:'unsigned-8 number array. eg:"wowok"'},
|
|
118
|
+
{type: ValueType.TYPE_U128, name: 'number', description:'unsigned-8 number. eg:12348900999'},
|
|
119
|
+
{type: ValueType.TYPE_VEC_ADDRESS, name: '[address]', description:'address array. eg:[0x2277f2, 0x3344af]'},
|
|
120
|
+
{type: ValueType.TYPE_VEC_BOOL, name: '[bool]', description:'boolean array. eg:[true, false, true]'},
|
|
121
|
+
{type: ValueType.TYPE_VEC_VEC_U8, name: '[[number]]', description:'array of unsigned-8 number array. eg:["i", "like", "wowok"]'},
|
|
122
|
+
{type: ValueType.TYPE_VEC_U64, name: '[number]', description:'unsigned-64 number array. eg:[123, 778888, 42312]'},
|
|
123
|
+
{type: ValueType.TYPE_VEC_U128, name: '[number]', description:'unsigned-128 number array. eg:[123, 778888, 42312]'},
|
|
124
|
+
{type: ValueType.TYPE_OPTION_ADDRESS, name: 'option', description:'option of address. eg:none or address'},
|
|
125
|
+
{type: ValueType.TYPE_OPTION_BOOL, name: 'option', description:'option of bool. eg:none or boolean value'},
|
|
126
|
+
{type: ValueType.TYPE_OPTION_U8, name: 'option', description:'option of u8. eg:none or u8 value'},
|
|
127
|
+
{type: ValueType.TYPE_OPTION_U64, name: 'option', description:'option of u64. eg:none or u64 value'},
|
|
128
|
+
{type: ValueType.TYPE_OPTION_U128, name: 'option', description:'option of u128. eg:none or u128 value'},
|
|
129
|
+
{type: ValueType.TYPE_OPTION_U256, name: 'option', description:'option of u256. eg:none or u256 value'},
|
|
130
|
+
{type: ValueType.TYPE_VEC_U256, name: '[number]', description:'unsigned-256 number array. eg:[123, 778888, 42312]'},
|
|
131
|
+
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233'},
|
|
125
132
|
]
|
|
126
133
|
|
|
127
134
|
export enum ContextType {
|
|
128
135
|
TYPE_SIGNER = 60,
|
|
129
136
|
TYPE_CLOCK = 61,
|
|
130
137
|
TYPE_WITNESS_ID = 62,
|
|
131
|
-
|
|
138
|
+
TYPE_CONSTANT = 80,
|
|
132
139
|
}
|
|
133
140
|
|
|
134
|
-
export type
|
|
141
|
+
export type ConstantType = ValueType | ContextType.TYPE_WITNESS_ID;
|
|
135
142
|
export type Data_Type = ValueType | OperatorType | ContextType;
|
|
136
143
|
|
|
137
144
|
export enum ENTRYPOINT {
|
|
@@ -145,7 +152,8 @@ export class Protocol {
|
|
|
145
152
|
protected network = '';
|
|
146
153
|
protected package = '';
|
|
147
154
|
protected signer = '';
|
|
148
|
-
protected
|
|
155
|
+
protected wowok_object = '';
|
|
156
|
+
protected entity_object = '';
|
|
149
157
|
protected graphql = '';
|
|
150
158
|
protected txb: TransactionBlock | undefined;
|
|
151
159
|
|
|
@@ -157,14 +165,13 @@ export class Protocol {
|
|
|
157
165
|
this.network = network;
|
|
158
166
|
switch(network) {
|
|
159
167
|
case ENTRYPOINT.localnet:
|
|
160
|
-
this.package = "0xe9721254e97dd074e06c5efe5c57be169b64b39ae48939d89c00bf2f62b19e10";
|
|
161
|
-
this.everyone_guard = "0xb2a3fe7881cb883743c4e962b7e3c7716a1cd47a67adad01dc79795def4f769d";
|
|
162
168
|
break;
|
|
163
169
|
case ENTRYPOINT.devnet:
|
|
164
170
|
break;
|
|
165
171
|
case ENTRYPOINT.testnet:
|
|
166
|
-
this.package = "
|
|
167
|
-
this.
|
|
172
|
+
this.package = "0x2ac00805aa0ec3c62b575e412108bb295389bbfc86202fd7b73c69dbbb80769a";
|
|
173
|
+
this.wowok_object = '0x49d49fb41c63c3f6c838fca20c25741f20aa74a176391685446794bdaa9b7934';
|
|
174
|
+
this.entity_object= '0xd21d8d76f553b2db6c6d28a8b2ae3405bec92f2a300676d80fcc004ca40b0a77';
|
|
168
175
|
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
169
176
|
break;
|
|
170
177
|
case ENTRYPOINT.mainnet:
|
|
@@ -172,7 +179,8 @@ export class Protocol {
|
|
|
172
179
|
};
|
|
173
180
|
}
|
|
174
181
|
Package(): string { return this.package }
|
|
175
|
-
|
|
182
|
+
WowokObject(): string { return this.wowok_object }
|
|
183
|
+
EntityObject(): string { return this.entity_object }
|
|
176
184
|
GraphqlUrl() : string { return this.graphql }
|
|
177
185
|
|
|
178
186
|
NetworkUrl() : string {
|
|
@@ -201,6 +209,8 @@ export class Protocol {
|
|
|
201
209
|
OrderFn = (fn:any) => { return `${this.package}::${MODULES.order}::${fn}`};
|
|
202
210
|
RewardFn = (fn: any) => { return `${this.package}::${MODULES.reward}::${fn}`};
|
|
203
211
|
ServiceFn = (fn: any) => { return `${this.package}::${MODULES.service}::${fn}`};
|
|
212
|
+
ResourceFn = (fn: any) => { return `${this.package}::${MODULES.resource}::${fn}`};
|
|
213
|
+
EntityFn = (fn: any) => { return `${this.package}::${MODULES.entity}::${fn}`};
|
|
204
214
|
WowokFn = (fn: any) => { return `${this.package}::${MODULES.wowok}::${fn}`};
|
|
205
215
|
|
|
206
216
|
Query = async (objects: Query_Param[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
|
|
@@ -325,7 +335,7 @@ export class RpcResultParser {
|
|
|
325
335
|
export type Query_Param = {
|
|
326
336
|
objectid: string;
|
|
327
337
|
callback: (protocol:Protocol, response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions)=>void;
|
|
328
|
-
parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array,
|
|
338
|
+
parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array, constant?:GuardConstant) => boolean;
|
|
329
339
|
data?: any; // response data filted by callback
|
|
330
|
-
|
|
340
|
+
constants?: GuardConstant;
|
|
331
341
|
};
|
package/src/repository.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Protocol, FnCallType, ValueType, RepositoryObject, RepositoryAddress, P
|
|
|
3
3
|
import { PermissionIndexType, Permission } from './permission'
|
|
4
4
|
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, } from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
|
+
import { Resource } from './resource';
|
|
6
7
|
|
|
7
8
|
export enum Repository_Policy_Mode {
|
|
8
9
|
POLICY_MODE_FREE = 0,
|
|
@@ -42,7 +43,6 @@ export class Repository {
|
|
|
42
43
|
}
|
|
43
44
|
static New(protocol:Protocol, permission:PermissionObject, description:string,
|
|
44
45
|
policy_mode: Repository_Policy_Mode, passport?:PassportObject) : Repository {
|
|
45
|
-
let r = new Repository(protocol, permission);
|
|
46
46
|
if (!Protocol.IsValidObjects([permission])) {
|
|
47
47
|
ERROR(Errors.IsValidObjects, 'permission')
|
|
48
48
|
}
|
|
@@ -50,6 +50,7 @@ export class Repository {
|
|
|
50
50
|
ERROR(Errors.IsValidDesription)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
let r = new Repository(protocol, permission);
|
|
53
54
|
let txb = protocol.CurrentSession();
|
|
54
55
|
|
|
55
56
|
if (passport) {
|
|
@@ -81,7 +82,16 @@ export class Repository {
|
|
|
81
82
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
82
83
|
})
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
+
/* move to: Entity.mark
|
|
86
|
+
mark(like:'like' | 'unlike', resource:Resource) {
|
|
87
|
+
if (!Protocol.IsValidObjects([this.object])) return false;
|
|
88
|
+
let txb = this.protocol.CurrentSession();
|
|
89
|
+
txb.moveCall({
|
|
90
|
+
target:this.protocol.RepositoryFn(like) as FnCallType,
|
|
91
|
+
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
*/
|
|
85
95
|
add_data(data:Repository_Policy_Data) {
|
|
86
96
|
if (!Repository.IsValidName(data.key)) {
|
|
87
97
|
ERROR(Errors.IsValidName)
|
package/src/resource.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { BCS } from '@mysten/bcs';
|
|
2
|
+
import { Protocol, FnCallType, TxbObject, ResourceAddress} from './protocol';
|
|
3
|
+
import { IsValidDesription, IsValidAddress, IsValidName, } from './utils';
|
|
4
|
+
import { ERROR, Errors } from './exception';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class Resource {
|
|
8
|
+
static MAX_WORDS_LEN = 102400;
|
|
9
|
+
static IsValidWords(words:string) : boolean {
|
|
10
|
+
return words.length <= Resource.MAX_WORDS_LEN
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
protected object:TxbObject;
|
|
14
|
+
protected protocol;
|
|
15
|
+
|
|
16
|
+
get_object() { return this.object }
|
|
17
|
+
private constructor(protocol:Protocol) {
|
|
18
|
+
this.protocol = protocol;
|
|
19
|
+
this.object = '';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static From(protocol:Protocol, object:TxbObject) : Resource {
|
|
23
|
+
let r = new Resource(protocol);
|
|
24
|
+
r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
|
|
25
|
+
return r
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
add(name:string, object:string) {
|
|
29
|
+
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: add');
|
|
30
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: add');
|
|
31
|
+
|
|
32
|
+
let txb = this.protocol.CurrentSession();
|
|
33
|
+
txb.moveCall({
|
|
34
|
+
target:this.protocol.ResourceFn('add') as FnCallType,
|
|
35
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.pure(object, BCS.ADDRESS)]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
remove(name:string, object?:string, removeall?:boolean) {
|
|
40
|
+
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
41
|
+
if (!object && !removeall) ERROR(Errors.InvalidParam, 'Resource: remove, BOTH param undefined');
|
|
42
|
+
|
|
43
|
+
let txb = this.protocol.CurrentSession();
|
|
44
|
+
if (removeall) {
|
|
45
|
+
txb.moveCall({
|
|
46
|
+
target:this.protocol.ResourceFn('remove_all') as FnCallType,
|
|
47
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING)]
|
|
48
|
+
});
|
|
49
|
+
} else if(object) {
|
|
50
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove');
|
|
51
|
+
|
|
52
|
+
txb.moveCall({
|
|
53
|
+
target:this.protocol.ResourceFn('remove') as FnCallType,
|
|
54
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.pure(object, BCS.ADDRESS)]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
rename(old_name:string, new_name:string) {
|
|
60
|
+
if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'Resource: rename');
|
|
61
|
+
|
|
62
|
+
let txb = this.protocol.CurrentSession();
|
|
63
|
+
txb.moveCall({
|
|
64
|
+
target:this.protocol.ResourceFn('rename') as FnCallType,
|
|
65
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_name, BCS.STRING), txb.pure(new_name, BCS.STRING)]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
add_words(object:string, words:string) {
|
|
70
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: add_words');
|
|
71
|
+
if (!Resource.IsValidWords(words)) ERROR(Errors.Fail, 'Resource: add_words');
|
|
72
|
+
|
|
73
|
+
let txb = this.protocol.CurrentSession();
|
|
74
|
+
txb.moveCall({
|
|
75
|
+
target:this.protocol.ResourceFn('words_add') as FnCallType,
|
|
76
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(words, BCS.STRING)]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
remove_words(object:string) {
|
|
81
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove_words');
|
|
82
|
+
|
|
83
|
+
let txb = this.protocol.CurrentSession();
|
|
84
|
+
txb.moveCall({
|
|
85
|
+
target:this.protocol.ResourceFn('words_remove') as FnCallType,
|
|
86
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS)]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|