wowok 1.2.4 → 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 +23 -7
  13. package/dist/permission.d.ts.map +1 -1
  14. package/dist/permission.js +149 -16
  15. package/dist/protocol.d.ts +35 -10
  16. package/dist/protocol.d.ts.map +1 -1
  17. package/dist/protocol.js +129 -21
  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 +15 -9
  28. package/dist/service.d.ts.map +1 -1
  29. package/dist/service.js +94 -56
  30. package/dist/utils.d.ts +18 -4
  31. package/dist/utils.d.ts.map +1 -1
  32. package/dist/utils.js +218 -45
  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 +168 -14
  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 +100 -57
  48. package/src/utils.ts +186 -22
  49. package/src/vote.ts +14 -14
package/dist/demand.d.ts CHANGED
@@ -9,17 +9,18 @@ export declare class Demand {
9
9
  get_object(): TxbObject;
10
10
  static From(protocol: Protocol, bounty_type: string, permission: PermissionObject, object: TxbObject): Demand;
11
11
  private constructor();
12
- static New(protocol: Protocol, bounty_type: string, permission: PermissionObject, description: string, bounty: TransactionResult, passport?: PassportObject): Demand;
12
+ static New(protocol: Protocol, bounty_type: string, permission: PermissionObject, description: string, bounty: TransactionResult | string, passport?: PassportObject): Demand;
13
13
  launch(): DemandAddress;
14
14
  destroy(): void;
15
15
  refund(passport?: PassportObject): void;
16
- expand_time(minutes_duration: number, passport?: PassportObject): void;
16
+ expand_time(minutes_duration: boolean, time: number, passport?: PassportObject): void;
17
17
  set_guard(guard?: GuardObject, passport?: PassportObject): void;
18
18
  set_description(description: string, passport?: PassportObject): void;
19
19
  yes(service_address: string, passport?: PassportObject): void;
20
20
  deposit(bounty: TxbObject): void;
21
21
  present(service_address: string, service_pay_type: string, tips: string, passport?: PassportObject): void;
22
22
  change_permission(new_permission: PermissionObject): void;
23
+ static parseObjectType: (chain_type: string) => string;
23
24
  static MAX_BOUNTY_COUNT: number;
24
25
  static MAX_PRESENTERS_COUNT: number;
25
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"demand.d.ts","sourceRoot":"","sources":["../src/demand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAAc,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAiB,MAAM,YAAY,CAAC;AAM1I,qBAAa,MAAM;IACf,SAAS,CAAC,WAAW,SAAC;IACtB,SAAS,CAAC,UAAU,mBAAE;IACtB,SAAS,CAAC,MAAM,EAAG,SAAS,CAAE;IAC9B,SAAS,CAAC,QAAQ,WAAC;IAEnB,eAAe;IACf,UAAU;IAEV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BAAoB,SAAO;CACrC"}
package/dist/demand.js CHANGED
@@ -35,14 +35,14 @@ export class Demand {
35
35
  if (passport) {
36
36
  d.object = txb.moveCall({
37
37
  target: protocol.DemandFn('new_with_passport'),
38
- arguments: [passport, txb.pure(description), bounty, Protocol.TXB_OBJECT(txb, permission)],
38
+ arguments: [passport, txb.pure(description), txb.object(bounty), Protocol.TXB_OBJECT(txb, permission)],
39
39
  typeArguments: [bounty_type],
40
40
  });
41
41
  }
42
42
  else {
43
43
  d.object = txb.moveCall({
44
44
  target: protocol.DemandFn('new'),
45
- arguments: [txb.pure(description), bounty, Protocol.TXB_OBJECT(txb, permission)],
45
+ arguments: [txb.pure(description), txb.object(bounty), Protocol.TXB_OBJECT(txb, permission)],
46
46
  typeArguments: [bounty_type],
47
47
  });
48
48
  }
@@ -81,15 +81,17 @@ export class Demand {
81
81
  });
82
82
  }
83
83
  }
84
- expand_time(minutes_duration, passport) {
85
- if (!IsValidUint(minutes_duration)) {
86
- ERROR(Errors.IsValidUint, 'minutes_duration');
84
+ // minutes_duration TRUE , time is minutes count; otherwise, the deadline time
85
+ expand_time(minutes_duration, time, passport) {
86
+ if (!IsValidUint(time)) {
87
+ ERROR(Errors.IsValidUint, 'time');
87
88
  }
88
89
  let txb = this.protocol.CurrentSession();
89
90
  if (passport) {
90
91
  txb.moveCall({
91
92
  target: this.protocol.DemandFn('time_expand_with_passport'),
92
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.U64),
93
+ arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.BOOL),
94
+ txb.pure(time, BCS.U64),
93
95
  txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)],
94
96
  typeArguments: [this.bounty_type],
95
97
  });
@@ -97,7 +99,8 @@ export class Demand {
97
99
  else {
98
100
  txb.moveCall({
99
101
  target: this.protocol.DemandFn('time_expand'),
100
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.U64),
102
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.BOOL),
103
+ txb.pure(time, BCS.U64),
101
104
  txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)],
102
105
  typeArguments: [this.bounty_type],
103
106
  });
@@ -239,6 +242,17 @@ export class Demand {
239
242
  });
240
243
  this.permission = new_permission;
241
244
  }
245
+ static parseObjectType = (chain_type) => {
246
+ if (chain_type) {
247
+ const s = 'demand::Demand<';
248
+ const i = chain_type.indexOf(s);
249
+ if (i > 0) {
250
+ let r = chain_type.slice(i + s.length, chain_type.length - 1);
251
+ return r;
252
+ }
253
+ }
254
+ return '';
255
+ };
242
256
  static MAX_BOUNTY_COUNT = 200;
243
257
  static MAX_PRESENTERS_COUNT = 200;
244
258
  }
package/dist/entity.d.ts CHANGED
@@ -16,8 +16,9 @@ export declare class Entity {
16
16
  static From(protocol: Protocol): Entity;
17
17
  mark(resource: Resource, address: string, like: 'like' | 'dislike'): void;
18
18
  update(info: Entity_Info): void;
19
- create_resource(description: string): ResourceAddress;
19
+ create_resource(): ResourceAddress;
20
20
  destroy_resource(resource: Resource): import("@mysten/sui.js/transactions").TransactionResult;
21
21
  transfer_resource(resource: Resource, new_address: string): import("@mysten/sui.js/transactions").TransactionResult;
22
+ query_ent(address_queried: string): void;
22
23
  }
23
24
  //# sourceMappingURL=entity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAc,SAAS,EAAE,eAAe,EAAmC,MAAM,YAAY,CAAC;AAG/G,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC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AAQ,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,GAAG,SAAS;IAU/D,MAAM,CAAC,IAAI,EAAE,WAAW;IAuBxB,eAAe,IAAK,eAAe;IAQnC,gBAAgB,CAAC,QAAQ,EAAC,QAAQ;IAQlC,iBAAiB,CAAC,QAAQ,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM;IASvD,SAAS,CAAC,eAAe,EAAC,MAAM;CAWnC"}
package/dist/entity.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BCS } from '@mysten/bcs';
2
2
  import { Protocol } from './protocol';
3
- import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, } from './utils';
3
+ import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, } from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
5
  export class Entity {
6
6
  object;
@@ -37,19 +37,25 @@ export class Entity {
37
37
  ERROR(Errors.isValidHttpUrl, 'update:homepage');
38
38
  if (info?.discord && !IsValidName(info.discord))
39
39
  ERROR(Errors.IsValidName, 'update:discord');
40
- let txb = this.protocol.CurrentSession();
40
+ const txb = this.protocol.CurrentSession();
41
+ const bytes = Bcs.getInstance().bcs.ser('PersonalInfo', {
42
+ name: info.name ? new TextEncoder().encode(info.name) : '',
43
+ description: info?.description ? new TextEncoder().encode(info.description) : '',
44
+ avatar: info?.avatar ?? '',
45
+ twitter: info?.twitter ?? '',
46
+ discord: info?.discord ?? '',
47
+ homepage: info?.homepage ?? '',
48
+ }).toBytes();
41
49
  txb.moveCall({
42
50
  target: this.protocol.EntityFn('avatar_update'),
43
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(JSON.stringify(info), BCS.STRING)]
51
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure([].slice.call(bytes), 'vector<u8>')]
44
52
  });
45
53
  }
46
- create_resource(description) {
47
- if (!IsValidDesription(description))
48
- ERROR(Errors.IsValidDesription, 'create_resource');
54
+ create_resource() {
49
55
  let txb = this.protocol.CurrentSession();
50
56
  return txb.moveCall({
51
57
  target: this.protocol.EntityFn('resource_create'),
52
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(description, BCS.STRING)]
58
+ arguments: [Protocol.TXB_OBJECT(txb, this.object)]
53
59
  });
54
60
  }
55
61
  destroy_resource(resource) {
@@ -68,4 +74,14 @@ export class Entity {
68
74
  arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, resource.get_object()), txb.pure(new_address, BCS.ADDRESS)]
69
75
  });
70
76
  }
77
+ query_ent(address_queried) {
78
+ if (!address_queried) {
79
+ ERROR(Errors.InvalidParam, 'query_ent');
80
+ }
81
+ const txb = this.protocol.CurrentSession();
82
+ txb.moveCall({
83
+ target: this.protocol.EntityFn('QueryEnt'),
84
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(address_queried, BCS.ADDRESS)]
85
+ });
86
+ }
71
87
  }
@@ -4,7 +4,8 @@ export declare enum Errors {
4
4
  IsValidName_AllowEmpty = "invalid name",
5
5
  IsValidEndpoint = "invalid endpoint",
6
6
  IsValidAddress = "invalid address",
7
- IsValidArgType = "invalid argumentType",
7
+ IsValidArgType = "invalid argument type",
8
+ IsValidTokenType = "invalid token type",
8
9
  IsValidUint = "invalid uint",
9
10
  IsValidInt = "invalid int",
10
11
  IsValidPercent = "invalid percent",
@@ -17,6 +18,7 @@ export declare enum Errors {
17
18
  Fail = "fail",
18
19
  IsValidIndentifier = "indentifier invalid",
19
20
  isValidHttpUrl = "invalid url",
21
+ IsValidUserDefinedIndex = "invalid user defined permission index",
20
22
  bcsTypeInvalid = "invalid bcs type"
21
23
  }
22
24
  export declare const ERROR: (error: Errors, info?: any) => never;
@@ -1 +1 @@
1
- {"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AACA,oBAAY,MAAM;IACd,iBAAiB,wBAAwB;IACzC,WAAW,iBAAiB;IAC5B,sBAAsB,iBAAiB;IACvC,eAAe,qBAAqB;IACpC,cAAc,oBAAoB;IAClC,cAAc,yBAAyB;IACvC,WAAW,iBAAiB;IAC5B,UAAU,gBAAgB;IAC1B,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;IAC9B,cAAc,oBAAoB;IAClC,UAAU,uBAAuB;IACjC,YAAY,sBAAuB;IACnC,sBAAsB,6BAA6B;IACnD,UAAU,gBAAgB;IAC1B,IAAI,SAAS;IACb,kBAAkB,wBAAwB;IAC1C,cAAc,gBAAgB;IAC9B,cAAc,qBAAqB;CACtC;AAED,eAAO,MAAM,KAAK,UAAU,MAAM,SAAQ,GAAG,UAG5C,CAAA"}
1
+ {"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AACA,oBAAY,MAAM;IACd,iBAAiB,wBAAwB;IACzC,WAAW,iBAAiB;IAC5B,sBAAsB,iBAAiB;IACvC,eAAe,qBAAqB;IACpC,cAAc,oBAAoB;IAClC,cAAc,0BAA0B;IACxC,gBAAgB,uBAAuB;IACvC,WAAW,iBAAiB;IAC5B,UAAU,gBAAgB;IAC1B,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;IAC9B,cAAc,oBAAoB;IAClC,UAAU,uBAAuB;IACjC,YAAY,sBAAuB;IACnC,sBAAsB,6BAA6B;IACnD,UAAU,gBAAgB;IAC1B,IAAI,SAAS;IACb,kBAAkB,wBAAwB;IAC1C,cAAc,gBAAgB;IAC9B,uBAAuB,0CAA0C;IACjE,cAAc,qBAAqB;CACtC;AAED,eAAO,MAAM,KAAK,UAAU,MAAM,SAAQ,GAAG,UAG5C,CAAA"}
package/dist/exception.js CHANGED
@@ -5,7 +5,8 @@ export var Errors;
5
5
  Errors["IsValidName_AllowEmpty"] = "invalid name";
6
6
  Errors["IsValidEndpoint"] = "invalid endpoint";
7
7
  Errors["IsValidAddress"] = "invalid address";
8
- Errors["IsValidArgType"] = "invalid argumentType";
8
+ Errors["IsValidArgType"] = "invalid argument type";
9
+ Errors["IsValidTokenType"] = "invalid token type";
9
10
  Errors["IsValidUint"] = "invalid uint";
10
11
  Errors["IsValidInt"] = "invalid int";
11
12
  Errors["IsValidPercent"] = "invalid percent";
@@ -18,6 +19,7 @@ export var Errors;
18
19
  Errors["Fail"] = "fail";
19
20
  Errors["IsValidIndentifier"] = "indentifier invalid";
20
21
  Errors["isValidHttpUrl"] = "invalid url";
22
+ Errors["IsValidUserDefinedIndex"] = "invalid user defined permission index";
21
23
  Errors["bcsTypeInvalid"] = "invalid bcs type";
22
24
  })(Errors || (Errors = {}));
23
25
  export const ERROR = (error, info) => {
package/dist/guard.js CHANGED
@@ -169,7 +169,7 @@ export class Guard {
169
169
  [MODULES.reward, 'sponsor', 162, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
170
170
  [MODULES.reward, 'sponsor_count', 163, [], ValueType.TYPE_U64],
171
171
  [MODULES.reward, 'bAllowRepeatClaim', 164, [], ValueType.TYPE_BOOL],
172
- [MODULES.reward, 'claimed_potions_count', 165, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
172
+ [MODULES.reward, 'claimed_portions_count', 165, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
173
173
  [MODULES.vote, 'permission', 171, [], ValueType.TYPE_ADDRESS],
174
174
  [MODULES.vote, 'bOptions_locked_for_voting', 172, [], ValueType.TYPE_BOOL],
175
175
  [MODULES.vote, 'bdeadline_locked', 173, [], ValueType.TYPE_BOOL],
package/dist/machine.js CHANGED
@@ -226,7 +226,7 @@ export class Machine {
226
226
  else {
227
227
  txb.moveCall({
228
228
  target: this.protocol.MachineFn('repository_remove_with_passport'),
229
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(repositories, 'vector<address>'),
229
+ arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(repositories), 'vector<address>'),
230
230
  Protocol.TXB_OBJECT(txb, this.permission)],
231
231
  });
232
232
  }
@@ -241,7 +241,7 @@ export class Machine {
241
241
  else {
242
242
  txb.moveCall({
243
243
  target: this.protocol.MachineFn('repository_remove'),
244
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(repositories, 'vector<address>'),
244
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(repositories), 'vector<address>'),
245
245
  Protocol.TXB_OBJECT(txb, this.permission)],
246
246
  });
247
247
  }
@@ -4,12 +4,12 @@ export declare enum PermissionIndex {
4
4
  repository_set_description_set = 101,
5
5
  repository_set_policy_mode = 102,
6
6
  repository_add_policies = 103,
7
- repository_remove_policies = 104,
7
+ repository_remove_policies = 103,
8
8
  repository_set_policy_description = 105,
9
9
  repository_set_policy_permission = 106,
10
10
  repository_reference_add = 107,
11
- repository_reference_remove = 108,
12
- repository_reference_removeall = 108,
11
+ repository_reference_remove = 107,
12
+ repository_reference_removeall = 107,
13
13
  vote = 150,
14
14
  vote_set_description = 151,
15
15
  vote_set_reference = 152,
@@ -28,13 +28,16 @@ export declare enum PermissionIndex {
28
28
  service_set_stock = 203,
29
29
  service_add_stock = 203,
30
30
  service_reduce_stock = 203,
31
+ service_set_sale_endpoint = 204,
31
32
  service_set_payee = 205,
32
33
  service_repository_add = 206,
33
34
  service_repository_remove = 207,
34
35
  service_add_withdraw_guards = 208,
35
- service_remove_withdraw_guards = 209,
36
+ service_remove_withdraw_guards = 208,
37
+ service_removeall_withdraw_guards = 208,
36
38
  service_add_refund_guards = 210,
37
- service_remove_refund_guards = 211,
39
+ service_remove_refund_guards = 210,
40
+ service_removeall_refund_guards = 210,
38
41
  service_add_sales = 212,
39
42
  service_remove_sales = 213,
40
43
  service_discount_transfer = 214,
@@ -53,7 +56,7 @@ export declare enum PermissionIndex {
53
56
  reward_refund = 241,
54
57
  reward_expand_time = 242,
55
58
  reward_add_guard = 243,
56
- reward_remove_guard = 244,
59
+ reward_remove_guard = 243,
57
60
  reward_set_description = 245,
58
61
  reward_lock_guards = 246,
59
62
  demand = 260,
@@ -80,6 +83,14 @@ export declare enum PermissionIndex {
80
83
  progress_unhold = 654,
81
84
  user_defined_start = 10000
82
85
  }
86
+ export interface PermissionInfoType {
87
+ index: number;
88
+ name: string;
89
+ description: string;
90
+ module: string;
91
+ guard?: string;
92
+ }
93
+ export declare const PermissionInfo: PermissionInfoType[];
83
94
  export type PermissionIndexType = PermissionIndex | number;
84
95
  export type Permission_Index = {
85
96
  index: PermissionIndexType;
@@ -92,12 +103,16 @@ export type Permission_Entity = {
92
103
  export declare class Permission {
93
104
  protected protocol: Protocol;
94
105
  protected object: TxbObject;
95
- get_object(): void;
106
+ get_object(): TxbObject;
96
107
  private constructor();
97
108
  static From(protocol: Protocol, object: TxbObject): Permission;
98
109
  static New(protocol: Protocol, description: string): Permission;
99
110
  launch(): PermissionAddress;
100
111
  destroy(): void;
112
+ add_userdefine(index: number, name: string): void;
113
+ remove_userdefine(index: number): void;
114
+ change_entity(old_entity: string, new_entity: string): void;
115
+ add_entity2(entities: string[], index?: PermissionIndexType): void;
101
116
  add_entity(entities: Permission_Entity[]): void;
102
117
  set_guard(entity_address: string, index: PermissionIndexType, guard?: GuardObject): void;
103
118
  remove_index(entity_address: string, index: PermissionIndexType[]): void;
@@ -109,6 +124,7 @@ export declare class Permission {
109
124
  static MAX_ADMIN_COUNT: number;
110
125
  static MAX_ENTITY_COUNT: number;
111
126
  static MAX_PERMISSION_INDEX_COUNT: number;
127
+ static MAX_PERSONAL_PERMISSION_COUNT: number;
112
128
  static IsValidUserDefinedIndex: (index: number) => boolean;
113
129
  static IsValidPermissionIndex: (index: PermissionIndexType) => boolean;
114
130
  }
@@ -1 +1 @@
1
- {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,SAAS,EAAoB,iBAAiB,EAAE,WAAW,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAK9G,oBAAY,eAAe;IACvB,UAAU,MAAM;IAChB,8BAA8B,MAAM;IACpC,0BAA0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,CAAC,EAAC,OAAO;IAwBhD,YAAY,CAAC,SAAS,EAAC,MAAM;IAY7B,MAAM,CAAC,eAAe,SAAM;IAC5B,MAAM,CAAC,gBAAgB,SAAQ;IAC/B,MAAM,CAAC,0BAA0B,SAAO;IACxC,MAAM,CAAC,6BAA6B,SAAO;IAC3C,MAAM,CAAC,uBAAuB,UAAU,MAAM,aAE7C;IAED,MAAM,CAAC,sBAAsB,UAAU,mBAAmB,KAAI,OAAO,CAOpE;CACJ"}
@@ -1,6 +1,6 @@
1
1
  import { BCS } from '@mysten/bcs';
2
2
  import { Protocol } from './protocol';
3
- import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs } from './utils';
3
+ import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs, IsValidName } from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
5
  import { ValueType } from './protocol';
6
6
  export var PermissionIndex;
@@ -9,12 +9,12 @@ export var PermissionIndex;
9
9
  PermissionIndex[PermissionIndex["repository_set_description_set"] = 101] = "repository_set_description_set";
10
10
  PermissionIndex[PermissionIndex["repository_set_policy_mode"] = 102] = "repository_set_policy_mode";
11
11
  PermissionIndex[PermissionIndex["repository_add_policies"] = 103] = "repository_add_policies";
12
- PermissionIndex[PermissionIndex["repository_remove_policies"] = 104] = "repository_remove_policies";
12
+ PermissionIndex[PermissionIndex["repository_remove_policies"] = 103] = "repository_remove_policies";
13
13
  PermissionIndex[PermissionIndex["repository_set_policy_description"] = 105] = "repository_set_policy_description";
14
14
  PermissionIndex[PermissionIndex["repository_set_policy_permission"] = 106] = "repository_set_policy_permission";
15
15
  PermissionIndex[PermissionIndex["repository_reference_add"] = 107] = "repository_reference_add";
16
- PermissionIndex[PermissionIndex["repository_reference_remove"] = 108] = "repository_reference_remove";
17
- PermissionIndex[PermissionIndex["repository_reference_removeall"] = 108] = "repository_reference_removeall";
16
+ PermissionIndex[PermissionIndex["repository_reference_remove"] = 107] = "repository_reference_remove";
17
+ PermissionIndex[PermissionIndex["repository_reference_removeall"] = 107] = "repository_reference_removeall";
18
18
  PermissionIndex[PermissionIndex["vote"] = 150] = "vote";
19
19
  PermissionIndex[PermissionIndex["vote_set_description"] = 151] = "vote_set_description";
20
20
  PermissionIndex[PermissionIndex["vote_set_reference"] = 152] = "vote_set_reference";
@@ -33,13 +33,16 @@ export var PermissionIndex;
33
33
  PermissionIndex[PermissionIndex["service_set_stock"] = 203] = "service_set_stock";
34
34
  PermissionIndex[PermissionIndex["service_add_stock"] = 203] = "service_add_stock";
35
35
  PermissionIndex[PermissionIndex["service_reduce_stock"] = 203] = "service_reduce_stock";
36
+ PermissionIndex[PermissionIndex["service_set_sale_endpoint"] = 204] = "service_set_sale_endpoint";
36
37
  PermissionIndex[PermissionIndex["service_set_payee"] = 205] = "service_set_payee";
37
38
  PermissionIndex[PermissionIndex["service_repository_add"] = 206] = "service_repository_add";
38
39
  PermissionIndex[PermissionIndex["service_repository_remove"] = 207] = "service_repository_remove";
39
40
  PermissionIndex[PermissionIndex["service_add_withdraw_guards"] = 208] = "service_add_withdraw_guards";
40
- PermissionIndex[PermissionIndex["service_remove_withdraw_guards"] = 209] = "service_remove_withdraw_guards";
41
+ PermissionIndex[PermissionIndex["service_remove_withdraw_guards"] = 208] = "service_remove_withdraw_guards";
42
+ PermissionIndex[PermissionIndex["service_removeall_withdraw_guards"] = 208] = "service_removeall_withdraw_guards";
41
43
  PermissionIndex[PermissionIndex["service_add_refund_guards"] = 210] = "service_add_refund_guards";
42
- PermissionIndex[PermissionIndex["service_remove_refund_guards"] = 211] = "service_remove_refund_guards";
44
+ PermissionIndex[PermissionIndex["service_remove_refund_guards"] = 210] = "service_remove_refund_guards";
45
+ PermissionIndex[PermissionIndex["service_removeall_refund_guards"] = 210] = "service_removeall_refund_guards";
43
46
  PermissionIndex[PermissionIndex["service_add_sales"] = 212] = "service_add_sales";
44
47
  PermissionIndex[PermissionIndex["service_remove_sales"] = 213] = "service_remove_sales";
45
48
  PermissionIndex[PermissionIndex["service_discount_transfer"] = 214] = "service_discount_transfer";
@@ -58,7 +61,7 @@ export var PermissionIndex;
58
61
  PermissionIndex[PermissionIndex["reward_refund"] = 241] = "reward_refund";
59
62
  PermissionIndex[PermissionIndex["reward_expand_time"] = 242] = "reward_expand_time";
60
63
  PermissionIndex[PermissionIndex["reward_add_guard"] = 243] = "reward_add_guard";
61
- PermissionIndex[PermissionIndex["reward_remove_guard"] = 244] = "reward_remove_guard";
64
+ PermissionIndex[PermissionIndex["reward_remove_guard"] = 243] = "reward_remove_guard";
62
65
  PermissionIndex[PermissionIndex["reward_set_description"] = 245] = "reward_set_description";
63
66
  PermissionIndex[PermissionIndex["reward_lock_guards"] = 246] = "reward_lock_guards";
64
67
  PermissionIndex[PermissionIndex["demand"] = 260] = "demand";
@@ -85,10 +88,83 @@ export var PermissionIndex;
85
88
  PermissionIndex[PermissionIndex["progress_unhold"] = 654] = "progress_unhold";
86
89
  PermissionIndex[PermissionIndex["user_defined_start"] = 10000] = "user_defined_start";
87
90
  })(PermissionIndex || (PermissionIndex = {}));
91
+ export const PermissionInfo = [
92
+ { index: PermissionIndex.repository, name: 'Repository', description: 'repository', module: 'repository' },
93
+ { index: PermissionIndex.repository_set_description_set, name: 'Description', description: 'repository_set_description_set', module: 'repository' },
94
+ { index: PermissionIndex.repository_set_policy_mode, name: 'Policy mode', description: 'repository_set_policy_mode', module: 'repository' },
95
+ { index: PermissionIndex.repository_add_policies, name: 'Add Policy', description: 'brepository_add_policies', module: 'repository' },
96
+ { index: PermissionIndex.repository_remove_policies, name: 'Remove Policy', description: 'build machine', module: 'repository' },
97
+ { index: PermissionIndex.repository_set_policy_description, name: 'Policy Description', description: 'build machine', module: 'repository' },
98
+ { index: PermissionIndex.repository_set_policy_permission, name: 'Policy Permission', description: 'build machine', module: 'repository' },
99
+ { index: PermissionIndex.repository_reference_add, name: 'Add Reference', description: 'build machine', module: 'repository' },
100
+ { index: PermissionIndex.repository_reference_remove, name: 'Remove Reference', description: 'build machine', module: 'repository' },
101
+ { index: PermissionIndex.vote, name: 'Vote', description: 'build machine', module: 'vote' },
102
+ { index: PermissionIndex.vote_set_description, name: 'Description', description: 'build machine', module: 'vote' },
103
+ { index: PermissionIndex.vote_set_reference, name: 'Reference', description: 'build machine', module: 'vote' },
104
+ { index: PermissionIndex.vote_add_guard, name: 'Add Guard', description: 'build machine', module: 'vote' },
105
+ { index: PermissionIndex.vote_remove_guard, name: 'Remove Guard', description: 'build machine', module: 'vote' },
106
+ { index: PermissionIndex.vote_add_option, name: 'Add Option', description: 'build machine', module: 'vote' },
107
+ { index: PermissionIndex.vote_remove_option, name: 'Remove Option', description: 'build machine', module: 'vote' },
108
+ { index: PermissionIndex.vote_set_max_choice_count, name: 'Choice count', description: 'build machine', module: 'vote' },
109
+ { index: PermissionIndex.vote_open_voting, name: 'Open voting', description: 'build machine', module: 'vote' },
110
+ { index: PermissionIndex.vote_lock_deadline, name: 'Lock deadline', description: 'build machine', module: 'vote' },
111
+ { index: PermissionIndex.vote_expand_deadline, name: 'Expand deadline', description: 'build machine', module: 'vote' },
112
+ { index: PermissionIndex.vote_lock_guard, name: 'Lock Guard', description: 'build machine', module: 'vote' },
113
+ { index: PermissionIndex.service, name: 'Service', description: 'build machine', module: 'service' },
114
+ { index: PermissionIndex.service_set_description, name: 'Description', description: 'build machine', module: 'service' },
115
+ { index: PermissionIndex.service_set_price, name: 'Price', description: 'build machine', module: 'service' },
116
+ { index: PermissionIndex.service_set_stock, name: 'Inventory', description: 'build machine', module: 'service' },
117
+ { index: PermissionIndex.service_set_payee, name: 'Payee', description: 'build machine', module: 'service' },
118
+ { index: PermissionIndex.service_repository_add, name: 'Add Repository', description: 'build machine', module: 'service' },
119
+ { index: PermissionIndex.service_repository_remove, name: 'Remove Repository', description: 'build machine', module: 'service' },
120
+ { index: PermissionIndex.service_add_withdraw_guards, name: 'Withdraw Guard', description: 'Add, remove withdraw guards', module: 'service' },
121
+ { index: PermissionIndex.service_add_refund_guards, name: 'Refund Guard', description: 'Add, remove refund guards', module: 'service' },
122
+ { index: PermissionIndex.service_remove_refund_guards, name: 'Remove Refund Guard', description: 'build machine', module: 'service' },
123
+ { index: PermissionIndex.service_add_sales, name: 'Add sales', description: 'build machine', module: 'service' },
124
+ { index: PermissionIndex.service_remove_sales, name: 'Remove sales', description: 'build machine', module: 'service' },
125
+ { index: PermissionIndex.service_discount_transfer, name: 'Discount', description: 'build machine', module: 'service' },
126
+ { index: PermissionIndex.service_withdraw, name: 'Withdraw', description: 'build machine', module: 'service' },
127
+ { index: PermissionIndex.service_set_buy_guard, name: 'Buyer Guard', description: 'build machine', module: 'service' },
128
+ { index: PermissionIndex.service_set_machine, name: 'Machine', description: 'build machine', module: 'service' },
129
+ { index: PermissionIndex.service_set_endpoint, name: 'Endpoint', description: 'build machine', module: 'service' },
130
+ { index: PermissionIndex.service_publish, name: 'Publish', description: 'build machine', module: 'service' },
131
+ { index: PermissionIndex.service_clone, name: 'Clone', description: 'build machine', module: 'service' },
132
+ { index: PermissionIndex.service_set_customer_required, name: 'Buyer info', description: 'build machine', module: 'service' },
133
+ { index: PermissionIndex.service_change_order_required_pubkey, name: 'Order pubkey', description: 'build machine', module: 'service' },
134
+ { index: PermissionIndex.service_pause, name: 'Pause', description: 'build machine', module: 'service' },
135
+ { index: PermissionIndex.reward, name: 'Reward', description: 'build machine', module: 'reward' },
136
+ { index: PermissionIndex.reward_refund, name: 'Refund', description: 'build machine', module: 'reward' },
137
+ { index: PermissionIndex.reward_expand_time, name: 'Expand deadline', description: 'build machine', module: 'reward' },
138
+ { index: PermissionIndex.reward_add_guard, name: 'Add Guard', description: 'build machine', module: 'reward' },
139
+ { index: PermissionIndex.reward_remove_guard, name: 'Remove Guard', description: 'build machine', module: 'reward' },
140
+ { index: PermissionIndex.reward_set_description, name: 'Description', description: 'build machine', module: 'reward' },
141
+ { index: PermissionIndex.reward_lock_guards, name: 'Lock Guard', description: 'build machine', module: 'reward' },
142
+ { index: PermissionIndex.demand, name: 'Demand', description: 'build machine', module: 'demand' },
143
+ { index: PermissionIndex.demand_refund, name: 'Refund', description: 'build machine', module: 'demand' },
144
+ { index: PermissionIndex.demand_expand_time, name: 'Expand deadline', description: 'build machine', module: 'demand' },
145
+ { index: PermissionIndex.demand_set_guard, name: 'Guard', description: 'build machine', module: 'demand' },
146
+ { index: PermissionIndex.demand_set_description, name: 'Description', description: 'build machine', module: 'demand' },
147
+ { index: PermissionIndex.demand_yes, name: 'Yes', description: 'build machine', module: 'demand' },
148
+ { index: PermissionIndex.machine, name: 'Machine', description: 'build machine', module: 'machine' },
149
+ { index: PermissionIndex.machine_set_description, name: 'Description', description: 'machine_set_description', module: 'machine' },
150
+ { index: PermissionIndex.machine_add_repository, name: 'Add Repository', description: 'machine_add_repository', module: 'machine' },
151
+ { index: PermissionIndex.machine_remove_repository, name: 'Remove Repository', description: 'machine_remove_repository', module: 'machine' },
152
+ { index: PermissionIndex.machine_clone, name: 'Clone', description: 'machine_clone', module: 'machine' },
153
+ { index: PermissionIndex.machine_add_node, name: 'Add node', description: 'machine_add_node/2', module: 'machine' },
154
+ { index: PermissionIndex.machine_remove_node, name: 'Remove node', description: 'machine_remove_node', module: 'machine' },
155
+ { index: PermissionIndex.machine_set_endpoint, name: 'Endpoint', description: 'machine_set_endpoint', module: 'machine' },
156
+ { index: PermissionIndex.machine_pause, name: 'Pause', description: 'machine_pause', module: 'machine' },
157
+ { index: PermissionIndex.machine_publish, name: 'Publish', description: 'machine_publish', module: 'machine' },
158
+ { index: PermissionIndex.progress, name: 'Progress', description: 'build progress', module: 'progress' },
159
+ { index: PermissionIndex.progress_set_namedOperator, name: 'Operator', description: 'progress_set_namedOperator', module: 'progress' },
160
+ { index: PermissionIndex.progress_bind_task, name: 'Bind', description: 'progress_bind_task', module: 'progress' },
161
+ { index: PermissionIndex.progress_set_context_repository, name: 'Repository', description: 'progress_set_context_repository', module: 'progress' },
162
+ { index: PermissionIndex.progress_unhold, name: 'Unhold', description: 'progress_unhold', module: 'progress' },
163
+ ];
88
164
  export class Permission {
89
165
  protocol;
90
166
  object;
91
- get_object() { this.object; }
167
+ get_object() { return this.object; }
92
168
  constructor(protocol) {
93
169
  this.protocol = protocol;
94
170
  this.object = '';
@@ -124,9 +200,65 @@ export class Permission {
124
200
  arguments: [Protocol.TXB_OBJECT(txb, this.object)],
125
201
  });
126
202
  }
203
+ add_userdefine(index, name) {
204
+ if (!Permission.IsValidUserDefinedIndex(index)) {
205
+ ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
206
+ }
207
+ if (!IsValidName(name)) {
208
+ ERROR(Errors.IsValidName, 'add_userdefine');
209
+ }
210
+ let txb = this.protocol.CurrentSession();
211
+ txb.moveCall({
212
+ target: this.protocol.PermissionFn('user_define_add'),
213
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64), txb.pure(name, BCS.STRING)]
214
+ });
215
+ }
216
+ remove_userdefine(index) {
217
+ if (!Permission.IsValidUserDefinedIndex(index)) {
218
+ ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
219
+ }
220
+ let txb = this.protocol.CurrentSession();
221
+ txb.moveCall({
222
+ target: this.protocol.PermissionFn('user_define_remove'),
223
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64)]
224
+ });
225
+ }
226
+ change_entity(old_entity, new_entity) {
227
+ if (!IsValidAddress(old_entity) || !IsValidAddress(new_entity)) {
228
+ ERROR(Errors.IsValidAddress, 'change_entity');
229
+ }
230
+ let txb = this.protocol.CurrentSession();
231
+ txb.moveCall({
232
+ target: this.protocol.PermissionFn('change_entity'),
233
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_entity, BCS.ADDRESS),
234
+ txb.pure(new_entity, BCS.ADDRESS)]
235
+ });
236
+ }
237
+ add_entity2(entities, index) {
238
+ if (!entities) {
239
+ ERROR(Errors.InvalidParam, 'add_entity2');
240
+ }
241
+ if (!IsValidArray(entities, IsValidAddress)) {
242
+ ERROR(Errors.IsValidArray, 'add_entity2');
243
+ }
244
+ let txb = this.protocol.CurrentSession();
245
+ if (index) {
246
+ txb.moveCall({
247
+ target: this.protocol.PermissionFn('add_with_index'),
248
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64),
249
+ txb.pure(array_unique(entities), 'vector<address>')]
250
+ });
251
+ }
252
+ else {
253
+ txb.moveCall({
254
+ target: this.protocol.PermissionFn('add'),
255
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(entities), 'vector<address>')]
256
+ });
257
+ }
258
+ }
127
259
  add_entity(entities) {
128
260
  if (!entities) {
129
- ERROR(Errors.InvalidParam, 'entities');
261
+ ERROR(Errors.InvalidParam, 'add_entity');
130
262
  }
131
263
  let bValid = true;
132
264
  let e = entities.forEach((v) => {
@@ -159,13 +291,13 @@ export class Permission {
159
291
  }
160
292
  }
161
293
  }
162
- if (indexes.length > 0) {
163
- txb.moveCall({
164
- target: this.protocol.PermissionFn('add_batch'),
165
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity.entity_address, BCS.ADDRESS),
166
- txb.pure(indexes, 'vector<u64>')]
167
- });
168
- }
294
+ //if (indexes.length > 0) {
295
+ txb.moveCall({
296
+ target: this.protocol.PermissionFn('add_batch'),
297
+ arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity.entity_address, BCS.ADDRESS),
298
+ txb.pure(indexes, 'vector<u64>')]
299
+ });
300
+ //}
169
301
  }
170
302
  // set guards
171
303
  guards.forEach(({ entity_address, index, guard }) => {
@@ -280,6 +412,7 @@ export class Permission {
280
412
  static MAX_ADMIN_COUNT = 64;
281
413
  static MAX_ENTITY_COUNT = 2000;
282
414
  static MAX_PERMISSION_INDEX_COUNT = 200;
415
+ static MAX_PERSONAL_PERMISSION_COUNT = 200;
283
416
  static IsValidUserDefinedIndex = (index) => {
284
417
  return index >= PermissionIndex.user_defined_start && IsValidUint(index);
285
418
  };