wowok 1.2.5 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/demand.d.ts +3 -2
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +21 -7
- package/dist/entity.d.ts +2 -1
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +23 -7
- package/dist/exception.d.ts +3 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +3 -1
- package/dist/guard.js +1 -1
- package/dist/machine.js +2 -2
- package/dist/permission.d.ts +20 -4
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +146 -13
- package/dist/protocol.d.ts +30 -6
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +124 -17
- package/dist/repository.d.ts +6 -3
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +59 -40
- package/dist/resource.d.ts +20 -6
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +58 -21
- package/dist/reward.d.ts +6 -3
- package/dist/reward.d.ts.map +1 -1
- package/dist/reward.js +43 -19
- package/dist/service.d.ts +6 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +76 -44
- package/dist/utils.d.ts +15 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +150 -13
- package/dist/vote.d.ts +2 -2
- package/dist/vote.d.ts.map +1 -1
- package/dist/vote.js +14 -14
- package/package.json +1 -1
- package/src/demand.ts +26 -12
- package/src/entity.ts +33 -6
- package/src/exception.ts +3 -1
- package/src/guard.ts +2 -2
- package/src/machine.ts +207 -55
- package/src/permission.ts +168 -41
- package/src/progress.ts +101 -43
- package/src/protocol.ts +129 -20
- package/src/repository.ts +160 -53
- package/src/resource.ts +75 -24
- package/src/reward.ts +53 -32
- package/src/service.ts +109 -74
- package/src/utils.ts +174 -22
- package/src/vote.ts +30 -33
- package/src/wowok.ts +2 -2
package/src/resource.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { Protocol, FnCallType, TxbObject, ResourceAddress} from './protocol';
|
|
3
|
-
import { IsValidDesription, IsValidAddress, IsValidName, } from './utils';
|
|
3
|
+
import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
+
export interface Tags {
|
|
6
|
+
address: string;
|
|
7
|
+
nick: string;
|
|
8
|
+
tags: string[];
|
|
9
|
+
}
|
|
5
10
|
|
|
11
|
+
export interface ResourceData {
|
|
12
|
+
name: string;
|
|
13
|
+
address: string[];
|
|
14
|
+
}
|
|
6
15
|
|
|
7
16
|
export class Resource {
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
static MAX_ADDRESS_COUNT = 600;
|
|
18
|
+
static MAX_TAGS = 8;
|
|
19
|
+
|
|
20
|
+
static LikeName = "like";
|
|
21
|
+
static DislikeName = "dislike";
|
|
22
|
+
static FavorName = "favor";
|
|
12
23
|
|
|
13
24
|
protected object:TxbObject;
|
|
14
25
|
protected protocol;
|
|
@@ -25,64 +36,104 @@ export class Resource {
|
|
|
25
36
|
return r
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
if (!
|
|
30
|
-
|
|
39
|
+
launch() {
|
|
40
|
+
if (!this.object) ERROR(Errors.Fail, 'launch object Invalid');
|
|
41
|
+
let txb = this.protocol.CurrentSession();
|
|
42
|
+
txb.moveCall({
|
|
43
|
+
target:this.protocol.ResourceFn('create') as FnCallType,
|
|
44
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object)]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
add(name:string, object:string[]) {
|
|
48
|
+
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add');
|
|
49
|
+
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'add');
|
|
31
50
|
|
|
32
51
|
let txb = this.protocol.CurrentSession();
|
|
33
52
|
txb.moveCall({
|
|
34
53
|
target:this.protocol.ResourceFn('add') as FnCallType,
|
|
35
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
54
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.pure(object, 'vector<address>')]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
add2(object:string, name:string[]) {
|
|
59
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add2');
|
|
60
|
+
if (!IsValidArray(name, IsValidName)) ERROR(Errors.IsValidArray, 'add2');
|
|
61
|
+
if (!name) return
|
|
62
|
+
|
|
63
|
+
let txb = this.protocol.CurrentSession();
|
|
64
|
+
txb.moveCall({
|
|
65
|
+
target:this.protocol.ResourceFn('add2') as FnCallType,
|
|
66
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(name, 'vector<string>')]
|
|
36
67
|
});
|
|
37
68
|
}
|
|
38
69
|
|
|
39
|
-
remove(name:string, object
|
|
70
|
+
remove(name:string, object:string[], removeall?:boolean) {
|
|
40
71
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
41
|
-
if (
|
|
72
|
+
if (object.length===0 && !removeall) return;
|
|
42
73
|
|
|
43
74
|
let txb = this.protocol.CurrentSession();
|
|
44
75
|
if (removeall) {
|
|
45
76
|
txb.moveCall({
|
|
46
77
|
target:this.protocol.ResourceFn('remove_all') as FnCallType,
|
|
47
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
78
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name)]
|
|
48
79
|
});
|
|
49
80
|
} else if(object) {
|
|
50
|
-
if (!
|
|
81
|
+
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
|
|
51
82
|
|
|
52
83
|
txb.moveCall({
|
|
53
84
|
target:this.protocol.ResourceFn('remove') as FnCallType,
|
|
54
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
85
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.pure(object, 'vector<address>')]
|
|
55
86
|
});
|
|
56
87
|
}
|
|
57
88
|
}
|
|
58
89
|
|
|
90
|
+
remove2(object:string, name:string[]) {
|
|
91
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove2');
|
|
92
|
+
if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
|
|
93
|
+
if (!name) return
|
|
94
|
+
|
|
95
|
+
let txb = this.protocol.CurrentSession();
|
|
96
|
+
txb.moveCall({
|
|
97
|
+
target:this.protocol.ResourceFn('remove2') as FnCallType,
|
|
98
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(name, 'vector<string>')]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
59
102
|
rename(old_name:string, new_name:string) {
|
|
60
103
|
if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'Resource: rename');
|
|
61
104
|
|
|
62
105
|
let txb = this.protocol.CurrentSession();
|
|
63
106
|
txb.moveCall({
|
|
64
107
|
target:this.protocol.ResourceFn('rename') as FnCallType,
|
|
65
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_name
|
|
108
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_name), txb.pure(new_name)]
|
|
66
109
|
});
|
|
67
110
|
}
|
|
68
111
|
|
|
69
|
-
|
|
70
|
-
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, '
|
|
71
|
-
if (!
|
|
112
|
+
add_tags(object:string, nick:string, tags:string[]) {
|
|
113
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add_tags');
|
|
114
|
+
if (!nick || !tags) return;
|
|
115
|
+
if (!IsValidName(nick)) ERROR(Errors.IsValidName, 'add_tags');
|
|
116
|
+
if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'add_tags');
|
|
117
|
+
if (tags.length > Resource.MAX_TAGS) ERROR(Errors.InvalidParam, 'add_tags');
|
|
118
|
+
|
|
119
|
+
const txb = this.protocol.CurrentSession();
|
|
120
|
+
const encode = new TextEncoder();
|
|
72
121
|
|
|
73
|
-
let txb = this.protocol.CurrentSession();
|
|
74
122
|
txb.moveCall({
|
|
75
|
-
target:this.protocol.ResourceFn('
|
|
76
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS),
|
|
123
|
+
target:this.protocol.ResourceFn('tags_add') as FnCallType,
|
|
124
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS),
|
|
125
|
+
txb.pure(nick),
|
|
126
|
+
txb.pure(tags, 'vector<string>')
|
|
127
|
+
]
|
|
77
128
|
});
|
|
78
129
|
}
|
|
79
130
|
|
|
80
|
-
|
|
81
|
-
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource:
|
|
131
|
+
remove_tags(object:string) {
|
|
132
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove_tags');
|
|
82
133
|
|
|
83
134
|
let txb = this.protocol.CurrentSession();
|
|
84
135
|
txb.moveCall({
|
|
85
|
-
target:this.protocol.ResourceFn('
|
|
136
|
+
target:this.protocol.ResourceFn('tags_remove') as FnCallType,
|
|
86
137
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS)]
|
|
87
138
|
});
|
|
88
139
|
}
|
package/src/reward.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TransactionBlock, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
1
|
+
import { TransactionArgument, TransactionBlock, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { BCS} from '@mysten/bcs';
|
|
3
3
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
|
|
4
|
-
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription,
|
|
4
|
+
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUintLarge, } from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
6
|
import { Resource } from './resource';
|
|
7
7
|
|
|
@@ -31,7 +31,7 @@ export class Reward {
|
|
|
31
31
|
return r
|
|
32
32
|
}
|
|
33
33
|
static New(protocol:Protocol, earnest_type:string, permission:PermissionObject, description:string,
|
|
34
|
-
|
|
34
|
+
ms_expand:boolean, time:number, passport?:PassportObject) : Reward {
|
|
35
35
|
if (!Protocol.IsValidObjects([permission])) {
|
|
36
36
|
ERROR(Errors.IsValidObjects, 'permission')
|
|
37
37
|
}
|
|
@@ -41,8 +41,8 @@ export class Reward {
|
|
|
41
41
|
if (!IsValidDesription(description)) {
|
|
42
42
|
ERROR(Errors.IsValidDesription)
|
|
43
43
|
}
|
|
44
|
-
if (!
|
|
45
|
-
ERROR(Errors.IsValidUint, '
|
|
44
|
+
if (!IsValidUintLarge(time)) {
|
|
45
|
+
ERROR(Errors.IsValidUint, 'time')
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
let r = new Reward(protocol, earnest_type, permission);
|
|
@@ -51,14 +51,14 @@ export class Reward {
|
|
|
51
51
|
if (passport) {
|
|
52
52
|
r.object = txb.moveCall({
|
|
53
53
|
target:protocol.RewardFn('new_with_passport') as FnCallType,
|
|
54
|
-
arguments:[passport, txb.pure(description), txb.pure(
|
|
55
|
-
txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, permission)],
|
|
54
|
+
arguments:[passport, txb.pure(description), txb.pure(ms_expand, BCS.BOOL), txb.pure(time, BCS.U64),
|
|
55
|
+
txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, permission)],
|
|
56
56
|
typeArguments:[earnest_type]
|
|
57
57
|
})
|
|
58
58
|
} else {
|
|
59
59
|
r.object = txb.moveCall({
|
|
60
60
|
target:protocol.RewardFn('new') as FnCallType,
|
|
61
|
-
arguments:[txb.pure(description), txb.pure(
|
|
61
|
+
arguments:[txb.pure(description), txb.pure(ms_expand, BCS.BOOL), txb.pure(time, BCS.U64),
|
|
62
62
|
txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, permission)],
|
|
63
63
|
typeArguments:[earnest_type]
|
|
64
64
|
})
|
|
@@ -82,15 +82,7 @@ export class Reward {
|
|
|
82
82
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
87
|
-
let txb = this.protocol.CurrentSession();
|
|
88
|
-
txb.moveCall({
|
|
89
|
-
target:this.protocol.RewardFn(like) as FnCallType,
|
|
90
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
*/
|
|
85
|
+
|
|
94
86
|
refund(passport?:PassportObject) {
|
|
95
87
|
let txb = this.protocol.CurrentSession();
|
|
96
88
|
if (passport) {
|
|
@@ -108,8 +100,8 @@ export class Reward {
|
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
102
|
|
|
111
|
-
expand_time(
|
|
112
|
-
if (!
|
|
103
|
+
expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
|
|
104
|
+
if (!IsValidUintLarge(time)) {
|
|
113
105
|
ERROR(Errors.IsValidUint, 'minutes_expand')
|
|
114
106
|
}
|
|
115
107
|
|
|
@@ -117,13 +109,15 @@ export class Reward {
|
|
|
117
109
|
if (passport) {
|
|
118
110
|
txb.moveCall({
|
|
119
111
|
target:this.protocol.RewardFn('time_expand_with_passport') as FnCallType,
|
|
120
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
112
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
|
|
113
|
+
txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
121
114
|
typeArguments:[this.earnest_type]
|
|
122
115
|
})
|
|
123
116
|
} else {
|
|
124
117
|
txb.moveCall({
|
|
125
118
|
target:this.protocol.RewardFn('time_expand') as FnCallType,
|
|
126
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
119
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
|
|
120
|
+
txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
127
121
|
typeArguments:[this.earnest_type]
|
|
128
122
|
})
|
|
129
123
|
}
|
|
@@ -131,13 +125,11 @@ export class Reward {
|
|
|
131
125
|
}
|
|
132
126
|
|
|
133
127
|
add_guard(gurads:RewardGuardPortions[], passport?:PassportObject) {
|
|
134
|
-
if (
|
|
135
|
-
ERROR(Errors.InvalidParam, 'gurads')
|
|
136
|
-
}
|
|
128
|
+
if (gurads.length === 0) return;
|
|
137
129
|
|
|
138
130
|
let bValid = true;
|
|
139
131
|
gurads.forEach((v) => {
|
|
140
|
-
if (!
|
|
132
|
+
if (!IsValidUintLarge(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
|
|
141
133
|
if (!Protocol.IsValidObjects([v.guard])) bValid = false;
|
|
142
134
|
})
|
|
143
135
|
if (!bValid) {
|
|
@@ -168,11 +160,11 @@ export class Reward {
|
|
|
168
160
|
}
|
|
169
161
|
|
|
170
162
|
remove_guard(guards:string[], removeall?:boolean, passport?:PassportObject) {
|
|
171
|
-
if (!removeall &&
|
|
172
|
-
|
|
163
|
+
if (!removeall && guards.length===0) {
|
|
164
|
+
return
|
|
173
165
|
}
|
|
174
166
|
|
|
175
|
-
if (
|
|
167
|
+
if (!IsValidArray(guards, IsValidAddress)) {
|
|
176
168
|
ERROR(Errors.IsValidArray, 'guards')
|
|
177
169
|
}
|
|
178
170
|
|
|
@@ -284,7 +276,8 @@ export class Reward {
|
|
|
284
276
|
}
|
|
285
277
|
;
|
|
286
278
|
}
|
|
287
|
-
deposit(rewards:
|
|
279
|
+
deposit(rewards:TransactionResult[]) {
|
|
280
|
+
console.log(rewards)
|
|
288
281
|
if (!rewards || !Protocol.IsValidObjects(rewards)) {
|
|
289
282
|
ERROR(Errors.IsValidArray)
|
|
290
283
|
}
|
|
@@ -296,6 +289,23 @@ export class Reward {
|
|
|
296
289
|
typeArguments:[this.earnest_type]
|
|
297
290
|
})
|
|
298
291
|
}
|
|
292
|
+
allow_claim(bAllowClaim: boolean, passport?:PassportObject) {
|
|
293
|
+
let txb = this.protocol.CurrentSession();
|
|
294
|
+
if (passport) {
|
|
295
|
+
txb.moveCall({
|
|
296
|
+
target:this.protocol.RewardFn('allow_claim_with_passport') as FnCallType,
|
|
297
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission),
|
|
298
|
+
txb.pure(bAllowClaim, BCS.BOOL)],
|
|
299
|
+
typeArguments:[this.earnest_type]
|
|
300
|
+
})
|
|
301
|
+
} else {
|
|
302
|
+
txb.moveCall({
|
|
303
|
+
target:this.protocol.RewardFn('allow_claim') as FnCallType,
|
|
304
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), txb.pure(bAllowClaim, BCS.BOOL)],
|
|
305
|
+
typeArguments:[this.earnest_type]
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
}
|
|
299
309
|
|
|
300
310
|
change_permission(new_permission:PermissionObject) {
|
|
301
311
|
if (!Protocol.IsValidObjects([new_permission])) {
|
|
@@ -304,12 +314,23 @@ export class Reward {
|
|
|
304
314
|
|
|
305
315
|
let txb = this.protocol.CurrentSession();
|
|
306
316
|
txb.moveCall({
|
|
307
|
-
target:this.protocol.RewardFn('
|
|
317
|
+
target:this.protocol.RewardFn('permission_set') as FnCallType,
|
|
308
318
|
arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
|
|
309
319
|
typeArguments:[this.earnest_type]
|
|
310
320
|
})
|
|
311
321
|
this.permission = new_permission
|
|
312
322
|
}
|
|
313
|
-
|
|
314
|
-
|
|
323
|
+
static parseObjectType = (chain_type:string) : string => {
|
|
324
|
+
if (chain_type) {
|
|
325
|
+
const s = 'reward::Reward<'
|
|
326
|
+
const i = chain_type.indexOf(s);
|
|
327
|
+
if (i > 0) {
|
|
328
|
+
let r = chain_type.slice(i + s.length, chain_type.length-1);
|
|
329
|
+
return r
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return '';
|
|
333
|
+
}
|
|
334
|
+
static MAX_PORTIONS_COUNT = 600;
|
|
335
|
+
static MAX_GUARD_COUNT = 16;
|
|
315
336
|
}
|