wowok 1.2.11 → 1.3.3

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/src/permission.ts CHANGED
@@ -1,36 +1,36 @@
1
- import { BCS } from '@mysten/bcs';
2
1
  import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
3
2
  import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUintLarge, Bcs, IsValidName} from './utils';
4
3
  import { ERROR, Errors } from './exception';
5
4
  import { ValueType } from './protocol';
6
- import { Passport } from './passport';
5
+ import { BCS } from '@mysten/bcs';
6
+ import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
7
7
 
8
8
  export enum PermissionIndex {
9
9
  repository = 100,
10
- repository_set_description_set = 101,
11
- repository_set_policy_mode = 102,
12
- repository_add_remove_policies = 103,
13
- repository_set_policy_description = 105,
14
- repository_set_policy_permission = 106,
10
+ repository_description = 101,
11
+ repository_policy_mode = 102,
12
+ repository_policies = 103,
13
+ repository_policy_description = 105,
14
+ repository_policy_permission = 106,
15
15
  repository_reference = 107,
16
16
 
17
17
  vote = 150,
18
- vote_set_description = 151,
19
- vote_set_reference = 152,
18
+ vote_description = 151,
19
+ vote_reference = 152,
20
20
  vote_guard = 153,
21
21
  vote_option = 155,
22
- vote_set_max_choice_count = 157,
22
+ vote_max_choice_count = 157,
23
23
  vote_open_voting = 158,
24
24
  vote_lock_deadline = 159,
25
25
  vote_expand_deadline = 160,
26
26
  vote_lock_guard = 161,
27
27
 
28
28
  service = 200,
29
- service_set_description = 201,
30
- service_set_price = 202,
31
- service_set_add_reduce_stock = 203,
32
- service_set_sale_endpoint = 204,
33
- service_set_payee = 205,
29
+ service_description = 201,
30
+ service_price = 202,
31
+ service_stock = 203,
32
+ service_sale_endpoint = 204,
33
+ service_payee = 205,
34
34
  service_repository = 206,
35
35
  service_withdraw_guards = 208,
36
36
  service_refund_guards = 210,
@@ -38,9 +38,9 @@ export enum PermissionIndex {
38
38
  service_remove_sales = 213,
39
39
  service_discount_transfer = 214,
40
40
  service_withdraw = 216,
41
- service_set_buy_guard = 217,
42
- service_set_machine = 218,
43
- service_set_endpoint = 219,
41
+ service_buy_guard = 217,
42
+ service_machine = 218,
43
+ service_endpoint = 219,
44
44
  service_publish = 220,
45
45
  service_clone = 221,
46
46
  service_customer_required = 222,
@@ -51,30 +51,33 @@ export enum PermissionIndex {
51
51
  reward_refund = 241,
52
52
  reward_expand_time = 242,
53
53
  reward_guard = 243,
54
- reward_set_description = 245,
54
+ reward_description = 245,
55
55
  reward_lock_guards = 246,
56
+ reward_claim_repeatably = 247,
57
+ reward_allow_claiming = 248,
56
58
 
57
59
  demand = 260,
58
60
  demand_refund = 261,
59
61
  demand_expand_time = 262,
60
- demand_set_guard = 263,
61
- demand_set_description = 264,
62
+ demand_guard = 263,
63
+ demand_description = 264,
62
64
  demand_yes = 265,
63
65
 
64
66
  machine = 600,
65
- machine_set_description = 601,
67
+ machine_description = 601,
66
68
  machine_repository = 602,
67
69
  machine_clone = 604,
68
70
  machine_node = 606,
69
- machine_set_endpoint = 608,
71
+ machine_endpoint = 608,
70
72
  machine_pause = 609,
71
73
  machine_publish = 610,
72
74
 
73
75
  progress = 650,
74
- progress_set_namedOperator = 651,
76
+ progress_namedOperator = 651,
75
77
  progress_bind_task = 652,
76
- progress_set_context_repository = 653,
78
+ progress_context_repository = 653,
77
79
  progress_unhold = 654,
80
+ progress_parent = 655,
78
81
  user_defined_start = 10000,
79
82
  }
80
83
 
@@ -91,6 +94,7 @@ export interface PermissionAnswer {
91
94
  owner?: boolean;
92
95
  admin?: boolean;
93
96
  items?: PermissionAnswerItem[]; // items === undefined, while errors
97
+ object: string; // permission object
94
98
  }
95
99
  export interface PermissionAnswerItem {
96
100
  query: PermissionIndexType;
@@ -101,29 +105,29 @@ export type OnPermissionAnswer = (answer: PermissionAnswer) => void;
101
105
 
102
106
  export const PermissionInfo : PermissionInfoType[] = [
103
107
  {index:PermissionIndex.repository, name:'Repository', description:'Launch new Repository', module: 'repository'},
104
- {index:PermissionIndex.repository_set_description_set, name:'Description', description:'Set Repository description', module: 'repository'},
105
- {index:PermissionIndex.repository_set_policy_mode, name:'Policy mode', description:'Set Repository policy mode', module: 'repository'},
106
- {index:PermissionIndex.repository_add_remove_policies, name:'Policy', description:'Add/Remove Repository policy', module: 'repository'},
107
- {index:PermissionIndex.repository_set_policy_description, name:'Policy Description', description:'Set Repository policy description', module: 'repository'},
108
- {index:PermissionIndex.repository_set_policy_permission, name:'Policy Permission', description:'Set Repository policy permission', module: 'repository'},
108
+ {index:PermissionIndex.repository_description, name:'Description', description:'Set Repository description', module: 'repository'},
109
+ {index:PermissionIndex.repository_policy_mode, name:'Policy mode', description:'Set Repository policy mode', module: 'repository'},
110
+ {index:PermissionIndex.repository_policies, name:'Policy', description:'Add/Remove/Edit Repository policy', module: 'repository'},
111
+ {index:PermissionIndex.repository_policy_description, name:'Policy Description', description:'Set Repository policy description', module: 'repository'},
112
+ {index:PermissionIndex.repository_policy_permission, name:'Policy Permission', description:'Set Repository policy permission', module: 'repository'},
109
113
  {index:PermissionIndex.repository_reference, name:'Reference', description:'Set Repository reference', module: 'repository'},
110
114
 
111
115
  {index:PermissionIndex.vote, name:'Vote', description:'Launch new Vote', module: 'vote'},
112
- {index:PermissionIndex.vote_set_description, name:'Description', description:'Set Vote description', module: 'vote'},
113
- {index:PermissionIndex.vote_set_reference, name:'Reference', description:'Set Vote reference', module: 'vote'},
116
+ {index:PermissionIndex.vote_description, name:'Description', description:'Set Vote description', module: 'vote'},
117
+ {index:PermissionIndex.vote_reference, name:'Reference', description:'Set Vote reference', module: 'vote'},
114
118
  {index:PermissionIndex.vote_guard, name:'Guard', description:'Set Vote guards', module: 'vote'},
115
119
  {index:PermissionIndex.vote_option, name:'Option', description:'Set Vote options', module: 'vote'},
116
- {index:PermissionIndex.vote_set_max_choice_count, name:'Choice count', description:'Set Vote max choice count', module: 'vote'},
120
+ {index:PermissionIndex.vote_max_choice_count, name:'Choice count', description:'Set Vote max choice count', module: 'vote'},
117
121
  {index:PermissionIndex.vote_open_voting, name:'Open voting', description:'Open voting', module: 'vote'},
118
122
  {index:PermissionIndex.vote_lock_deadline, name:'Lock deadline', description:'Set Vote deadline immutable', module: 'vote'},
119
123
  {index:PermissionIndex.vote_expand_deadline, name:'Expand deadline', description:'Expand Vote deadline', module: 'vote'},
120
124
  {index:PermissionIndex.vote_lock_guard, name:'Lock Guard', description:'Set Vote guards immutable', module: 'vote'},
121
125
 
122
126
  {index:PermissionIndex.service, name:'Service', description:'Launch new Service', module: 'service'},
123
- {index:PermissionIndex.service_set_description, name:'Description', description:'Set Service description', module: 'service'},
124
- {index:PermissionIndex.service_set_price, name:'Price', description:'Set Service item price', module: 'service'},
125
- {index:PermissionIndex.service_set_add_reduce_stock, name:'Inventory', description:'Set Service item inventory', module: 'service'},
126
- {index:PermissionIndex.service_set_payee, name:'Payee', description:'Set Service payee', module: 'service'},
127
+ {index:PermissionIndex.service_description, name:'Description', description:'Set Service description', module: 'service'},
128
+ {index:PermissionIndex.service_price, name:'Price', description:'Set Service item price', module: 'service'},
129
+ {index:PermissionIndex.service_stock, name:'Inventory', description:'Set Service item inventory', module: 'service'},
130
+ {index:PermissionIndex.service_payee, name:'Payee', description:'Set Service payee', module: 'service'},
127
131
  {index:PermissionIndex.service_repository, name:'Repository', description:'Set Service repositories', module: 'service'},
128
132
  {index:PermissionIndex.service_withdraw_guards, name:'Withdraw Guard', description:'Set Service withdraw guards', module: 'service'},
129
133
  {index:PermissionIndex.service_refund_guards, name:'Refund Guard', description:'Set Service refund guards', module: 'service'},
@@ -131,9 +135,9 @@ export const PermissionInfo : PermissionInfoType[] = [
131
135
  {index:PermissionIndex.service_remove_sales, name:'Remove sales', description:'Remove sale items for Service', module: 'service'},
132
136
  {index:PermissionIndex.service_discount_transfer, name:'Discount', description:'Launch discounts for Service', module: 'service'},
133
137
  {index:PermissionIndex.service_withdraw, name:'Withdraw', description:'Widthraw from Service orders', module: 'service'},
134
- {index:PermissionIndex.service_set_buy_guard, name:'Buyer Guard', description:'Set Guard of buying for Service', module: 'service'},
135
- {index:PermissionIndex.service_set_machine, name:'Machine', description:'Set Machine for Service', module: 'service'},
136
- {index:PermissionIndex.service_set_endpoint, name:'Endpoint', description:'Set Service endpoint', module: 'service'},
138
+ {index:PermissionIndex.service_buy_guard, name:'Buyer Guard', description:'Set Guard of buying for Service', module: 'service'},
139
+ {index:PermissionIndex.service_machine, name:'Machine', description:'Set Machine for Service', module: 'service'},
140
+ {index:PermissionIndex.service_endpoint, name:'Endpoint', description:'Set Service endpoint', module: 'service'},
137
141
  {index:PermissionIndex.service_publish, name:'Publish', description:'Publish Service', module: 'service'},
138
142
  {index:PermissionIndex.service_clone, name:'Clone', description:'Clone Service', module: 'service'},
139
143
  {index:PermissionIndex.service_customer_required, name:'Buyer info', description:'Set Service buyer info required', module: 'service'},
@@ -143,31 +147,34 @@ export const PermissionInfo : PermissionInfoType[] = [
143
147
  {index:PermissionIndex.reward, name:'Reward', description:'Launch new Reward', module: 'reward'},
144
148
  {index:PermissionIndex.reward_refund, name:'Refund', description:'Refund from Reward', module: 'reward'},
145
149
  {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'Expand Reward deadline', module: 'reward'},
146
- {index:PermissionIndex.reward_guard, name:'Guard', description:'build machine', module: 'Set Reward guard'},
147
- {index:PermissionIndex.reward_set_description, name:'Description', description:'Set Reward description', module: 'reward'},
150
+ {index:PermissionIndex.reward_guard, name:'Guard', description:'Set Reward guard', module: 'reward'},
151
+ {index:PermissionIndex.reward_description, name:'Description', description:'Set Reward description', module: 'reward'},
148
152
  {index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'Set Reward guard immutable', module: 'reward'},
153
+ {index:PermissionIndex.reward_claim_repeatably, name:'Claim repeatably', description:'Allow claimming repeatably', module: 'reward'},
154
+ {index:PermissionIndex.reward_allow_claiming, name:'Allow claiming', description:'Allow claiming', module: 'reward'},
149
155
 
150
156
  {index:PermissionIndex.demand, name:'Demand', description:'Launch new Demand', module: 'demand'},
151
157
  {index:PermissionIndex.demand_refund, name:'Refund', description:'Refund from Demand', module: 'demand'},
152
158
  {index:PermissionIndex.demand_expand_time, name:'Expand deadline', description:'Expand Demand deadline', module: 'demand'},
153
- {index:PermissionIndex.demand_set_guard, name:'Guard', description:'Set Demand guard', module: 'demand'},
154
- {index:PermissionIndex.demand_set_description, name:'Description', description:'Set Demand description', module: 'demand'},
159
+ {index:PermissionIndex.demand_guard, name:'Guard', description:'Set Demand guard', module: 'demand'},
160
+ {index:PermissionIndex.demand_description, name:'Description', description:'Set Demand description', module: 'demand'},
155
161
  {index:PermissionIndex.demand_yes, name:'Yes', description:'Pick the Deamand serice', module: 'demand'},
156
162
 
157
163
  {index:PermissionIndex.machine, name: 'Machine', description:'Launch new Machine', module: 'machine'},
158
- {index:PermissionIndex.machine_set_description, name: 'Description', description:'Set Machine description', module: 'machine'},
164
+ {index:PermissionIndex.machine_description, name: 'Description', description:'Set Machine description', module: 'machine'},
159
165
  {index:PermissionIndex.machine_repository, name: 'Repository', description:'Set Machine repository', module: 'machine'},
160
166
  {index:PermissionIndex.machine_clone, name: 'Clone', description:'Clone Machine', module: 'machine'},
161
167
  {index:PermissionIndex.machine_node, name: 'Node', description:'Set Machine nodes', module: 'machine'},
162
- {index:PermissionIndex.machine_set_endpoint, name: 'Endpoint', description:'Set Machine endpoint', module: 'machine'},
168
+ {index:PermissionIndex.machine_endpoint, name: 'Endpoint', description:'Set Machine endpoint', module: 'machine'},
163
169
  {index:PermissionIndex.machine_pause, name: 'Pause', description:'Pause/Unpause Machine', module: 'machine'},
164
170
  {index:PermissionIndex.machine_publish, name: 'Publish', description:'Publish Machine', module: 'machine'},
165
171
 
166
172
  {index:PermissionIndex.progress, name: 'Progress', description:'Launch new Progress', module: 'progress'},
167
- {index:PermissionIndex.progress_set_namedOperator, name: 'Operator', description:'Set Progress operators', module: 'progress'},
173
+ {index:PermissionIndex.progress_namedOperator, name: 'Operator', description:'Set Progress operators', module: 'progress'},
168
174
  {index:PermissionIndex.progress_bind_task, name: 'Bind', description:'Set Progress task', module: 'progress'},
169
- {index:PermissionIndex.progress_set_context_repository, name: 'Repository', description:'Set Progress repository', module: 'progress'},
175
+ {index:PermissionIndex.progress_context_repository, name: 'Repository', description:'Set Progress repository', module: 'progress'},
170
176
  {index:PermissionIndex.progress_unhold, name: 'Unhold', description:'Release Progress holdings', module: 'progress'},
177
+ {index:PermissionIndex.progress_parent, name: 'Parent', description:'Set Progress parent', module: 'progress'},
171
178
  ]
172
179
 
173
180
  export type PermissionIndexType = PermissionIndex | number;
@@ -183,46 +190,43 @@ export type Permission_Entity = {
183
190
  }
184
191
 
185
192
  export class Permission {
186
- protected protocol;
193
+ protected txb;
187
194
  protected object : TxbObject;
188
195
 
189
196
  get_object() { return this.object }
190
- private constructor(protocol:Protocol) {
191
- this.protocol = protocol;
197
+ private constructor(txb:TransactionBlock) {
198
+ this.txb = txb;
192
199
  this.object = '';
193
200
  }
194
- static From(protocol:Protocol, object:TxbObject) : Permission {
195
- let p = new Permission(protocol);
196
- p.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
201
+ static From(txb:TransactionBlock, object:TxbObject) : Permission {
202
+ let p = new Permission(txb);
203
+ p.object = Protocol.TXB_OBJECT(txb, object);
197
204
  return p
198
205
  }
199
206
 
200
- static New(protocol:Protocol, description:string) : Permission {
207
+ static New(txb:TransactionBlock, description:string) : Permission {
201
208
  if (!IsValidDesription(description)) {
202
209
  ERROR(Errors.IsValidDesription)
203
210
  }
204
- let p = new Permission(protocol);
205
- let txb = protocol.CurrentSession();
211
+ let p = new Permission(txb);
206
212
  p.object = txb.moveCall({
207
- target: protocol.PermissionFn('new') as FnCallType,
208
- arguments: [txb.pure(description)]
213
+ target: Protocol.Instance().PermissionFn('new') as FnCallType,
214
+ arguments: [txb.pure.string(description)]
209
215
  });
210
216
  return p
211
217
  }
212
218
 
213
219
  launch() : PermissionAddress {
214
- let txb = this.protocol.CurrentSession();
215
- return txb.moveCall({ // address returned
216
- target:this.protocol.PermissionFn('create') as FnCallType,
217
- arguments:[ Protocol.TXB_OBJECT(txb, this.object) ]
220
+ return this.txb.moveCall({ // address returned
221
+ target:Protocol.Instance().PermissionFn('create') as FnCallType,
222
+ arguments:[ Protocol.TXB_OBJECT(this.txb, this.object) ]
218
223
  })
219
224
  }
220
225
 
221
226
  destroy() {
222
- let txb = this.protocol.CurrentSession();
223
- txb.moveCall({
224
- target:this.protocol.PermissionFn('destroy') as FnCallType,
225
- arguments: [Protocol.TXB_OBJECT(txb, this.object)],
227
+ this.txb.moveCall({
228
+ target:Protocol.Instance().PermissionFn('destroy') as FnCallType,
229
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
226
230
  })
227
231
  }
228
232
  add_userdefine(index: number, name:string) {
@@ -233,10 +237,9 @@ export class Permission {
233
237
  if (!IsValidName(name)) {
234
238
  ERROR(Errors.IsValidName, 'add_userdefine');
235
239
  }
236
- let txb = this.protocol.CurrentSession();
237
- txb.moveCall({
238
- target:this.protocol.PermissionFn('user_define_add') as FnCallType,
239
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64), txb.pure(name)]
240
+ this.txb.moveCall({
241
+ target:Protocol.Instance().PermissionFn('user_define_add') as FnCallType,
242
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(index), this.txb.pure.string(name)]
240
243
  })
241
244
  }
242
245
 
@@ -245,10 +248,9 @@ export class Permission {
245
248
  ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
246
249
  }
247
250
 
248
- let txb = this.protocol.CurrentSession();
249
- txb.moveCall({
250
- target:this.protocol.PermissionFn('user_define_remove') as FnCallType,
251
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64)]
251
+ this.txb.moveCall({
252
+ target:Protocol.Instance().PermissionFn('user_define_remove') as FnCallType,
253
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(index)]
252
254
  })
253
255
  }
254
256
 
@@ -256,11 +258,11 @@ export class Permission {
256
258
  if (!IsValidAddress(old_entity) || !IsValidAddress(new_entity)) {
257
259
  ERROR(Errors.IsValidAddress, 'change_entity')
258
260
  }
259
- let txb = this.protocol.CurrentSession();
260
- txb.moveCall({
261
- target:this.protocol.PermissionFn('change_entity') as FnCallType,
262
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_entity, BCS.ADDRESS),
263
- txb.pure(new_entity, BCS.ADDRESS) ]
261
+
262
+ this.txb.moveCall({
263
+ target:Protocol.Instance().PermissionFn('change_entity') as FnCallType,
264
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(old_entity),
265
+ this.txb.pure.address(new_entity) ]
264
266
  })
265
267
  }
266
268
 
@@ -271,17 +273,16 @@ export class Permission {
271
273
  ERROR(Errors.IsValidArray, 'add_entity2');
272
274
  }
273
275
 
274
- let txb = this.protocol.CurrentSession();
275
276
  if (index) {
276
- txb.moveCall({
277
- target:this.protocol.PermissionFn('add_with_index') as FnCallType,
278
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64),
279
- txb.pure(array_unique(entities), 'vector<address>')]
277
+ this.txb.moveCall({
278
+ target:Protocol.Instance().PermissionFn('add_with_index') as FnCallType,
279
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u64(index),
280
+ this.txb.pure.vector('address', array_unique(entities))]
280
281
  })
281
282
  } else {
282
- txb.moveCall({
283
- target:this.protocol.PermissionFn('add') as FnCallType,
284
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(entities), 'vector<address>')]
283
+ this.txb.moveCall({
284
+ target:Protocol.Instance().PermissionFn('add') as FnCallType,
285
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(entities))]
285
286
  })
286
287
  }
287
288
  }
@@ -303,9 +304,7 @@ export class Permission {
303
304
  ERROR(Errors.InvalidParam, 'entities');
304
305
  }
305
306
 
306
- let txb = this.protocol.CurrentSession();
307
307
  let guards:any[] = [];
308
-
309
308
  for (let i = 0; i < entities.length; i++) {
310
309
  let entity = entities[i];
311
310
  let indexes :number[] = [];
@@ -324,19 +323,19 @@ export class Permission {
324
323
  }
325
324
  }
326
325
  //if (indexes.length > 0) {
327
- txb.moveCall({
328
- target:this.protocol.PermissionFn('add_batch') as FnCallType,
329
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity.entity_address, BCS.ADDRESS),
330
- txb.pure(indexes, 'vector<u64>')]
326
+ this.txb.moveCall({
327
+ target:Protocol.Instance().PermissionFn('add_batch') as FnCallType,
328
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity.entity_address),
329
+ this.txb.pure.vector('u64', indexes)]
331
330
  })
332
331
  //}
333
332
  }
334
333
  // set guards
335
334
  guards.forEach(({entity_address, index, guard}) => {
336
- txb.moveCall({
337
- target:this.protocol.PermissionFn('guard_set') as FnCallType,
338
- arguments:[ Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
339
- txb.pure(index, BCS.U64), Protocol.TXB_OBJECT(txb, guard)]
335
+ this.txb.moveCall({
336
+ target:Protocol.Instance().PermissionFn('guard_set') as FnCallType,
337
+ arguments:[ Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
338
+ this.txb.pure.u64(index), Protocol.TXB_OBJECT(this.txb, guard)]
340
339
  })
341
340
  })
342
341
  }
@@ -346,22 +345,21 @@ export class Permission {
346
345
  if (!IsValidAddress(entity_address)) {
347
346
  ERROR(Errors.IsValidAddress, 'entity_address')
348
347
  }
349
- if(!Permission.IsValidPermissionIndex(index)) {
348
+ if(!Permission.IsValidPermissionIndex(index) && !Permission.IsValidUserDefinedIndex(index)) {
350
349
  ERROR(Errors.IsValidPermissionIndex, 'index')
351
350
  }
352
351
 
353
- let txb = this.protocol.CurrentSession();
354
352
  if (guard) {
355
- txb.moveCall({
356
- target:this.protocol.PermissionFn('guard_set') as FnCallType,
357
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
358
- txb.pure(index, BCS.U64), Protocol.TXB_OBJECT(txb, guard)]
353
+ this.txb.moveCall({
354
+ target:Protocol.Instance().PermissionFn('guard_set') as FnCallType,
355
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
356
+ this.txb.pure.u64(index), Protocol.TXB_OBJECT(this.txb, guard)]
359
357
  })
360
358
  } else {
361
- txb.moveCall({
362
- target:this.protocol.PermissionFn('guard_none') as FnCallType,
363
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
364
- txb.pure(index, BCS.U64)]
359
+ this.txb.moveCall({
360
+ target:Protocol.Instance().PermissionFn('guard_none') as FnCallType,
361
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
362
+ this.txb.pure.u64(index)]
365
363
  })
366
364
  };
367
365
  }
@@ -374,11 +372,10 @@ export class Permission {
374
372
  ERROR(Errors.InvalidParam, 'index')
375
373
  }
376
374
 
377
- let txb = this.protocol.CurrentSession();
378
- txb.moveCall({
379
- target:this.protocol.PermissionFn('remove_index') as FnCallType,
380
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
381
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, array_unique(index)))]
375
+ this.txb.moveCall({
376
+ target:Protocol.Instance().PermissionFn('remove_index') as FnCallType,
377
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
378
+ this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, array_unique(index)))]
382
379
  })
383
380
  }
384
381
  remove_entity(entity_address:string[]) {
@@ -386,54 +383,52 @@ export class Permission {
386
383
  ERROR(Errors.IsValidArray)
387
384
  }
388
385
 
389
- let txb = this.protocol.CurrentSession();
390
- txb.moveCall({
391
- target:this.protocol.PermissionFn('remove') as FnCallType,
392
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(entity_address), 'vector<address>')]
386
+ this.txb.moveCall({
387
+ target:Protocol.Instance().PermissionFn('remove') as FnCallType,
388
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(entity_address))]
393
389
  })
394
- ;
395
390
  }
391
+
396
392
  set_description(description:string) {
397
393
  if (!IsValidDesription(description)) {
398
394
  ERROR(Errors.IsValidDesription)
399
395
  }
400
- let txb = this.protocol.CurrentSession();
401
- txb.moveCall({
402
- target:this.protocol.PermissionFn('description_set') as FnCallType,
403
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(description)]
396
+
397
+ this.txb.moveCall({
398
+ target:Protocol.Instance().PermissionFn('description_set') as FnCallType,
399
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description)]
404
400
  })
405
401
  ;
406
402
  }
407
403
 
408
404
  add_admin(admin:string[]) {
409
- if (!admin || !IsValidArray(admin, IsValidAddress)) {
405
+ if (admin.length === 0) return ;
406
+
407
+ if (!IsValidArray(admin, IsValidAddress)) {
410
408
  ERROR(Errors.IsValidArray)
411
409
  }
412
410
 
413
- let txb = this.protocol.CurrentSession();
414
- txb.moveCall({
415
- target:this.protocol.PermissionFn('admin_add_batch') as FnCallType,
416
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(admin), 'vector<address>')]
411
+ this.txb.moveCall({
412
+ target:Protocol.Instance().PermissionFn('admin_add_batch') as FnCallType,
413
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(admin))]
417
414
  });
418
- ;
419
415
  }
420
416
 
421
417
  remove_admin(admin:string[], removeall?:boolean) {
422
- if (!removeall && admin.length === 0) return
418
+ if (!removeall && admin.length === 0) return;
423
419
  if (!IsValidArray(admin, IsValidAddress)) {
424
420
  ERROR(Errors.IsValidArray, 'admin')
425
421
  }
426
422
 
427
- let txb = this.protocol.CurrentSession();
428
423
  if (removeall) {
429
- txb.moveCall({
430
- target:this.protocol.PermissionFn('admins_clear') as FnCallType,
431
- arguments:[Protocol.TXB_OBJECT(txb, this.object)]
424
+ this.txb.moveCall({
425
+ target:Protocol.Instance().PermissionFn('admins_clear') as FnCallType,
426
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
432
427
  });
433
428
  } else if (admin) {
434
- txb.moveCall({
435
- target:this.protocol.PermissionFn('admin_remove_batch') as FnCallType,
436
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(admin), 'vector<address>')]
429
+ this.txb.moveCall({
430
+ target:Protocol.Instance().PermissionFn('admin_remove_batch') as FnCallType,
431
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(admin))]
437
432
  });
438
433
  }
439
434
 
@@ -444,10 +439,9 @@ export class Permission {
444
439
  ERROR(Errors.IsValidAddress)
445
440
  }
446
441
 
447
- let txb = this.protocol.CurrentSession();
448
- txb.moveCall({
449
- target:this.protocol.PermissionFn('builder_set') as FnCallType,
450
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_owner, BCS.ADDRESS)]
442
+ this.txb.moveCall({
443
+ target:Protocol.Instance().PermissionFn('builder_set') as FnCallType,
444
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(new_owner)]
451
445
  });
452
446
  }
453
447
  query_permissions(address_queried:string, permissions:PermissionIndexType[]) {
@@ -459,31 +453,31 @@ export class Permission {
459
453
  ERROR(Errors.InvalidParam, 'permissions count');
460
454
  }
461
455
 
462
- const txb = this.protocol.CurrentSession();
463
- txb.moveCall({
464
- target:this.protocol.PermissionFn('query_permissions') as FnCallType,
465
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(address_queried, BCS.ADDRESS), txb.pure(permissions, 'vector<u64>')]
456
+ this.txb.moveCall({
457
+ target:Protocol.Instance().PermissionFn('query_permissions') as FnCallType,
458
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(address_queried),
459
+ this.txb.pure.vector('u64', permissions)]
466
460
  })
467
461
  }
468
462
 
469
- QueryPermissions(address_queried:string, permissions:PermissionIndexType[], onPermissionAnswer:OnPermissionAnswer, sender?:string) {
463
+ QueryPermissions(permission:string, address_queried:string, permissions:PermissionIndexType[], onPermissionAnswer:OnPermissionAnswer, sender?:string) {
464
+ //@ be the same txb
470
465
  this.query_permissions(address_queried, permissions);
471
- Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried,
472
- transactionBlock:this.protocol.CurrentSession()}).then((res) => {
466
+ Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried, transactionBlock:this.txb}).then((res) => {
473
467
  if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
474
- onPermissionAnswer({who:address_queried});
468
+ onPermissionAnswer({who:address_queried, object:permission});
475
469
  return
476
470
  }
477
471
 
478
472
  const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
479
473
 
480
474
  if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
481
- onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[]})
475
+ onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[], object:permission})
482
476
  } else {
483
477
  const perms = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
484
478
  const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from((res.results as any)[0].returnValues[2][0]));
485
479
  if (perms.length !== permissions.length) {
486
- onPermissionAnswer({who:address_queried});
480
+ onPermissionAnswer({who:address_queried, object:permission});
487
481
  return
488
482
  }
489
483
 
@@ -495,22 +489,25 @@ export class Permission {
495
489
  }
496
490
  return {query:v, permission:p, guard:g}
497
491
  })
498
- onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items});
492
+ onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
499
493
  }
500
494
  }).catch((e) => {
501
495
  console.log(e);
502
- onPermissionAnswer({who:address_queried});
496
+ onPermissionAnswer({who:address_queried, object:permission});
503
497
  })
504
498
  }
505
- static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType) : {has:boolean, guard?:string, owner?:boolean} {
499
+ static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType, bStrict:boolean=false) : {has:boolean, guard?:string, owner?:boolean} | undefined {
506
500
  if (answer) {
507
501
  if (answer.admin) return {has:true, owner:answer.owner}; // admin
508
502
  let i = answer.items?.find((v)=>v.query === index);
509
503
  if (i) {
510
504
  return {has:i.permission, guard:i.guard, owner:answer.owner};
511
- }
505
+ }
512
506
  }
513
- return {has:false}
507
+ if (bStrict) {
508
+ return {has:false, guard:undefined, owner:answer?.owner}
509
+ }
510
+ return undefined
514
511
  }
515
512
 
516
513
  static MAX_ADMIN_COUNT = 64;