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.
Files changed (49) hide show
  1. package/dist/demand.d.ts +3 -2
  2. package/dist/demand.d.ts.map +1 -1
  3. package/dist/demand.js +21 -7
  4. package/dist/entity.d.ts +2 -1
  5. package/dist/entity.d.ts.map +1 -1
  6. package/dist/entity.js +23 -7
  7. package/dist/exception.d.ts +3 -1
  8. package/dist/exception.d.ts.map +1 -1
  9. package/dist/exception.js +3 -1
  10. package/dist/guard.js +1 -1
  11. package/dist/machine.js +2 -2
  12. package/dist/permission.d.ts +20 -4
  13. package/dist/permission.d.ts.map +1 -1
  14. package/dist/permission.js +146 -13
  15. package/dist/protocol.d.ts +30 -6
  16. package/dist/protocol.d.ts.map +1 -1
  17. package/dist/protocol.js +124 -17
  18. package/dist/repository.d.ts +6 -3
  19. package/dist/repository.d.ts.map +1 -1
  20. package/dist/repository.js +59 -40
  21. package/dist/resource.d.ts +20 -6
  22. package/dist/resource.d.ts.map +1 -1
  23. package/dist/resource.js +58 -21
  24. package/dist/reward.d.ts +6 -3
  25. package/dist/reward.d.ts.map +1 -1
  26. package/dist/reward.js +43 -19
  27. package/dist/service.d.ts +6 -3
  28. package/dist/service.d.ts.map +1 -1
  29. package/dist/service.js +76 -44
  30. package/dist/utils.d.ts +15 -1
  31. package/dist/utils.d.ts.map +1 -1
  32. package/dist/utils.js +150 -13
  33. package/dist/vote.d.ts +2 -2
  34. package/dist/vote.d.ts.map +1 -1
  35. package/dist/vote.js +14 -14
  36. package/package.json +1 -1
  37. package/src/demand.ts +22 -8
  38. package/src/entity.ts +25 -6
  39. package/src/exception.ts +3 -1
  40. package/src/guard.ts +1 -1
  41. package/src/machine.ts +2 -2
  42. package/src/permission.ts +165 -10
  43. package/src/protocol.ts +127 -17
  44. package/src/repository.ts +64 -44
  45. package/src/resource.ts +61 -20
  46. package/src/reward.ts +46 -23
  47. package/src/service.ts +79 -46
  48. package/src/utils.ts +141 -15
  49. 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 MAX_WORDS_LEN = 102400;
9
- static IsValidWords(words:string) : boolean {
10
- return words.length <= Resource.MAX_WORDS_LEN
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, 'Resource: add');
30
- if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: add');
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, BCS.ADDRESS)]
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 (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove');
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, BCS.ADDRESS)]
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
- 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');
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('words_add') as FnCallType,
76
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS), txb.pure(words, BCS.STRING)]
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
- remove_words(object:string) {
81
- if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove_words');
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('words_remove') as FnCallType,
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
- minutes_duration:number, passport?:PassportObject) : Reward {
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(minutes_duration)) {
45
- ERROR(Errors.IsValidUint, 'minutes_duration')
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(minutes_duration, BCS.U64),
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(minutes_duration, BCS.U64),
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(minutes_expand:number, passport?:PassportObject) {
112
- if (!IsValidUint(minutes_expand)) {
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(minutes_expand, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)],
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(minutes_expand, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)],
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:CoinReward[]) {
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('this.permission_set') as FnCallType,
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, IsValidArgType, IsValidDesription,
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, this.token2coin(token_type), permission);
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 (!IsValidArgType(token_type)) {
87
- ERROR(Errors.IsValidArgType, 'New: pay_token_type')
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 = this.token2coin(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, 'Service_Sale')
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
- names.push(s.item); price.push(s.price); stock.push(s.stock);
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.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
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[], removeall?:boolean, passport?:PassportObject) {
526
- if (!removeall && !sales) {
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
- if (removeall) {
536
- txb.moveCall({
537
- target:this.protocol.ServiceFn('sales_remove_all_with_passport') as FnCallType,
538
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
539
- typeArguments:[this.pay_token_type]
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
- if (removeall) {
551
- txb.moveCall({
552
- target:this.protocol.ServiceFn('sales_remove_all') as FnCallType,
553
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
554
- typeArguments:[this.pay_token_type]
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
  }