wowok 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/demand.d.ts +3 -2
  2. package/dist/demand.d.ts.map +1 -1
  3. package/dist/demand.js +21 -7
  4. package/dist/entity.d.ts +2 -1
  5. package/dist/entity.d.ts.map +1 -1
  6. package/dist/entity.js +23 -7
  7. package/dist/exception.d.ts +3 -1
  8. package/dist/exception.d.ts.map +1 -1
  9. package/dist/exception.js +3 -1
  10. package/dist/guard.js +1 -1
  11. package/dist/machine.js +2 -2
  12. package/dist/permission.d.ts +20 -4
  13. package/dist/permission.d.ts.map +1 -1
  14. package/dist/permission.js +146 -13
  15. package/dist/protocol.d.ts +30 -6
  16. package/dist/protocol.d.ts.map +1 -1
  17. package/dist/protocol.js +124 -17
  18. package/dist/repository.d.ts +6 -3
  19. package/dist/repository.d.ts.map +1 -1
  20. package/dist/repository.js +59 -40
  21. package/dist/resource.d.ts +20 -6
  22. package/dist/resource.d.ts.map +1 -1
  23. package/dist/resource.js +58 -21
  24. package/dist/reward.d.ts +6 -3
  25. package/dist/reward.d.ts.map +1 -1
  26. package/dist/reward.js +43 -19
  27. package/dist/service.d.ts +6 -3
  28. package/dist/service.d.ts.map +1 -1
  29. package/dist/service.js +76 -44
  30. package/dist/utils.d.ts +15 -1
  31. package/dist/utils.d.ts.map +1 -1
  32. package/dist/utils.js +150 -13
  33. package/dist/vote.d.ts +2 -2
  34. package/dist/vote.d.ts.map +1 -1
  35. package/dist/vote.js +14 -14
  36. package/package.json +1 -1
  37. package/src/demand.ts +22 -8
  38. package/src/entity.ts +25 -6
  39. package/src/exception.ts +3 -1
  40. package/src/guard.ts +1 -1
  41. package/src/machine.ts +2 -2
  42. package/src/permission.ts +165 -10
  43. package/src/protocol.ts +127 -17
  44. package/src/repository.ts +64 -44
  45. package/src/resource.ts +61 -20
  46. package/src/reward.ts +46 -23
  47. package/src/service.ts +79 -46
  48. package/src/utils.ts +141 -15
  49. package/src/vote.ts +14 -14
package/src/permission.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BCS } from '@mysten/bcs';
2
2
  import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, 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
 
@@ -9,12 +9,13 @@ export enum PermissionIndex {
9
9
  repository_set_description_set = 101,
10
10
  repository_set_policy_mode = 102,
11
11
  repository_add_policies = 103,
12
- repository_remove_policies = 104,
12
+ repository_remove_policies = 103,
13
13
  repository_set_policy_description = 105,
14
14
  repository_set_policy_permission = 106,
15
15
  repository_reference_add = 107,
16
- repository_reference_remove = 108,
17
- repository_reference_removeall = 108,
16
+ repository_reference_remove = 107,
17
+ repository_reference_removeall = 107,
18
+
18
19
  vote = 150,
19
20
  vote_set_description = 151,
20
21
  vote_set_reference = 152,
@@ -27,19 +28,23 @@ export enum PermissionIndex {
27
28
  vote_lock_deadline = 159,
28
29
  vote_expand_deadline = 160,
29
30
  vote_lock_guard = 161,
31
+
30
32
  service = 200,
31
33
  service_set_description = 201,
32
34
  service_set_price = 202,
33
35
  service_set_stock = 203,
34
36
  service_add_stock = 203,
35
37
  service_reduce_stock = 203,
38
+ service_set_sale_endpoint = 204,
36
39
  service_set_payee = 205,
37
40
  service_repository_add = 206,
38
41
  service_repository_remove = 207,
39
42
  service_add_withdraw_guards = 208,
40
43
  service_remove_withdraw_guards = 208,
44
+ service_removeall_withdraw_guards = 208,
41
45
  service_add_refund_guards = 210,
42
46
  service_remove_refund_guards = 210,
47
+ service_removeall_refund_guards = 210,
43
48
  service_add_sales = 212,
44
49
  service_remove_sales = 213,
45
50
  service_discount_transfer = 214,
@@ -54,11 +59,12 @@ export enum PermissionIndex {
54
59
  service_change_required_pubkey = 222,
55
60
  service_change_order_required_pubkey = 224,
56
61
  service_pause = 225,
62
+
57
63
  reward = 240,
58
64
  reward_refund = 241,
59
65
  reward_expand_time = 242,
60
66
  reward_add_guard = 243,
61
- reward_remove_guard = 244,
67
+ reward_remove_guard = 243,
62
68
  reward_set_description = 245,
63
69
  reward_lock_guards = 246,
64
70
  demand = 260,
@@ -86,6 +92,94 @@ export enum PermissionIndex {
86
92
  user_defined_start = 10000,
87
93
  }
88
94
 
95
+ export interface PermissionInfoType {
96
+ index: number;
97
+ name:string;
98
+ description:string;
99
+ module: string;
100
+ guard?: string;
101
+ }
102
+
103
+ export const PermissionInfo : PermissionInfoType[] = [
104
+ {index:PermissionIndex.repository, name:'Repository', description:'repository', module: 'repository'},
105
+ {index:PermissionIndex.repository_set_description_set, name:'Description', description:'repository_set_description_set', module: 'repository'},
106
+ {index:PermissionIndex.repository_set_policy_mode, name:'Policy mode', description:'repository_set_policy_mode', module: 'repository'},
107
+ {index:PermissionIndex.repository_add_policies, name:'Add Policy', description:'brepository_add_policies', module: 'repository'},
108
+ {index:PermissionIndex.repository_remove_policies, name:'Remove Policy', description:'build machine', module: 'repository'},
109
+ {index:PermissionIndex.repository_set_policy_description, name:'Policy Description', description:'build machine', module: 'repository'},
110
+ {index:PermissionIndex.repository_set_policy_permission, name:'Policy Permission', description:'build machine', module: 'repository'},
111
+ {index:PermissionIndex.repository_reference_add, name:'Add Reference', description:'build machine', module: 'repository'},
112
+ {index:PermissionIndex.repository_reference_remove, name:'Remove Reference', description:'build machine', module: 'repository'},
113
+
114
+ {index:PermissionIndex.vote, name:'Vote', description:'build machine', module: 'vote'},
115
+ {index:PermissionIndex.vote_set_description, name:'Description', description:'build machine', module: 'vote'},
116
+ {index:PermissionIndex.vote_set_reference, name:'Reference', description:'build machine', module: 'vote'},
117
+ {index:PermissionIndex.vote_add_guard, name:'Add Guard', description:'build machine', module: 'vote'},
118
+ {index:PermissionIndex.vote_remove_guard, name:'Remove Guard', description:'build machine', module: 'vote'},
119
+ {index:PermissionIndex.vote_add_option, name:'Add Option', description:'build machine', module: 'vote'},
120
+ {index:PermissionIndex.vote_remove_option, name:'Remove Option', description:'build machine', module: 'vote'},
121
+ {index:PermissionIndex.vote_set_max_choice_count, name:'Choice count', description:'build machine', module: 'vote'},
122
+ {index:PermissionIndex.vote_open_voting, name:'Open voting', description:'build machine', module: 'vote'},
123
+ {index:PermissionIndex.vote_lock_deadline, name:'Lock deadline', description:'build machine', module: 'vote'},
124
+ {index:PermissionIndex.vote_expand_deadline, name:'Expand deadline', description:'build machine', module: 'vote'},
125
+ {index:PermissionIndex.vote_lock_guard, name:'Lock Guard', description:'build machine', module: 'vote'},
126
+
127
+ {index:PermissionIndex.service, name:'Service', description:'build machine', module: 'service'},
128
+ {index:PermissionIndex.service_set_description, name:'Description', description:'build machine', module: 'service'},
129
+ {index:PermissionIndex.service_set_price, name:'Price', description:'build machine', module: 'service'},
130
+ {index:PermissionIndex.service_set_stock, name:'Inventory', description:'build machine', module: 'service'},
131
+ {index:PermissionIndex.service_set_payee, name:'Payee', description:'build machine', module: 'service'},
132
+ {index:PermissionIndex.service_repository_add, name:'Add Repository', description:'build machine', module: 'service'},
133
+ {index:PermissionIndex.service_repository_remove, name:'Remove Repository', description:'build machine', module: 'service'},
134
+ {index:PermissionIndex.service_add_withdraw_guards, name:'Withdraw Guard', description:'Add, remove withdraw guards', module: 'service'},
135
+ {index:PermissionIndex.service_add_refund_guards, name:'Refund Guard', description:'Add, remove refund guards', module: 'service'},
136
+ {index:PermissionIndex.service_remove_refund_guards, name:'Remove Refund Guard', description:'build machine', module: 'service'},
137
+ {index:PermissionIndex.service_add_sales, name:'Add sales', description:'build machine', module: 'service'},
138
+ {index:PermissionIndex.service_remove_sales, name:'Remove sales', description:'build machine', module: 'service'},
139
+ {index:PermissionIndex.service_discount_transfer, name:'Discount', description:'build machine', module: 'service'},
140
+ {index:PermissionIndex.service_withdraw, name:'Withdraw', description:'build machine', module: 'service'},
141
+ {index:PermissionIndex.service_set_buy_guard, name:'Buyer Guard', description:'build machine', module: 'service'},
142
+ {index:PermissionIndex.service_set_machine, name:'Machine', description:'build machine', module: 'service'},
143
+ {index:PermissionIndex.service_set_endpoint, name:'Endpoint', description:'build machine', module: 'service'},
144
+ {index:PermissionIndex.service_publish, name:'Publish', description:'build machine', module: 'service'},
145
+ {index:PermissionIndex.service_clone, name:'Clone', description:'build machine', module: 'service'},
146
+ {index:PermissionIndex.service_set_customer_required, name:'Buyer info', description:'build machine', module: 'service'},
147
+ {index:PermissionIndex.service_change_order_required_pubkey, name:'Order pubkey', description:'build machine', module: 'service'},
148
+ {index:PermissionIndex.service_pause, name:'Pause', description:'build machine', module: 'service'},
149
+
150
+ {index:PermissionIndex.reward, name:'Reward', description:'build machine', module: 'reward'},
151
+ {index:PermissionIndex.reward_refund, name:'Refund', description:'build machine', module: 'reward'},
152
+ {index:PermissionIndex.reward_expand_time, name:'Expand deadline', description:'build machine', module: 'reward'},
153
+ {index:PermissionIndex.reward_add_guard, name:'Add Guard', description:'build machine', module: 'reward'},
154
+ {index:PermissionIndex.reward_remove_guard, name:'Remove Guard', description:'build machine', module: 'reward'},
155
+ {index:PermissionIndex.reward_set_description, name:'Description', description:'build machine', module: 'reward'},
156
+ {index:PermissionIndex.reward_lock_guards, name:'Lock Guard', description:'build machine', module: 'reward'},
157
+
158
+ {index:PermissionIndex.demand, name:'Demand', description:'build machine', module: 'demand'},
159
+ {index:PermissionIndex.demand_refund, name:'Refund', description:'build machine', module: 'demand'},
160
+ {index:PermissionIndex.demand_expand_time, name:'Expand deadline', description:'build machine', module: 'demand'},
161
+ {index:PermissionIndex.demand_set_guard, name:'Guard', description:'build machine', module: 'demand'},
162
+ {index:PermissionIndex.demand_set_description, name:'Description', description:'build machine', module: 'demand'},
163
+ {index:PermissionIndex.demand_yes, name:'Yes', description:'build machine', module: 'demand'},
164
+
165
+ {index:PermissionIndex.machine, name: 'Machine', description:'build machine', module: 'machine'},
166
+ {index:PermissionIndex.machine_set_description, name: 'Description', description:'machine_set_description', module: 'machine'},
167
+ {index:PermissionIndex.machine_add_repository, name: 'Add Repository', description:'machine_add_repository', module: 'machine'},
168
+ {index:PermissionIndex.machine_remove_repository, name: 'Remove Repository', description:'machine_remove_repository', module: 'machine'},
169
+ {index:PermissionIndex.machine_clone, name: 'Clone', description:'machine_clone', module: 'machine'},
170
+ {index:PermissionIndex.machine_add_node, name: 'Add node', description:'machine_add_node/2', module: 'machine'},
171
+ {index:PermissionIndex.machine_remove_node, name: 'Remove node', description:'machine_remove_node', module: 'machine'},
172
+ {index:PermissionIndex.machine_set_endpoint, name: 'Endpoint', description:'machine_set_endpoint', module: 'machine'},
173
+ {index:PermissionIndex.machine_pause, name: 'Pause', description:'machine_pause', module: 'machine'},
174
+ {index:PermissionIndex.machine_publish, name: 'Publish', description:'machine_publish', module: 'machine'},
175
+
176
+ {index:PermissionIndex.progress, name: 'Progress', description:'build progress', module: 'progress'},
177
+ {index:PermissionIndex.progress_set_namedOperator, name: 'Operator', description:'progress_set_namedOperator', module: 'progress'},
178
+ {index:PermissionIndex.progress_bind_task, name: 'Bind', description:'progress_bind_task', module: 'progress'},
179
+ {index:PermissionIndex.progress_set_context_repository, name: 'Repository', description:'progress_set_context_repository', module: 'progress'},
180
+ {index:PermissionIndex.progress_unhold, name: 'Unhold', description:'progress_unhold', module: 'progress'},
181
+ ]
182
+
89
183
  export type PermissionIndexType = PermissionIndex | number;
90
184
 
91
185
  export type Permission_Index = {
@@ -141,10 +235,71 @@ export class Permission {
141
235
  arguments: [Protocol.TXB_OBJECT(txb, this.object)],
142
236
  })
143
237
  }
238
+ add_userdefine(index: number, name:string) {
239
+ if (!Permission.IsValidUserDefinedIndex(index)) {
240
+ ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
241
+ }
242
+
243
+ if (!IsValidName(name)) {
244
+ ERROR(Errors.IsValidName, 'add_userdefine');
245
+ }
246
+ let txb = this.protocol.CurrentSession();
247
+ txb.moveCall({
248
+ target:this.protocol.PermissionFn('user_define_add') as FnCallType,
249
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64), txb.pure(name, BCS.STRING)]
250
+ })
251
+ }
252
+
253
+ remove_userdefine(index: number) {
254
+ if (!Permission.IsValidUserDefinedIndex(index)) {
255
+ ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
256
+ }
257
+
258
+ let txb = this.protocol.CurrentSession();
259
+ txb.moveCall({
260
+ target:this.protocol.PermissionFn('user_define_remove') as FnCallType,
261
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64)]
262
+ })
263
+ }
264
+
265
+ change_entity(old_entity: string, new_entity: string) {
266
+ if (!IsValidAddress(old_entity) || !IsValidAddress(new_entity)) {
267
+ ERROR(Errors.IsValidAddress, 'change_entity')
268
+ }
269
+ let txb = this.protocol.CurrentSession();
270
+ txb.moveCall({
271
+ target:this.protocol.PermissionFn('change_entity') as FnCallType,
272
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_entity, BCS.ADDRESS),
273
+ txb.pure(new_entity, BCS.ADDRESS) ]
274
+ })
275
+ }
276
+
277
+ add_entity2(entities: string[], index?:PermissionIndexType) {
278
+ if (!entities) {
279
+ ERROR(Errors.InvalidParam, 'add_entity2');
280
+ }
281
+ if (!IsValidArray(entities, IsValidAddress)) {
282
+ ERROR(Errors.IsValidArray, 'add_entity2');
283
+ }
284
+
285
+ let txb = this.protocol.CurrentSession();
286
+ if (index) {
287
+ txb.moveCall({
288
+ target:this.protocol.PermissionFn('add_with_index') as FnCallType,
289
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(index, BCS.U64),
290
+ txb.pure(array_unique(entities), 'vector<address>')]
291
+ })
292
+ } else {
293
+ txb.moveCall({
294
+ target:this.protocol.PermissionFn('add') as FnCallType,
295
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(entities), 'vector<address>')]
296
+ })
297
+ }
298
+ }
144
299
 
145
300
  add_entity(entities:Permission_Entity[]) {
146
301
  if (!entities) {
147
- ERROR(Errors.InvalidParam, 'entities');
302
+ ERROR(Errors.InvalidParam, 'add_entity');
148
303
  }
149
304
 
150
305
  let bValid = true;
@@ -179,13 +334,13 @@ export class Permission {
179
334
  }
180
335
  }
181
336
  }
182
- if (indexes.length > 0) {
337
+ //if (indexes.length > 0) {
183
338
  txb.moveCall({
184
339
  target:this.protocol.PermissionFn('add_batch') as FnCallType,
185
340
  arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity.entity_address, BCS.ADDRESS),
186
341
  txb.pure(indexes, 'vector<u64>')]
187
342
  })
188
- }
343
+ //}
189
344
  }
190
345
  // set guards
191
346
  guards.forEach(({entity_address, index, guard}) => {
@@ -219,8 +374,7 @@ export class Permission {
219
374
  arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
220
375
  txb.pure(index, BCS.U64)]
221
376
  })
222
- }
223
- ;
377
+ };
224
378
  }
225
379
 
226
380
  remove_index(entity_address:string, index:PermissionIndexType[]) {
@@ -314,6 +468,7 @@ export class Permission {
314
468
  static MAX_ADMIN_COUNT = 64;
315
469
  static MAX_ENTITY_COUNT = 2000;
316
470
  static MAX_PERMISSION_INDEX_COUNT = 200;
471
+ static MAX_PERSONAL_PERMISSION_COUNT = 200;
317
472
  static IsValidUserDefinedIndex = (index:number) => {
318
473
  return index >= PermissionIndex.user_defined_start && IsValidUint(index)
319
474
  }
package/src/protocol.ts CHANGED
@@ -101,6 +101,49 @@ export enum ValueType {
101
101
  TYPE_VEC_STRING = 121,
102
102
  TYPE_U256 = 122,
103
103
  }
104
+ export enum RepositoryValueType {
105
+ Address = 200,
106
+ Address_Vec = 201,
107
+ PositiveNumber = 202,
108
+ PositiveNumber_Vec = 203,
109
+ String = 204,
110
+ String_Vec = 205,
111
+ }
112
+
113
+ export const RepositoryValueTypeInfo = [
114
+ {type: RepositoryValueType.Address, name:'Address', description:'Object id or Personal address.'},
115
+ {type: RepositoryValueType.Address_Vec, name:'Address vector', description:'Vector of address.'},
116
+ {type: RepositoryValueType.String, name:'String', description:'String.'},
117
+ {type: RepositoryValueType.String_Vec, name:'String vector', description:'Vector of string.'},
118
+ {type: RepositoryValueType.PositiveNumber, name:'Positive number', description:'Positive number. including u8, u16 ,..., u256'},
119
+ {type: RepositoryValueType.PositiveNumber_Vec, name:'Positive number vector', description:'Vector of positive number'},
120
+ ]
121
+
122
+ export const ValueTypeInfo = [
123
+ {type:ValueType.TYPE_BOOL, name:'bool'},
124
+ {type:ValueType.TYPE_ADDRESS, name:'address'},
125
+ {type:ValueType.TYPE_U64, name:'u64'},
126
+ {type:ValueType.TYPE_U8, name:'u8'},
127
+ {type:ValueType.TYPE_VEC_U8, name:'vec-u8'},
128
+ {type:ValueType.TYPE_U128, name:'u128'},
129
+ {type:ValueType.TYPE_VEC_ADDRESS, name:'vec-address'},
130
+ {type:ValueType.TYPE_VEC_BOOL, name:'vec-bool'},
131
+ {type:ValueType.TYPE_VEC_VEC_U8, name:'vec-vec-u8'},
132
+ {type:ValueType.TYPE_VEC_U64, name:'vec-u64'},
133
+ {type:ValueType.TYPE_VEC_U128, name:'vec-u128'},
134
+ {type:ValueType.TYPE_OPTION_ADDRESS, name:'opt-address'},
135
+ {type:ValueType.TYPE_OPTION_BOOL, name:'opt-bool'},
136
+ {type:ValueType.TYPE_OPTION_U8, name:'opt-u8'},
137
+ {type:ValueType.TYPE_OPTION_U64, name:'opt-u64'},
138
+ {type:ValueType.TYPE_OPTION_U128, name:'opt-u128'},
139
+ {type:ValueType.TYPE_OPTION_U256, name:'opt-u256'},
140
+ {type:ValueType.TYPE_OPTION_STRING, name:'opt-string'},
141
+ {type:ValueType.TYPE_OPTION_VEC_U8, name:'opt-vec-u8'},
142
+ {type:ValueType.TYPE_VEC_U256, name:'vec-u256'},
143
+ {type:ValueType.TYPE_STRING, name:'string'},
144
+ {type:ValueType.TYPE_VEC_STRING, name:'vec-string'},
145
+ {type:ValueType.TYPE_U256, name:'u256'},
146
+ ]
104
147
 
105
148
  export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
106
149
  export const ValueTypeArray = (Object.values(ValueType) as []).filter((v)=>typeof(v) === 'number') as number[];
@@ -155,6 +198,23 @@ export enum ENTRYPOINT {
155
198
  localnet = 'localnet'
156
199
  }
157
200
 
201
+ const TESTNET = {
202
+ package: "0x852fa17575b1ae11932b475110bf46981458fdb67a2f07b922022e1516560fad",
203
+ wowok_object: '0xf98cc6d8bd9feadc5dce7365270b4ffb32f69a5320ab739193d301103e686e8c',
204
+ entity_object: '0xe0469c187499273ec39a575cc28d4d93f0a66b11e1b92028c61bc69bfc1167c6',
205
+ }
206
+
207
+ const MAINNET = {
208
+ package: "",
209
+ wowok_object: '',
210
+ entity_object: '',
211
+ }
212
+
213
+ export interface CoinTypeInfo {
214
+ symbol: string;
215
+ type: string;
216
+ decimals: number;
217
+ }
158
218
  export class Protocol {
159
219
  protected network = '';
160
220
  protected package = '';
@@ -175,6 +235,9 @@ export class Protocol {
175
235
  Protocol._instance = new Protocol();
176
236
  }; return Protocol._instance
177
237
  }
238
+ static Client() : SuiClient {
239
+ return new SuiClient({ url: Protocol.Instance().NetworkUrl() });
240
+ }
178
241
 
179
242
  UseNetwork(network:ENTRYPOINT=ENTRYPOINT.testnet) {
180
243
  this.network = network;
@@ -184,12 +247,16 @@ export class Protocol {
184
247
  case ENTRYPOINT.devnet:
185
248
  break;
186
249
  case ENTRYPOINT.testnet:
187
- this.package = "0x10edb3f8e11008c8c5cfe951989d10c353d885377fe6cbdfedea3b315fa6b06c";
188
- this.wowok_object = '0xb2a940236a1811ff43eaf902e165155687f9c756dcdd1fc70096551bffcb89fc';
189
- this.entity_object= '0x8dc27895c123c9736649a800fc58e621b7747d56f0b15a560d09a4412c42ae28';
250
+ this.package = TESTNET.package;
251
+ this.wowok_object = TESTNET.wowok_object;
252
+ this.entity_object= TESTNET.entity_object;
190
253
  this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
191
254
  break;
192
255
  case ENTRYPOINT.mainnet:
256
+ this.package = MAINNET.package;
257
+ this.wowok_object = MAINNET.wowok_object;
258
+ this.entity_object= MAINNET.entity_object;
259
+ this.graphql = 'https://sui-mainnet.mystenlabs.com/graphql';
193
260
  break;
194
261
  };
195
262
  }
@@ -269,29 +336,70 @@ export class Protocol {
269
336
  }
270
337
 
271
338
  // used in service, discount, order, because service has COIN wrapper for TOKEN
272
- static SUI_TOKEN_TYPE = '0x2::sui::SUI'; // TOKEN_TYPE
339
+ static SUI_TOKEN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'; // TOKEN_TYPE
273
340
  // used in demand, reward, ...
274
- static SUI_COIN_TYPE = '0x2::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
341
+ static SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
275
342
  WOWOK_TOKEN_TYPE = () => { return this.package + '::wowok::WOWOK' }
276
343
  WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.package + '::wowok::WOWOK>'}
277
344
  COINS_TYPE = () => {
278
345
  switch(this.network) {
279
346
  case ENTRYPOINT.testnet:
280
- /*return [
281
- {name:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
282
- {name:'WOW', type:this.WOWOK_TOKEN_TYPE(), decimals:9},
283
- ];*/
347
+ return this.CoinTypes_Testnet;
284
348
  case ENTRYPOINT.mainnet:
285
- return [
286
- {name:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
287
- {name:'WOW', type:this.WOWOK_TOKEN_TYPE(), decimals:9},
288
- {name:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
289
- {name:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
290
- {name:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
291
- {name:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
292
- ];
349
+ return this.CoinTypes_Mainnet;
293
350
  }; return [];
294
351
  }
352
+ Update_CoinType = (token_type: string, decimals:number, symbol: string) => {
353
+ if (!symbol || !token_type) return ;
354
+ switch(this.network) {
355
+ case ENTRYPOINT.testnet:
356
+ var r = this.CoinTypes_Testnet.filter((v) => v?.type !== token_type);
357
+ r.push({symbol:symbol, type:token_type, decimals:decimals});
358
+ this.CoinTypes_Testnet = r;
359
+ break;
360
+ case ENTRYPOINT.mainnet:
361
+ var r = this.CoinTypes_Mainnet.filter((v) => v?.type !== token_type);
362
+ r.push({symbol:symbol, type:token_type, decimals:decimals});
363
+ this.CoinTypes_Mainnet = r;
364
+ break;
365
+ };
366
+ }
367
+ ExplorerUrl = (objectid: string, type:'object' | 'txblock' | 'account'='object') => {
368
+ if (this.network === ENTRYPOINT.testnet) {
369
+ return 'https://testnet.suivision.xyz/' + type + '/' + objectid;
370
+ } else if (this.network === ENTRYPOINT.mainnet) {
371
+ return 'https://suivision.xyz/' + type + '/' + objectid;
372
+ }; return ''
373
+ }
374
+
375
+ CoinTypes_Testnet:CoinTypeInfo[] = [
376
+ {symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
377
+ {symbol:'SUI', type:'0x2::sui::SUI', decimals:9},
378
+ {symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
379
+ {symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
380
+ {symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
381
+ {symbol:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
382
+ {symbol:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
383
+ ];
384
+
385
+ CoinTypes_Mainnet:CoinTypeInfo[] = [
386
+ ];
387
+
388
+ GetCoinTypeInfo = (token_type: string, handler:(info:CoinTypeInfo)=>void) : CoinTypeInfo | 'loading' => {
389
+ let r = this.COINS_TYPE().find((v) => v?.type === token_type);
390
+ if (!r) {
391
+ Protocol.Client().getCoinMetadata({coinType:token_type}).then((res) => {
392
+ if (res?.decimals && res?.symbol) {
393
+ this.Update_CoinType(token_type, res?.decimals, res?.symbol);
394
+ handler({symbol:res.symbol, decimals:res.decimals, type:token_type});
395
+ }
396
+ }).catch((e) => {
397
+ console.log(e);
398
+ })
399
+ } else {
400
+ return r;
401
+ }; return 'loading';
402
+ }
295
403
 
296
404
  static CLOCK_OBJECT = Inputs.SharedObjectRef({
297
405
  objectId:"0x6",
@@ -316,6 +424,7 @@ export class Protocol {
316
424
  WOWOK_OBJECTS_PREFIX_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
317
425
  { return this.package + '::' + key + '::'; })
318
426
  object_name_from_type_repr = (type_repr:string) : string => {
427
+ if (!type_repr) return ''
319
428
  let i = type_repr.indexOf('::');
320
429
  if (i > 0 && type_repr.slice(0, i) === this.package) {
321
430
  i = type_repr.indexOf('<');
@@ -339,6 +448,7 @@ export class RpcResultParser {
339
448
  return names;
340
449
  }
341
450
  static objectids_from_response = (protocol:Protocol, response:SuiTransactionBlockResponse, concat_result?:Map<string, TxbObject[]>): Map<string, TxbObject[]> => {
451
+ // console.log(response)
342
452
  let ret = new Map<string, string[]>();
343
453
  if (response?.objectChanges) {
344
454
  response.objectChanges.forEach((change) => {
package/src/repository.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BCS } from '@mysten/bcs';
2
- import { Protocol, FnCallType, ValueType, RepositoryObject, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
2
+ import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
3
3
  import { PermissionIndexType, Permission } from './permission'
4
- import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, } from './utils';
4
+ import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, IsValidName, } from './utils';
5
5
  import { ERROR, Errors } from './exception';
6
6
  import { Resource } from './resource';
7
7
 
@@ -9,10 +9,12 @@ export enum Repository_Policy_Mode {
9
9
  POLICY_MODE_FREE = 0,
10
10
  POLICY_MODE_STRICT = 1,
11
11
  }
12
+
13
+
12
14
  export type Repository_Policy = {
13
15
  key:string;
14
16
  description: string;
15
- value_type: ValueType;
17
+ data_type: RepositoryValueType;
16
18
  permission?: PermissionIndexType; // PermissionIndex like, must be geater than 10000
17
19
  }
18
20
  export type Repository_Policy_Data = {
@@ -142,13 +144,13 @@ export class Repository {
142
144
  }
143
145
  add_reference(references:string[], passport?:PassportObject) {
144
146
  if (!references) {
145
- ERROR(Errors.InvalidParam, 'references')
147
+ ERROR(Errors.InvalidParam, 'add_reference')
146
148
  }
147
149
 
148
150
  if (!IsValidArray(references, IsValidAddress)) {
149
- ERROR(Errors.IsValidArray, 'references')
151
+ ERROR(Errors.IsValidArray, 'add_reference')
150
152
  }
151
-
153
+ console.log(array_unique(references))
152
154
  let txb = this.protocol.CurrentSession();
153
155
  if (passport) {
154
156
  txb.moveCall({
@@ -167,12 +169,12 @@ export class Repository {
167
169
  }
168
170
  }
169
171
  remove_reference(references:string[], removeall?:boolean, passport?:PassportObject) {
170
- if (!references) {
171
- ERROR(Errors.InvalidParam, 'references')
172
+ if (!references && !removeall) {
173
+ ERROR(Errors.InvalidParam, 'remove_reference')
172
174
  }
173
175
 
174
- if (!IsValidArray(references, IsValidAddress)) {
175
- ERROR(Errors.IsValidArray, 'references')
176
+ if (references && !IsValidArray(references, IsValidAddress)) {
177
+ ERROR(Errors.IsValidArray, 'remove_reference')
176
178
  }
177
179
 
178
180
  let txb = this.protocol.CurrentSession();
@@ -233,7 +235,7 @@ export class Repository {
233
235
  arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
234
236
  txb.pure(policy.key),
235
237
  txb.pure(policy.description),
236
- permission_index, txb.pure(policy.value_type, BCS.U8),
238
+ permission_index, txb.pure(policy.data_type, BCS.U8),
237
239
  Protocol.TXB_OBJECT(txb, this.permission)]
238
240
  })
239
241
  } else {
@@ -242,15 +244,15 @@ export class Repository {
242
244
  arguments:[Protocol.TXB_OBJECT(txb, this.object),
243
245
  txb.pure(policy.key),
244
246
  txb.pure(policy.description),
245
- permission_index, txb.pure(policy.value_type, BCS.U8),
247
+ permission_index, txb.pure(policy.data_type, BCS.U8),
246
248
  Protocol.TXB_OBJECT(txb, this.permission)]
247
249
  })
248
250
  }
249
251
  });
250
252
  }
251
253
 
252
- remove_policies(policy_keys:string[], removeall?:boolean, passport?:PassportObject) {
253
- if (!removeall && !policy_keys) {
254
+ remove_policies(policy_keys:string[], passport?:PassportObject) {
255
+ if (!policy_keys) {
254
256
  ERROR(Errors.AllInvalid, 'policy_keys & removeall')
255
257
  }
256
258
  if (policy_keys && !IsValidArray(policy_keys, Repository.IsValidName)){
@@ -259,36 +261,44 @@ export class Repository {
259
261
 
260
262
  let txb = this.protocol.CurrentSession();
261
263
  if (passport) {
262
- if (removeall) {
263
- txb.moveCall({
264
- target:this.protocol.RepositoryFn('policy_remove_all_with_passport') as FnCallType,
265
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
266
- })
267
- } else {
268
- txb.moveCall({
269
- target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
270
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
271
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
272
- Protocol.TXB_OBJECT(txb, this.permission)]
273
- })
274
- }
264
+ txb.moveCall({
265
+ target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
266
+ arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
267
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
268
+ Protocol.TXB_OBJECT(txb, this.permission)]
269
+ })
275
270
  } else {
276
- if (removeall) {
277
- txb.moveCall({
278
- target:this.protocol.RepositoryFn('policy_remove_all') as FnCallType,
279
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
280
- })
281
- } else {
282
- txb.moveCall({
283
- target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
284
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
285
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
286
- Protocol.TXB_OBJECT(txb, this.permission)]
287
- })
288
- }
271
+ txb.moveCall({
272
+ target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
273
+ arguments:[Protocol.TXB_OBJECT(txb, this.object),
274
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
275
+ Protocol.TXB_OBJECT(txb, this.permission)]
276
+ })
289
277
  }
290
-
291
278
  }
279
+ rename_policy(policy_key:string, new_policy_key:string, passport?:PassportObject) {
280
+ if (!IsValidName(policy_key) || !IsValidName(new_policy_key)) {
281
+ ERROR(Errors.IsValidName, 'change_policy')
282
+ }
283
+
284
+ let txb = this.protocol.CurrentSession();
285
+ if (passport) {
286
+ txb.moveCall({
287
+ target:this.protocol.RepositoryFn('policy_rename_with_passport') as FnCallType,
288
+ arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
289
+ txb.pure(policy_key, BCS.STRING), txb.pure(new_policy_key, BCS.STRING),
290
+ Protocol.TXB_OBJECT(txb, this.permission)]
291
+ })
292
+ } else {
293
+ txb.moveCall({
294
+ target:this.protocol.RepositoryFn('policy_rename') as FnCallType,
295
+ arguments:[Protocol.TXB_OBJECT(txb, this.object),
296
+ txb.pure(policy_key, BCS.STRING), txb.pure(new_policy_key, BCS.STRING),
297
+ Protocol.TXB_OBJECT(txb, this.permission)]
298
+ })
299
+ }
300
+ }
301
+
292
302
  // PermissionIndex.description_set
293
303
  set_description(description:string, passport?:PassportObject) {
294
304
  if (!IsValidDesription(description)){
@@ -347,7 +357,6 @@ export class Repository {
347
357
  Protocol.TXB_OBJECT(txb, this.permission)]
348
358
  })
349
359
  }
350
-
351
360
  }
352
361
 
353
362
  set_policy_permission(policy:string, permission_index?:number, passport?:PassportObject) {
@@ -376,7 +385,6 @@ export class Repository {
376
385
  arguments:[Protocol.TXB_OBJECT(txb, this.object), index, Protocol.TXB_OBJECT(txb, this.permission)]
377
386
  })
378
387
  }
379
-
380
388
  }
381
389
 
382
390
  change_permission(new_permission:PermissionObject) {
@@ -392,14 +400,26 @@ export class Repository {
392
400
  this.permission = new_permission
393
401
  }
394
402
 
395
- static MAX_POLICY_COUNT = 1000;
403
+ static MAX_POLICY_COUNT = 200;
396
404
  static MAX_KEY_LENGTH = 128;
397
405
  static MAX_VALUE_LENGTH = 204800;
406
+ static MAX_REFERENCE_COUNT = 100;
398
407
  static IsValidName = (key:string) => {
399
408
  return key.length <= Repository.MAX_KEY_LENGTH && key.length != 0;
400
409
  }
401
410
  static IsValidValue = (value:Uint8Array) => {
402
411
  return value.length < Repository.MAX_VALUE_LENGTH;
403
412
  }
413
+ static parseObjectType = (chain_type:string) : string => {
414
+ if (chain_type) {
415
+ const s = 'repository::Repository<'
416
+ const i = chain_type.indexOf(s);
417
+ if (i > 0) {
418
+ let r = chain_type.slice(i + s.length, chain_type.length-1);
419
+ return r
420
+ }
421
+ }
422
+ return '';
423
+ }
404
424
  }
405
425