wowok 1.4.16 → 1.4.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.4.16",
3
+ "version": "1.4.18",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/exception.ts CHANGED
@@ -22,6 +22,7 @@ export enum Errors {
22
22
  isValidHttpUrl = 'invalid url',
23
23
  IsValidUserDefinedIndex = 'invalid user defined permission index',
24
24
  bcsTypeInvalid = 'invalid bcs type',
25
+ IsValidServiceItemName = 'invalid service item name',
25
26
  }
26
27
 
27
28
  export const ERROR = (error:Errors, info?:any) => {
package/src/guard.ts CHANGED
@@ -150,20 +150,24 @@ export class Guard {
150
150
  [MODULES.progress, 'Has Context Repository', 59, [], ValueType.TYPE_BOOL, 'Whether the repository reference for Progress is set?'],
151
151
  [MODULES.progress, 'Context Repository', 60, [], ValueType.TYPE_ADDRESS, 'Repository reference for Progress.'],
152
152
  [MODULES.progress, 'Last Session Time', 61, [], ValueType.TYPE_U64, 'Time when the previous session was completed.'],
153
- [MODULES.progress, 'Session Time', 62, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'Time a node completes its session.', 'Input:the node name'],
154
-
155
- [MODULES.demand, 'Permission', 71, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
156
- [MODULES.demand, 'Has Deadline', 72, [], ValueType.TYPE_BOOL, 'Whether to set the expiration time of presenting?'],
157
- [MODULES.demand, 'Deadline', 73, [], ValueType.TYPE_U64, 'The expiration time of presenting.'],
158
- [MODULES.demand, 'Bounty Count', 74, [], ValueType.TYPE_U64, 'Number of Bounties.'],
159
- [MODULES.demand, 'Has Guard', 75, [], ValueType.TYPE_BOOL, 'Whether the present guard is set?'],
160
- [MODULES.demand, 'Guard', 76, [], ValueType.TYPE_ADDRESS, 'The present guard address.'],
161
- [MODULES.demand, 'Has Service Picked', 77, [], ValueType.TYPE_BOOL, 'Whether a service has been picked and bounties given?'],
162
- [MODULES.demand, 'Service Picked', 78, [], ValueType.TYPE_ADDRESS, 'Service address that has been picked.'],
163
- [MODULES.demand, 'Presenter Count', 79, [], ValueType.TYPE_U64, 'Number of presenters.'],
164
- [MODULES.demand, 'Has Presenter', 80, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is a certain address a presenter?', 'Input:address'],
165
- [MODULES.demand, 'Who Got Bounty', 81, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS, 'The address that bounties given.', 'Input:address'],
166
-
153
+ [MODULES.progress, 'Last Session Node', 62, [], ValueType.TYPE_STRING, 'The name of the last completed node.'],
154
+ [MODULES.progress, 'Current Session-id', 63, [], ValueType.TYPE_U64, 'The session id of ongoing node.'],
155
+ [MODULES.progress, 'Parent Session-id', 64, [], ValueType.TYPE_U64, 'The child process was started in the Session-id phase of the parent process.'],
156
+ [MODULES.progress, 'Parent Next Node', 65, [], ValueType.TYPE_STRING, 'The child process is started at the next node stage of the parent process.'],
157
+ [MODULES.progress, 'Parent Forward', 66, [], ValueType.TYPE_STRING, 'The child process is started in the Forward phase of the next node of the parent process.'],
158
+ [MODULES.progress, 'Parent Node', 67, [], ValueType.TYPE_STRING, 'The node name of the parent process where the child process is located.'],
159
+ [MODULES.progress, 'Forward Accomplished', 68, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Has a forward been accomplished?', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
160
+ [MODULES.progress, 'Forward Operator', 69, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The forward operator.', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
161
+ [MODULES.progress, 'Forward Sub-progress', 70, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The forward child process address(if set).', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
162
+ [MODULES.progress, 'Forward Deliverables', 71, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The forward deliverable(if set).', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
163
+ [MODULES.progress, 'Forward time', 72, [ValueType.TYPE_U64, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The time when the forward was last triggered.', 'Input 1:session-id; Input 2:next node name; Input 3:forward name'],
164
+ [MODULES.progress, 'Closest Session Time', 73, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The time a node that closest time to the current node completes its session.', 'Input:the node name'],
165
+ [MODULES.progress, 'Closest Forward Accomplished', 74, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Has a forward been accomplished?', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
166
+ [MODULES.progress, 'Closest Forward Operator', 75, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The operator of the forward that closest time to the current node.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
167
+ [MODULES.progress, 'Closest Forward Sub-progress', 76, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The child process address(if set) of the forward that closest time to the current node.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
168
+ [MODULES.progress, 'Closest Forward Deliverables', 77, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The deliverable(if set) of the forward that closest time to the current node.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
169
+ [MODULES.progress, 'Closest Forward time', 78, [ValueType.TYPE_STRING, ValueType.TYPE_STRING, ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The time when the forward that closest time to the current node was last triggered.', 'Input 1:node name; Input 2:next node name; Input 3:forward name'],
170
+
167
171
  [MODULES.order, 'Amount', 91, [], ValueType.TYPE_U64, 'Order amount.'],
168
172
  [MODULES.order, 'Payer', 92, [], ValueType.TYPE_ADDRESS, 'Order payer.'],
169
173
  [MODULES.order, 'Service', 93, [], ValueType.TYPE_ADDRESS, 'Service for creating orders.'],
@@ -196,6 +200,18 @@ export class Guard {
196
200
  [MODULES.service, 'Required Info of Service-Pubkey', 128, [], ValueType.TYPE_STRING, 'The public key used to encrypt customer information, and only the service provider can decrypt and view customer information.'],
197
201
  [MODULES.service, 'Required Info', 129, [], ValueType.TYPE_VEC_STRING, 'Names of the required information item that needs to be provided by the customer.'],
198
202
 
203
+ [MODULES.demand, 'Permission', 135, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
204
+ [MODULES.demand, 'Has Deadline', 136, [], ValueType.TYPE_BOOL, 'Whether to set the expiration time of presenting?'],
205
+ [MODULES.demand, 'Deadline', 137, [], ValueType.TYPE_U64, 'The expiration time of presenting.'],
206
+ [MODULES.demand, 'Bounty Count', 138, [], ValueType.TYPE_U64, 'Number of Bounties.'],
207
+ [MODULES.demand, 'Has Guard', 139, [], ValueType.TYPE_BOOL, 'Whether the present guard is set?'],
208
+ [MODULES.demand, 'Guard', 140, [], ValueType.TYPE_ADDRESS, 'The present guard address.'],
209
+ [MODULES.demand, 'Has Service Picked', 141, [], ValueType.TYPE_BOOL, 'Whether a service has been picked and bounties given?'],
210
+ [MODULES.demand, 'Service Picked', 142, [], ValueType.TYPE_ADDRESS, 'Service address that has been picked.'],
211
+ [MODULES.demand, 'Presenter Count', 143, [], ValueType.TYPE_U64, 'Number of presenters.'],
212
+ [MODULES.demand, 'Has Presenter', 144, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Is a certain address a presenter?', 'Input:address'],
213
+ [MODULES.demand, 'Who Got Bounty', 145, [ValueType.TYPE_ADDRESS], ValueType.TYPE_ADDRESS, 'The address that bounties given.', 'Input:address'],
214
+
199
215
  [MODULES.reward, 'Permission', 151, [], ValueType.TYPE_ADDRESS, 'Permission object address.'],
200
216
  [MODULES.reward, 'Rewards Remaining', 152, [], ValueType.TYPE_U64, 'Number of rewards to be claimed.'],
201
217
  [MODULES.reward, 'Reward Count Supplied', 153, [], ValueType.TYPE_U64, 'Total rewards supplied.'],
@@ -455,7 +471,6 @@ export class GuardMaker {
455
471
  // serialize const & data
456
472
  add_param(type:ValueType | ContextType, param?:any) : GuardMaker {
457
473
  const e = SER_VALUE.find((v:any)=>v.type===type)?.name ?? '' + ' invalid';
458
-
459
474
  switch(type) {
460
475
  case ValueType.TYPE_ADDRESS:
461
476
  case ValueType.TYPE_BOOL:
@@ -502,7 +517,7 @@ export class GuardMaker {
502
517
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, param));
503
518
  this.type_validator.push(ValueType.TYPE_ADDRESS);
504
519
  break;
505
- case ContextType.TYPE_CONSTANT:
520
+ case ContextType.TYPE_CONSTANT:
506
521
  if (!param) {
507
522
  ERROR(Errors.InvalidParam, 'param invalid:'+e);
508
523
  }
@@ -512,9 +527,13 @@ export class GuardMaker {
512
527
 
513
528
  var v = this.constant.get(param);
514
529
  if (!v) ERROR(Errors.Fail, 'identifier not in constant:'+e);
515
- this.type_validator.push(v!.type);
516
- this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
517
- this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param));
530
+ var t = v!.type;
531
+ if (v?.type === ContextType.TYPE_WITNESS_ID) {
532
+ t = ValueType.TYPE_ADDRESS;
533
+ }
534
+ this.type_validator.push(t); //@ type validator convert
535
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // constant flag
536
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param)); // identifier
518
537
  break;
519
538
  default:
520
539
  ERROR(Errors.InvalidParam, 'add_param type:'+e);
@@ -571,7 +590,7 @@ export class GuardMaker {
571
590
  return this;
572
591
  }
573
592
 
574
- add_logic(type:OperatorType, param:number=2) : GuardMaker {
593
+ add_logic(type:OperatorType, logic_count:number=2) : GuardMaker {
575
594
  var e:any = LogicsInfo.find((v:any) => v[0] === type);
576
595
  if (e) { e=e[1] }
577
596
 
@@ -612,8 +631,8 @@ export class GuardMaker {
612
631
  break;
613
632
  case OperatorType.TYPE_LOGIC_AND:
614
633
  case OperatorType.TYPE_LOGIC_OR: //@ logics count
615
- if (!param || param < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
616
- splice_len = param!;
634
+ if (!logic_count || logic_count < 2) ERROR(Errors.Fail, 'logic param invalid:'+e);
635
+ splice_len = logic_count!;
617
636
  if (this.type_validator.length < splice_len) { ERROR(Errors.Fail, 'type_validator.length:'+e) }
618
637
  for (let i = 1; i <= splice_len; ++i) {
619
638
  if (this.type_validator[this.type_validator.length -i] != ValueType.TYPE_BOOL) { ERROR(Errors.Fail, 'type_validator check:'+e) }
@@ -637,7 +656,7 @@ export class GuardMaker {
637
656
 
638
657
  this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
639
658
  if (type === OperatorType.TYPE_LOGIC_AND || type === OperatorType.TYPE_LOGIC_OR) {
640
- this.data.push((Bcs.getInstance().ser(ValueType.TYPE_U8, param))); //@ logics
659
+ this.data.push((Bcs.getInstance().ser(ValueType.TYPE_U8, logic_count))); //@ logics
641
660
  }
642
661
  this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
643
662
  this.type_validator.push(ret); // add bool to type stack
@@ -683,7 +702,7 @@ export class GuardMaker {
683
702
  maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
684
703
  })
685
704
  let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
686
- maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, 2), Bcs.getInstance().ser(ValueType.TYPE_U8, op)));
705
+ maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op), Bcs.getInstance().ser(ValueType.TYPE_U8, 2)));
687
706
  this.data.splice(0, this.data.length-1);
688
707
  maker.type_validator = this.type_validator;
689
708
  return maker
@@ -695,7 +714,7 @@ export class GuardMaker {
695
714
  // and/or + logics count
696
715
  static input_combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
697
716
  let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
698
- return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, 2), Bcs.getInstance().ser(ValueType.TYPE_U8, op)) as Uint8Array;
717
+ return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, op), Bcs.getInstance().ser(ValueType.TYPE_U8, 2), ) as Uint8Array;
699
718
  }
700
719
  static input_not(input:Uint8Array) : Uint8Array {
701
720
  return concatenate(Uint8Array, input, Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
package/src/passport.ts CHANGED
@@ -765,6 +765,7 @@ export class Passport {
765
765
  });
766
766
  })
767
767
 
768
+ console.log(query)
768
769
  // witness
769
770
  query?.witness.forEach((w) => {
770
771
  this.txb.moveCall({
package/src/permission.ts CHANGED
@@ -273,7 +273,7 @@ export class Permission {
273
273
  ERROR(Errors.IsValidArray, 'add_entity2');
274
274
  }
275
275
 
276
- if (index) {
276
+ if (index !== undefined) {
277
277
  this.txb.moveCall({
278
278
  target:Protocol.Instance().PermissionFn('add_with_index') as FnCallType,
279
279
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(index),
@@ -288,9 +288,7 @@ export class Permission {
288
288
  }
289
289
 
290
290
  add_entity(entities:Permission_Entity[]) {
291
- if (!entities) {
292
- ERROR(Errors.InvalidParam, 'add_entity');
293
- }
291
+ if (entities.length === 0) return
294
292
 
295
293
  let bValid = true;
296
294
  let e = entities.forEach((v) => {
@@ -322,13 +320,14 @@ export class Permission {
322
320
  }
323
321
  }
324
322
  }
325
- //if (indexes.length > 0) {
323
+
324
+ if (indexes.length > 0) {
326
325
  this.txb.moveCall({
327
326
  target:Protocol.Instance().PermissionFn('add_batch') as FnCallType,
328
327
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity.entity_address),
329
328
  this.txb.pure.vector('u64', indexes)]
330
329
  })
331
- //}
330
+ }
332
331
  }
333
332
  // set guards
334
333
  guards.forEach(({entity_address, index, guard}) => {
@@ -368,7 +367,8 @@ export class Permission {
368
367
  if (!IsValidAddress(entity_address)) {
369
368
  ERROR(Errors.IsValidAddress)
370
369
  }
371
- if (!index || !(IsValidArray(index, Permission.IsValidPermissionIndex))) {
370
+ if (index.length === 0) return ;
371
+ if (!(IsValidArray(index, Permission.IsValidPermissionIndex))) {
372
372
  ERROR(Errors.InvalidParam, 'index')
373
373
  }
374
374
 
@@ -379,7 +379,8 @@ export class Permission {
379
379
  })
380
380
  }
381
381
  remove_entity(entity_address:string[]) {
382
- if (!entity_address || !IsValidArray(entity_address, IsValidAddress)) {
382
+ if (entity_address.length === 0) return ;
383
+ if (!IsValidArray(entity_address, IsValidAddress)) {
383
384
  ERROR(Errors.IsValidArray)
384
385
  }
385
386
 
package/src/progress.ts CHANGED
@@ -188,24 +188,25 @@ export class Progress {
188
188
  }
189
189
  }
190
190
  unhold(next:ProgressNext, passport?:PassportObject) {
191
- console.log(next)
192
191
  if (!Progress.IsValidProgressNext(next)) {
193
192
  ERROR(Errors.InvalidParam, 'unhold')
194
193
  }
195
194
 
195
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
196
+
196
197
  if (passport) {
197
198
  this.txb.moveCall({
198
199
  target:Protocol.Instance().ProgressFn('unhold_with_passport') as FnCallType,
199
200
  arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object),
200
201
  Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
201
- this.txb.pure.string(next.forward), Protocol.TXB_OBJECT(this.txb, this.permission)],
202
+ this.txb.pure.string(next.forward), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
202
203
  })
203
204
  } else {
204
205
  this.txb.moveCall({
205
206
  target:Protocol.Instance().ProgressFn('unhold') as FnCallType,
206
207
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
207
208
  this.txb.pure.string(next.next_node_name), this.txb.pure.string(next.forward),
208
- Protocol.TXB_OBJECT(this.txb, this.permission)],
209
+ Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
209
210
  })
210
211
  }
211
212
  }
@@ -293,11 +294,11 @@ export class Progress {
293
294
  if (!Progress.IsValidProgressNext(next)) {
294
295
  ERROR(Errors.InvalidParam, 'hold')
295
296
  }
296
-
297
+ const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
297
298
  this.txb.moveCall({
298
299
  target:Protocol.Instance().ProgressFn('hold') as FnCallType,
299
300
  arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
300
- this.txb.pure.string(next.forward), this.txb.pure.bool(hold), Protocol.TXB_OBJECT(this.txb, this.permission)],
301
+ this.txb.pure.string(next.forward), this.txb.pure.bool(hold), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
301
302
  })
302
303
  }
303
304
 
package/src/protocol.ts CHANGED
@@ -165,7 +165,7 @@ interface ValueTypeString {
165
165
  export const SER_VALUE: ValueTypeString[] = [
166
166
  {type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false', validator:(value:any) => { return (value === true || value === false)}},
167
167
  {type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af', validator:IsValidAddress},
168
- {type: ContextType.TYPE_WITNESS_ID, name: 'future address', description:"eg: address of the Machine that will generate future Progress, address of the Service that will generate future Order", validator:IsValidAddress},
168
+ {type: ContextType.TYPE_WITNESS_ID, name: 'witness address', description:"For example, the address of the Machine object ensures that the Progress generated in the past or future is verified; the address of the Service object ensures that the Order generated in the past or future is verified.", validator:IsValidAddress},
169
169
  {type: ContextType.TYPE_SIGNER, name: 'txn signer', description:"signer address of the transaction, "},
170
170
  {type: ContextType.TYPE_CLOCK, name: 'txn time', description:"unsigned-64 number for the transaction time"},
171
171
  {type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233', validator:IsValidU64},
@@ -208,10 +208,10 @@ const TESTNET = {
208
208
  }
209
209
  */
210
210
  const TESTNET = {
211
- package: "0x4ce36e03ef9cd230f1158e48293ee01cb572cdcd2f9cab7ac7b2fd2251bfe51e",
212
- wowok_object: '0xd3639daf1daa300bbf694b21e42cecac6be242ad038fe48a7a1212e93f3845f6',
213
- entity_object: '0x8de1e01e6baca0990ca18de3ec51b57183512deaeb76076be9161ca38988c74f',
214
- treasury_cap:'0x2e05eda6ee5b0773854be6eb48c6cee2b5ca8aaa13ee810434d66232005b40ef',
211
+ package: "0x7a36d0cb4ac23770bd07b770997b5ceef57e8f7b22563eea945111a0bcf38e8d",
212
+ wowok_object: '0xa79bbf5d1b96a015da7b763bc9528a226c8dbf86e481947aa5cfd0d3949da33b',
213
+ entity_object: '0x524dcfb8d2fad580ccffb09cc3b3b1377213db040dad6cdad36ed5a99f1b0c00',
214
+ treasury_cap:'0x8e4dbb61e5cd2ca4812faa86e0e1d886903bd0c48c8bf8d5af0856cb8a8e5df1',
215
215
  }
216
216
  const MAINNET = {
217
217
  package: "",
package/src/service.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
2
- IsValidAddress, IsValidEndpoint, IsValidU64, IsValidName,} from './utils'
2
+ IsValidAddress, IsValidEndpoint, IsValidU64, } from './utils'
3
3
  import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
4
4
  ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
5
5
  TxbObject} from './protocol';
@@ -155,10 +155,11 @@ export class Service {
155
155
  }
156
156
  set_price(item:string, price:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
157
157
  if (!IsValidU64(price)) {
158
- ERROR(Errors.IsValidU64, 'price')
158
+ ERROR(Errors.IsValidU64, 'set_price price')
159
159
  }
160
- if (!IsValidName(item)) {
161
- ERROR(Errors.IsValidName, 'item')
160
+
161
+ if (!Service.IsValidItemName(item)) {
162
+ ERROR(Errors.IsValidServiceItemName, 'set_price item')
162
163
  }
163
164
 
164
165
  if (passport) {
@@ -180,8 +181,8 @@ export class Service {
180
181
  }
181
182
  }
182
183
  set_stock(item:string, stock:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
183
- if (!IsValidName(item)) {
184
- ERROR(Errors.IsValidName, 'item')
184
+ if (!Service.IsValidItemName(item)) {
185
+ ERROR(Errors.IsValidServiceItemName, 'item')
185
186
  }
186
187
  if (!IsValidU64(stock)) {
187
188
  ERROR(Errors.IsValidU64, 'stock')
@@ -206,11 +207,11 @@ export class Service {
206
207
  }
207
208
  }
208
209
  add_stock(item:string, stock_add:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
209
- if (!IsValidName(item)) {
210
- ERROR(Errors.IsValidName, 'item')
210
+ if (!Service.IsValidItemName(item)) {
211
+ ERROR(Errors.IsValidServiceItemName, 'add_stock item')
211
212
  }
212
213
  if (!IsValidU64(stock_add)) {
213
- ERROR(Errors.IsValidUint, 'stock_add')
214
+ ERROR(Errors.IsValidUint, 'add_stock stock_add')
214
215
  }
215
216
 
216
217
  if (passport) {
@@ -232,11 +233,11 @@ export class Service {
232
233
  }
233
234
  }
234
235
  reduce_stock(item:string, stock_reduce:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
235
- if (!IsValidName(item)) {
236
- ERROR(Errors.IsValidName, 'item')
236
+ if (!Service.IsValidItemName(item)) {
237
+ ERROR(Errors.IsValidServiceItemName, 'reduce_stock item')
237
238
  }
238
239
  if (!IsValidU64(stock_reduce)) {
239
- ERROR(Errors.IsValidUint, 'stock_reduce')
240
+ ERROR(Errors.IsValidUint, 'reduce_stock stock_reduce')
240
241
  }
241
242
 
242
243
  if (passport) {
@@ -259,11 +260,11 @@ export class Service {
259
260
  }
260
261
 
261
262
  set_sale_endpoint(item:string, endpoint?:string|null, bNotFoundAssert:boolean=true, passport?:PassportObject) {
262
- if (!IsValidName(item)) {
263
- ERROR(Errors.IsValidName, 'set_sale_endpoint')
263
+ if (!Service.IsValidItemName(item)) {
264
+ ERROR(Errors.IsValidServiceItemName, 'set_sale_endpoint item')
264
265
  }
265
266
  if (endpoint && !IsValidEndpoint(endpoint)) {
266
- ERROR(Errors.IsValidEndpoint, 'set_sale_endpoint')
267
+ ERROR(Errors.IsValidEndpoint, 'set_sale_endpoint endpoint')
267
268
  }
268
269
 
269
270
  let ep = this.txb.pure.option('string', endpoint ? endpoint : undefined);
@@ -505,7 +506,7 @@ export class Service {
505
506
  is_valid_sale(sales:Service_Sale[]) {
506
507
  let bValid = true; let names:string[] = [];
507
508
  sales.forEach((v) => {
508
- if (!IsValidName(v.item)) bValid = false;
509
+ if (!Service.IsValidItemName(v.item)) bValid = false;
509
510
  if (!IsValidU64(v.price)) bValid = false;
510
511
  if (!IsValidU64(v.stock)) bValid = false;
511
512
  if (names.includes(v.item)) bValid = false;
@@ -555,7 +556,7 @@ export class Service {
555
556
  remove_sales(sales:string[], passport?:PassportObject) {
556
557
  if (sales.length === 0) return;
557
558
 
558
- if (!IsValidArray(sales, IsValidName)) {
559
+ if (!IsValidArray(sales, Service.IsValidItemName)) {
559
560
  ERROR(Errors.IsValidArray, 'remove_sales')
560
561
  }
561
562
 
@@ -913,7 +914,7 @@ export class Service {
913
914
 
914
915
  let bValid = true; let names:string[] = [];
915
916
  buy_items.forEach((v) => {
916
- if (!IsValidName(v.item)) bValid = false;
917
+ if (!Service.IsValidItemName(v.item)) bValid = false;
917
918
  if (!IsValidU64(v.max_price)) bValid = false;
918
919
  if (!IsValidU64(v.count)) bValid = false;
919
920
  if (names.includes(v.item)) bValid = false;
@@ -1010,8 +1011,14 @@ export class Service {
1010
1011
  static MAX_DISCOUNT_COUNT_ONCE = 200;
1011
1012
  static MAX_DISCOUNT_RECEIVER_COUNT = 20;
1012
1013
  static MAX_GUARD_COUNT = 16;
1013
- static MAX_REPOSITORY_COUNT = 16;
1014
-
1014
+ static MAX_REPOSITORY_COUNT = 32;
1015
+ static MAX_ITEM_NAME_LENGTH = 256;
1016
+
1017
+ static IsValidItemName(name:string) : boolean {
1018
+ if (!name) return false;
1019
+ return new TextEncoder().encode(name).length <= Service.MAX_ITEM_NAME_LENGTH;
1020
+ }
1021
+
1015
1022
  static parseObjectType = (chain_type:string | undefined | null) : string => {
1016
1023
  if (chain_type) {
1017
1024
  const s = 'service::Service<'
package/src/utils.ts CHANGED
@@ -120,7 +120,6 @@ export const concatenate = (resultConstructor:any, ...arrays:any[]) => {
120
120
  }
121
121
 
122
122
  export const array_equal = (arr1: any[], arr2: any[]) => {
123
- // Array.some(): 有一项不满足,返回false
124
123
  if (arr1.length !== arr2.length) {
125
124
  return false;
126
125
  }