wowok 1.2.5 → 1.2.7
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 +22 -8
- package/src/entity.ts +25 -6
- package/src/exception.ts +3 -1
- package/src/guard.ts +1 -1
- package/src/machine.ts +2 -2
- package/src/permission.ts +165 -10
- package/src/protocol.ts +127 -17
- package/src/repository.ts +64 -44
- package/src/resource.ts +61 -20
- package/src/reward.ts +46 -23
- package/src/service.ts +79 -46
- package/src/utils.ts +141 -15
- package/src/vote.ts +14 -14
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,18 +36,31 @@ export class Resource {
|
|
|
25
36
|
return r
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
add(name:string, object:string) {
|
|
29
|
-
if (!IsValidName(name)) ERROR(Errors.IsValidName, '
|
|
30
|
-
if (!
|
|
39
|
+
add(name:string, object:string[]) {
|
|
40
|
+
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add');
|
|
41
|
+
if (!object) ERROR(Errors.InvalidParam, 'add')
|
|
42
|
+
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'add');
|
|
31
43
|
|
|
32
44
|
let txb = this.protocol.CurrentSession();
|
|
33
45
|
txb.moveCall({
|
|
34
46
|
target:this.protocol.ResourceFn('add') as FnCallType,
|
|
35
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.pure(object,
|
|
47
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.pure(object, 'vector<address>')]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
add2(object:string, name:string[]) {
|
|
52
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add2');
|
|
53
|
+
if (!IsValidArray(name, IsValidName)) ERROR(Errors.IsValidArray, 'add2');
|
|
54
|
+
if (!name) return
|
|
55
|
+
|
|
56
|
+
let txb = this.protocol.CurrentSession();
|
|
57
|
+
txb.moveCall({
|
|
58
|
+
target:this.protocol.ResourceFn('add2') as FnCallType,
|
|
59
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(name, 'vector<string>')]
|
|
36
60
|
});
|
|
37
61
|
}
|
|
38
62
|
|
|
39
|
-
remove(name:string, object?:string, removeall?:boolean) {
|
|
63
|
+
remove(name:string, object?:string[], removeall?:boolean) {
|
|
40
64
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
41
65
|
if (!object && !removeall) ERROR(Errors.InvalidParam, 'Resource: remove, BOTH param undefined');
|
|
42
66
|
|
|
@@ -47,15 +71,27 @@ export class Resource {
|
|
|
47
71
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING)]
|
|
48
72
|
});
|
|
49
73
|
} else if(object) {
|
|
50
|
-
if (!
|
|
74
|
+
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
|
|
51
75
|
|
|
52
76
|
txb.moveCall({
|
|
53
77
|
target:this.protocol.ResourceFn('remove') as FnCallType,
|
|
54
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.pure(object,
|
|
78
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name, BCS.STRING), txb.pure(object, 'vector<address>')]
|
|
55
79
|
});
|
|
56
80
|
}
|
|
57
81
|
}
|
|
58
82
|
|
|
83
|
+
remove2(object:string, name:string[]) {
|
|
84
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove2');
|
|
85
|
+
if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
|
|
86
|
+
if (!name) return
|
|
87
|
+
|
|
88
|
+
let txb = this.protocol.CurrentSession();
|
|
89
|
+
txb.moveCall({
|
|
90
|
+
target:this.protocol.ResourceFn('remove2') as FnCallType,
|
|
91
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(name, 'vector<string>')]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
59
95
|
rename(old_name:string, new_name:string) {
|
|
60
96
|
if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'Resource: rename');
|
|
61
97
|
|
|
@@ -66,23 +102,28 @@ export class Resource {
|
|
|
66
102
|
});
|
|
67
103
|
}
|
|
68
104
|
|
|
69
|
-
|
|
70
|
-
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, '
|
|
71
|
-
if (!
|
|
105
|
+
add_tags(object:string, nick:string, tags:string[]) {
|
|
106
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add_tags');
|
|
107
|
+
if (!nick || !tags) return;
|
|
108
|
+
if (!IsValidName(nick)) ERROR(Errors.IsValidName, 'add_tags');
|
|
109
|
+
if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'add_tags');
|
|
110
|
+
if (tags.length > Resource.MAX_TAGS) ERROR(Errors.InvalidParam, 'add_tags');
|
|
72
111
|
|
|
73
112
|
let txb = this.protocol.CurrentSession();
|
|
74
113
|
txb.moveCall({
|
|
75
|
-
target:this.protocol.ResourceFn('
|
|
76
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(
|
|
114
|
+
target:this.protocol.ResourceFn('tags_add') as FnCallType,
|
|
115
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(nick, BCS.STRING),
|
|
116
|
+
txb.pure(tags, 'vector<string>')
|
|
117
|
+
]
|
|
77
118
|
});
|
|
78
119
|
}
|
|
79
120
|
|
|
80
|
-
|
|
81
|
-
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource:
|
|
121
|
+
remove_tags(object:string) {
|
|
122
|
+
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove_tags');
|
|
82
123
|
|
|
83
124
|
let txb = this.protocol.CurrentSession();
|
|
84
125
|
txb.moveCall({
|
|
85
|
-
target:this.protocol.ResourceFn('
|
|
126
|
+
target:this.protocol.ResourceFn('tags_remove') as FnCallType,
|
|
86
127
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS)]
|
|
87
128
|
});
|
|
88
129
|
}
|
package/src/reward.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
4
|
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUint, } from './utils';
|
|
@@ -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 (!IsValidUint(
|
|
45
|
-
ERROR(Errors.IsValidUint, '
|
|
44
|
+
if (!IsValidUint(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 (!IsValidUint(
|
|
103
|
+
expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
|
|
104
|
+
if (!IsValidUint(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
|
}
|
|
@@ -284,7 +278,8 @@ export class Reward {
|
|
|
284
278
|
}
|
|
285
279
|
;
|
|
286
280
|
}
|
|
287
|
-
deposit(rewards:
|
|
281
|
+
deposit(rewards:TransactionResult[]) {
|
|
282
|
+
console.log(rewards)
|
|
288
283
|
if (!rewards || !Protocol.IsValidObjects(rewards)) {
|
|
289
284
|
ERROR(Errors.IsValidArray)
|
|
290
285
|
}
|
|
@@ -296,6 +291,23 @@ export class Reward {
|
|
|
296
291
|
typeArguments:[this.earnest_type]
|
|
297
292
|
})
|
|
298
293
|
}
|
|
294
|
+
allow_claim(bAllowClaim: boolean, passport?:PassportObject) {
|
|
295
|
+
let txb = this.protocol.CurrentSession();
|
|
296
|
+
if (passport) {
|
|
297
|
+
txb.moveCall({
|
|
298
|
+
target:this.protocol.RewardFn('allow_claim_with_passport') as FnCallType,
|
|
299
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission),
|
|
300
|
+
txb.pure(bAllowClaim, BCS.BOOL)],
|
|
301
|
+
typeArguments:[this.earnest_type]
|
|
302
|
+
})
|
|
303
|
+
} else {
|
|
304
|
+
txb.moveCall({
|
|
305
|
+
target:this.protocol.RewardFn('allow_claim') as FnCallType,
|
|
306
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), txb.pure(bAllowClaim, BCS.BOOL)],
|
|
307
|
+
typeArguments:[this.earnest_type]
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
}
|
|
299
311
|
|
|
300
312
|
change_permission(new_permission:PermissionObject) {
|
|
301
313
|
if (!Protocol.IsValidObjects([new_permission])) {
|
|
@@ -304,12 +316,23 @@ export class Reward {
|
|
|
304
316
|
|
|
305
317
|
let txb = this.protocol.CurrentSession();
|
|
306
318
|
txb.moveCall({
|
|
307
|
-
target:this.protocol.RewardFn('
|
|
319
|
+
target:this.protocol.RewardFn('permission_set') as FnCallType,
|
|
308
320
|
arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
|
|
309
321
|
typeArguments:[this.earnest_type]
|
|
310
322
|
})
|
|
311
323
|
this.permission = new_permission
|
|
312
324
|
}
|
|
313
|
-
|
|
325
|
+
static parseObjectType = (chain_type:string) : string => {
|
|
326
|
+
if (chain_type) {
|
|
327
|
+
const s = 'reward::Reward<'
|
|
328
|
+
const i = chain_type.indexOf(s);
|
|
329
|
+
if (i > 0) {
|
|
330
|
+
let r = chain_type.slice(i + s.length, chain_type.length-1);
|
|
331
|
+
return r
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return '';
|
|
335
|
+
}
|
|
314
336
|
static MAX_PORTIONS_COUNT = 255;
|
|
337
|
+
static MAX_GUARD_COUNT = 16;
|
|
315
338
|
}
|
package/src/service.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
|
|
2
|
-
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique,
|
|
2
|
+
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
|
|
3
3
|
IsValidAddress, IsValidEndpoint, OptionNone, IsValidUint, IsValidInt, IsValidName, } from './utils'
|
|
4
4
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
|
|
5
5
|
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
|
|
@@ -15,6 +15,7 @@ export type Service_Sale = {
|
|
|
15
15
|
item:string;
|
|
16
16
|
price:number;
|
|
17
17
|
stock:number;
|
|
18
|
+
endpoint?:string;
|
|
18
19
|
}
|
|
19
20
|
export enum Service_Discount_Type {
|
|
20
21
|
ratio = 0, // -off%
|
|
@@ -63,7 +64,7 @@ export class Service {
|
|
|
63
64
|
protected object : TxbObject;
|
|
64
65
|
protected protocol;
|
|
65
66
|
|
|
66
|
-
static token2coin = (token:string) => { return '0x2::coin::Coin<' + token + '>'};
|
|
67
|
+
//static token2coin = (token:string) => { return '0x2::coin::Coin<' + token + '>'};
|
|
67
68
|
|
|
68
69
|
get_pay_type() { return this.pay_token_type }
|
|
69
70
|
get_object() { return this.object }
|
|
@@ -74,7 +75,7 @@ export class Service {
|
|
|
74
75
|
this.object = ''
|
|
75
76
|
}
|
|
76
77
|
static From(protocol: Protocol, token_type:string, permission:PermissionObject, object:TxbObject) : Service {
|
|
77
|
-
let s = new Service(protocol,
|
|
78
|
+
let s = new Service(protocol, token_type, permission);
|
|
78
79
|
s.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
|
|
79
80
|
return s
|
|
80
81
|
}
|
|
@@ -83,8 +84,8 @@ export class Service {
|
|
|
83
84
|
if (!Protocol.IsValidObjects([permission])) {
|
|
84
85
|
ERROR(Errors.IsValidObjects)
|
|
85
86
|
}
|
|
86
|
-
if (!
|
|
87
|
-
ERROR(Errors.
|
|
87
|
+
if (!IsValidTokenType(token_type)) {
|
|
88
|
+
ERROR(Errors.IsValidTokenType, 'New: pay_token_type')
|
|
88
89
|
}
|
|
89
90
|
if (!IsValidDesription(description)) {
|
|
90
91
|
ERROR(Errors.IsValidDesription)
|
|
@@ -97,7 +98,7 @@ export class Service {
|
|
|
97
98
|
ERROR(Errors.IsValidEndpoint)
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
let pay_token_type =
|
|
101
|
+
let pay_token_type = token_type;
|
|
101
102
|
let s = new Service(protocol, pay_token_type, permission);
|
|
102
103
|
let txb = protocol.CurrentSession();
|
|
103
104
|
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
@@ -256,6 +257,32 @@ export class Service {
|
|
|
256
257
|
})
|
|
257
258
|
}
|
|
258
259
|
}
|
|
260
|
+
set_sale_endpoint(item:string, endpoint?:string, bNotFoundAssert:boolean=true, passport?:PassportObject) {
|
|
261
|
+
if (!IsValidName(item)) {
|
|
262
|
+
ERROR(Errors.IsValidName, 'set_sale_endpoint')
|
|
263
|
+
}
|
|
264
|
+
if (endpoint && !IsValidEndpoint(endpoint)) {
|
|
265
|
+
ERROR(Errors.IsValidEndpoint, 'set_sale_endpoint')
|
|
266
|
+
}
|
|
267
|
+
let txb = this.protocol.CurrentSession();
|
|
268
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
269
|
+
if (passport) {
|
|
270
|
+
txb.moveCall({
|
|
271
|
+
target:this.protocol.ServiceFn('sale_endpoint_set_with_passport') as FnCallType,
|
|
272
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(item), ep,
|
|
273
|
+
txb.pure(bNotFoundAssert, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
274
|
+
typeArguments:[this.pay_token_type]
|
|
275
|
+
})
|
|
276
|
+
} else {
|
|
277
|
+
txb.moveCall({
|
|
278
|
+
target:this.protocol.ServiceFn('sale_endpoint_set') as FnCallType,
|
|
279
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(item), ep,
|
|
280
|
+
txb.pure(bNotFoundAssert, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
281
|
+
typeArguments:[this.pay_token_type]
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
259
286
|
set_payee(payee:string, passport?:PassportObject) {
|
|
260
287
|
if (!IsValidAddress(payee)) {
|
|
261
288
|
ERROR(Errors.IsValidAddress, 'payee');
|
|
@@ -293,7 +320,7 @@ export class Service {
|
|
|
293
320
|
target:this.protocol.ServiceFn('repository_add') as FnCallType,
|
|
294
321
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, repository), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
295
322
|
typeArguments:[this.pay_token_type]
|
|
296
|
-
})
|
|
323
|
+
})
|
|
297
324
|
}
|
|
298
325
|
}
|
|
299
326
|
repository_remove(repository_address?:string[], removeall?:boolean, passport?:PassportObject) {
|
|
@@ -492,14 +519,17 @@ export class Service {
|
|
|
492
519
|
return bValid
|
|
493
520
|
}
|
|
494
521
|
|
|
495
|
-
add_sale(sales:Service_Sale[], passport?:PassportObject) {
|
|
522
|
+
add_sale(sales:Service_Sale[], bExistAssert:boolean=false, passport?:PassportObject) {
|
|
496
523
|
if (!sales || !this.is_valid_sale(sales)) {
|
|
497
|
-
ERROR(Errors.InvalidParam, '
|
|
524
|
+
ERROR(Errors.InvalidParam, 'add_sale')
|
|
498
525
|
}
|
|
499
526
|
|
|
500
|
-
let names: string[] = []; let price: number[] = []; let stock: number[] = [];
|
|
527
|
+
let names: string[] = []; let price: number[] = []; let stock: number[] = []; let endpoint: string[] = [];
|
|
501
528
|
sales.forEach((s) => {
|
|
502
|
-
|
|
529
|
+
if (s.endpoint && !IsValidEndpoint(s.endpoint)) {
|
|
530
|
+
ERROR(Errors.IsValidEndpoint, 'add_sale')
|
|
531
|
+
}
|
|
532
|
+
names.push(s.item); price.push(s.price); stock.push(s.stock); endpoint.push(s.endpoint ?? '')
|
|
503
533
|
})
|
|
504
534
|
|
|
505
535
|
let txb = this.protocol.CurrentSession();
|
|
@@ -507,7 +537,8 @@ export class Service {
|
|
|
507
537
|
txb.moveCall({
|
|
508
538
|
target:this.protocol.ServiceFn('sales_add_with_passport') as FnCallType,
|
|
509
539
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
|
|
510
|
-
txb.pure(Bcs.getInstance().ser(ValueType.
|
|
540
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, endpoint)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
541
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_BOOL, bExistAssert)),
|
|
511
542
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
512
543
|
typeArguments:[this.pay_token_type]
|
|
513
544
|
})
|
|
@@ -515,15 +546,16 @@ export class Service {
|
|
|
515
546
|
txb.moveCall({
|
|
516
547
|
target:this.protocol.ServiceFn('sales_add') as FnCallType,
|
|
517
548
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
|
|
549
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, endpoint)),
|
|
518
550
|
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
551
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_BOOL, bExistAssert)),
|
|
519
552
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
520
553
|
typeArguments:[this.pay_token_type]
|
|
521
554
|
})
|
|
522
555
|
}
|
|
523
|
-
|
|
524
556
|
}
|
|
525
|
-
remove_sales(sales?:string[],
|
|
526
|
-
if (!
|
|
557
|
+
remove_sales(sales?:string[], passport?:PassportObject) {
|
|
558
|
+
if (!sales) {
|
|
527
559
|
ERROR(Errors.AllInvalid, 'sales & removeall')
|
|
528
560
|
}
|
|
529
561
|
if (sales && !IsValidArray(sales, IsValidName)) {
|
|
@@ -532,35 +564,19 @@ export class Service {
|
|
|
532
564
|
|
|
533
565
|
let txb = this.protocol.CurrentSession();
|
|
534
566
|
if (passport) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
} else {
|
|
542
|
-
txb.moveCall({
|
|
543
|
-
target:this.protocol.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
544
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
545
|
-
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
546
|
-
typeArguments:[this.pay_token_type]
|
|
547
|
-
})
|
|
548
|
-
}
|
|
567
|
+
txb.moveCall({
|
|
568
|
+
target:this.protocol.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
569
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
570
|
+
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
571
|
+
typeArguments:[this.pay_token_type]
|
|
572
|
+
})
|
|
549
573
|
} else {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
} else {
|
|
557
|
-
txb.moveCall({
|
|
558
|
-
target:this.protocol.ServiceFn('sales_remove') as FnCallType,
|
|
559
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
560
|
-
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
561
|
-
typeArguments:[this.pay_token_type]
|
|
562
|
-
})
|
|
563
|
-
}
|
|
574
|
+
txb.moveCall({
|
|
575
|
+
target:this.protocol.ServiceFn('sales_remove') as FnCallType,
|
|
576
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
577
|
+
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
578
|
+
typeArguments:[this.pay_token_type]
|
|
579
|
+
})
|
|
564
580
|
}
|
|
565
581
|
}
|
|
566
582
|
|
|
@@ -766,8 +782,6 @@ export class Service {
|
|
|
766
782
|
}
|
|
767
783
|
|
|
768
784
|
let req = array_unique(customer_required) as string[];
|
|
769
|
-
console.log(req)
|
|
770
|
-
console.log(this.pay_token_type)
|
|
771
785
|
let txb = this.protocol.CurrentSession();
|
|
772
786
|
if (passport) {
|
|
773
787
|
txb.moveCall({
|
|
@@ -923,7 +937,7 @@ export class Service {
|
|
|
923
937
|
names.push(v.item)
|
|
924
938
|
})
|
|
925
939
|
if (!bValid) {
|
|
926
|
-
ERROR(Errors.InvalidParam, 'buy_items')
|
|
940
|
+
ERROR(Errors.InvalidParam, 'buy_items 2')
|
|
927
941
|
}
|
|
928
942
|
|
|
929
943
|
let name:string[] = []; let price:number[] = []; let stock:number[] = []; let order;
|
|
@@ -1018,4 +1032,23 @@ export class Service {
|
|
|
1018
1032
|
static MAX_DISCOUNT_RECEIVER_COUNT = 20;
|
|
1019
1033
|
static MAX_GUARD_COUNT = 16;
|
|
1020
1034
|
static MAX_REPOSITORY_COUNT = 16;
|
|
1035
|
+
|
|
1036
|
+
static parseObjectType = (chain_type:string | undefined | null) : string => {
|
|
1037
|
+
if (chain_type) {
|
|
1038
|
+
const s = 'service::Service<'
|
|
1039
|
+
const i = chain_type.indexOf(s);
|
|
1040
|
+
if (i > 0) {
|
|
1041
|
+
return chain_type.slice(i + s.length, chain_type.length-1);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
return '';
|
|
1045
|
+
}
|
|
1046
|
+
static endpoint = (service_endpoint:string, item_endpoint:string, item_name:string) => {
|
|
1047
|
+
if (item_endpoint) {
|
|
1048
|
+
return item_endpoint
|
|
1049
|
+
} else if (service_endpoint) {
|
|
1050
|
+
return service_endpoint + '/sales/' + encodeURI(item_name);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1021
1054
|
}
|