wowok_agent 1.2.38 → 1.2.41

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 (89) hide show
  1. package/dist/call/arbitration.d.ts +1 -1
  2. package/dist/call/arbitration.d.ts.map +1 -1
  3. package/dist/call/arbitration.js +76 -50
  4. package/dist/call/arbitration.js.map +1 -1
  5. package/dist/call/base.d.ts +3 -1
  6. package/dist/call/base.d.ts.map +1 -1
  7. package/dist/call/base.js +24 -16
  8. package/dist/call/base.js.map +1 -1
  9. package/dist/call/call.d.ts +18 -18
  10. package/dist/call/call.d.ts.map +1 -1
  11. package/dist/call/call.js +12 -12
  12. package/dist/call/call.js.map +1 -1
  13. package/dist/call/demand.d.ts +3 -1
  14. package/dist/call/demand.d.ts.map +1 -1
  15. package/dist/call/demand.js +55 -28
  16. package/dist/call/demand.js.map +1 -1
  17. package/dist/call/guard.d.ts.map +1 -1
  18. package/dist/call/guard.js +29 -18
  19. package/dist/call/guard.js.map +1 -1
  20. package/dist/call/machine.d.ts +1 -1
  21. package/dist/call/machine.d.ts.map +1 -1
  22. package/dist/call/machine.js +82 -38
  23. package/dist/call/machine.js.map +1 -1
  24. package/dist/call/object_permission.d.ts +1 -0
  25. package/dist/call/object_permission.d.ts.map +1 -1
  26. package/dist/call/object_permission.js +12 -9
  27. package/dist/call/object_permission.js.map +1 -1
  28. package/dist/call/permission.d.ts +1 -0
  29. package/dist/call/permission.d.ts.map +1 -1
  30. package/dist/call/permission.js +48 -18
  31. package/dist/call/permission.js.map +1 -1
  32. package/dist/call/personal.d.ts +1 -1
  33. package/dist/call/personal.d.ts.map +1 -1
  34. package/dist/call/personal.js +40 -13
  35. package/dist/call/personal.js.map +1 -1
  36. package/dist/call/repository.d.ts.map +1 -1
  37. package/dist/call/repository.js +24 -14
  38. package/dist/call/repository.js.map +1 -1
  39. package/dist/call/service.d.ts +1 -1
  40. package/dist/call/service.d.ts.map +1 -1
  41. package/dist/call/service.js +149 -71
  42. package/dist/call/service.js.map +1 -1
  43. package/dist/call/treasury.d.ts +1 -1
  44. package/dist/call/treasury.d.ts.map +1 -1
  45. package/dist/call/treasury.js +65 -49
  46. package/dist/call/treasury.js.map +1 -1
  47. package/dist/common.d.ts +1 -0
  48. package/dist/common.d.ts.map +1 -1
  49. package/dist/common.js +9 -0
  50. package/dist/common.js.map +1 -1
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/local/account.d.ts +26 -12
  56. package/dist/local/account.d.ts.map +1 -1
  57. package/dist/local/account.js +199 -93
  58. package/dist/local/account.js.map +1 -1
  59. package/dist/local/index.d.ts +44 -23
  60. package/dist/local/index.d.ts.map +1 -1
  61. package/dist/local/index.js +57 -50
  62. package/dist/local/index.js.map +1 -1
  63. package/dist/local/local.d.ts +4 -2
  64. package/dist/local/local.d.ts.map +1 -1
  65. package/dist/local/local.js +35 -27
  66. package/dist/local/local.js.map +1 -1
  67. package/dist/query/objects.d.ts.map +1 -1
  68. package/dist/query/objects.js +15 -7
  69. package/dist/query/objects.js.map +1 -1
  70. package/package.json +2 -2
  71. package/src/call/arbitration.ts +87 -54
  72. package/src/call/base.ts +28 -19
  73. package/src/call/call.ts +31 -31
  74. package/src/call/demand.ts +62 -30
  75. package/src/call/guard.ts +25 -16
  76. package/src/call/machine.ts +89 -42
  77. package/src/call/object_permission.ts +12 -8
  78. package/src/call/permission.ts +45 -18
  79. package/src/call/personal.ts +39 -13
  80. package/src/call/repository.ts +27 -13
  81. package/src/call/service.ts +152 -73
  82. package/src/call/treasury.ts +70 -50
  83. package/src/common.ts +9 -0
  84. package/src/index.ts +1 -0
  85. package/src/local/account.ts +212 -92
  86. package/src/local/index.ts +75 -68
  87. package/src/local/local.ts +44 -30
  88. package/src/query/objects.ts +14 -6
  89. package/tsconfig.tsbuildinfo +1 -1
@@ -5,6 +5,8 @@ import { TransactionBlock, IsValidArgType, TxbAddress, TagName, PassportObject,
5
5
  import { query_objects, ObjectService } from '../query/objects.js';
6
6
  import { CallBase, CallResult, Namedbject } from "./base.js";
7
7
  import { Account } from '../local/account.js';
8
+ import { LocalMark } from '../local/local.js';
9
+ import { get_object_address } from '../common.js';
8
10
 
9
11
  /// The execution priority is determined by the order in which the object attributes are arranged
10
12
  export interface CallService_Data {
@@ -28,7 +30,7 @@ export interface CallService_Data {
28
30
  refund_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
29
31
  | {op:'removeall'} | {op:'remove', addresses:string[]};
30
32
  bPublished?: boolean;
31
- order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string | 'fetch',
33
+ order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string,
32
34
  namedNewOrder?: Namedbject, namedNewProgress?:Namedbject}
33
35
  order_agent?: {order?:string; agents: string[]; progress?:string};
34
36
  order_required_info?: {order?:string; info?:Customer_RequiredInfo};
@@ -53,11 +55,27 @@ export class CallService extends CallBase {
53
55
 
54
56
  var checkOwner = false; const guards : string[] = [];
55
57
  const perms : PermissionIndexType[] = []; var obj: ObjectService | undefined;
56
- const permission_address = (this.data?.permission as any)?.address;
57
- const object_address = (this.data?.object as any)?.address;
58
- const treasury_address = (this.data?.payee_treasury as any)?.address;
58
+ var [permission_address, object_address, treasury_address] =
59
+ await LocalMark.Instance().get_many_address(
60
+ [(this.data?.permission as any)?.address,
61
+ (this.data?.object as any)?.address,
62
+ (this.data?.payee_treasury as any)?.address]);
59
63
 
60
- if (permission_address && IsValidAddress(permission_address)) {
64
+ if (object_address) {
65
+ if (!this.data.type_parameter || !permission_address) {
66
+ await this.update_content(object_address, 'Service');
67
+ if (this.content) {
68
+ permission_address = (this.content as ObjectService).permission;
69
+ this.data.type_parameter = this.content.type_raw!;
70
+ }
71
+ }
72
+ } else {
73
+ if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
74
+ ERROR(Errors.IsValidArgType, 'CallService_Data.data.type_parameter')
75
+ }
76
+ }
77
+
78
+ if (permission_address) {
61
79
  if (!this.data?.object) {
62
80
  perms.push(PermissionIndex.service)
63
81
  }
@@ -112,36 +130,39 @@ export class CallService extends CallBase {
112
130
  if (this.data?.sales !== undefined) {
113
131
  perms.push(PermissionIndex.service_sales)
114
132
  }
115
- if (this.data?.order_new?.guard !== undefined) {
116
- if (IsValidAddress(this.data.order_new.guard)) {
117
- guards.push(this.data.order_new.guard)
133
+ if (this.data?.order_new !== undefined) {
134
+ if (this.data.order_new.guard) {
135
+ const guard = await LocalMark.Instance().get_address(this.data.order_new.guard);
136
+ if (guard) {
137
+ guards.push(guard)
138
+ }
118
139
  } else {
119
- if (!this.data.object) {
120
- if (this.data?.buy_guard && IsValidAddress(this.data.buy_guard)) {
121
- guards.push(this.data?.buy_guard)
140
+ if (!object_address) {
141
+ const buy_guard = await LocalMark.Instance().get_address(this.data?.buy_guard);
142
+ if (buy_guard) {
143
+ guards.push(buy_guard)
122
144
  }
123
145
  } else {
124
- if (!obj) {
125
- const r = await query_objects({objects:[object_address]});
126
- if (r?.objects && r.objects[0].type === 'Service') {
127
- obj = r.objects[0] as ObjectService;
128
- }
129
- }
130
- if (obj?.buy_guard) {
131
- guards.push(obj?.buy_guard)
132
- }
146
+ await this.update_content(object_address, 'Service');
147
+
148
+ if ((this.content as ObjectService)?.buy_guard) {
149
+ guards.push((this.content as ObjectService).buy_guard!)
150
+ }
133
151
  }
134
152
  }
135
153
  }
136
- if (IsValidAddress((this.data?.order_refund as any)?.guard)) {
137
- guards.push((this.data?.order_refund as any)?.guard)
154
+ if (this.data.order_refund !== undefined) {
155
+ const guard = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.guard);
156
+ if (guard) guards.push(guard);
138
157
  }
158
+
139
159
  if (this.data.order_withdrawl !== undefined) { // permission(may be guard) + withdraw_guard
140
160
  perms.push(PermissionIndex.service_withdraw)
141
161
  }
142
162
 
143
- if (typeof(this.data?.order_withdrawl?.data?.withdraw_guard) === 'string' && IsValidAddress(this.data?.order_withdrawl?.data?.withdraw_guard)) {
144
- guards.push(this.data?.order_withdrawl?.data?.withdraw_guard)
163
+ if (typeof(this.data?.order_withdrawl?.data?.withdraw_guard) === 'string') {
164
+ const guard = await LocalMark.Instance().get_address(this.data?.order_withdrawl?.data?.withdraw_guard);
165
+ if (guard) guards.push(guard);
145
166
  }
146
167
 
147
168
  return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
@@ -150,9 +171,12 @@ export class CallService extends CallBase {
150
171
  }
151
172
  protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
152
173
  let obj : Service | undefined ; let permission: any; let payee: any;
153
- const permission_address = (this.data?.permission as any)?.address;
154
- const object_address = (this.data?.object as any)?.address;
155
- const treasury_address = (this.data?.payee_treasury as any)?.address;
174
+ var [permission_address, object_address] = this?.content ?
175
+ [(this.content as ObjectService).permission, this.content.object] :
176
+ await LocalMark.Instance().get_many_address(
177
+ [(this.data?.permission as any)?.address,
178
+ (this.data?.object as any)?.address]);
179
+ const treasury_address = await LocalMark.Instance().get_address((this.data?.payee_treasury as any)?.address);
156
180
 
157
181
  if (!object_address) {
158
182
  if (!permission_address || !IsValidAddress(permission_address)) {
@@ -166,10 +190,10 @@ export class CallService extends CallBase {
166
190
  obj = Service.New(txb, this.data.type_parameter!, permission?permission.get_object():permission_address,
167
191
  this.data?.description??'', payee?payee.get_object():treasury_address, permission?undefined:passport)
168
192
  } else {
169
- if (IsValidAddress(object_address) && this.data.type_parameter && permission_address && IsValidAddress(permission_address)) {
193
+ if (this.data.type_parameter && permission_address) {
170
194
  obj = Service.From(txb, this.data.type_parameter, permission_address, object_address)
171
195
  } else {
172
- ERROR(Errors.InvalidParam, 'object or permission address invalid.')
196
+ ERROR(Errors.InvalidParam, 'CallService_Data.data.type_parameter or permission')
173
197
  }
174
198
  }
175
199
 
@@ -183,23 +207,36 @@ export class CallService extends CallBase {
183
207
  if (this.data?.endpoint !== undefined) {
184
208
  obj?.set_endpoint(this.data.endpoint, pst)
185
209
  }
186
- if (this.data?.payee_treasury !== undefined && object_address) {
210
+ if (treasury_address !== undefined && object_address) {
187
211
  obj?.set_payee(treasury_address, pst);
188
212
  }
189
213
  if (this.data?.gen_discount !== undefined) {
190
- obj?.discount_transfer(this.data.gen_discount, pst)
214
+ const add = [];
215
+ for (let i = 0; i < this.data.gen_discount.length; ++ i) {
216
+ let v = this.data.gen_discount[i];
217
+ const addr = await LocalMark.Instance().get_address(v.receiver);
218
+ if (addr) {
219
+ v.receiver = addr;
220
+ add.push(v)
221
+ }
222
+ }
223
+ obj?.discount_transfer(add, pst)
191
224
  }
192
225
  if (this.data?.repository !== undefined) {
193
226
  switch (this.data.repository.op) {
194
227
  case 'add':
195
- this.data.repository.repositories.forEach(v => obj?.add_repository(v, pst))
228
+ case 'set':
229
+ if (this.data.repository.op === 'set') obj?.remove_repository([], true, pst);
230
+ for (let i = 0; i < this.data.repository.repositories.length; ++ i) {
231
+ let v = this.data.repository.repositories[i];
232
+ const addr = await LocalMark.Instance().get_address(v);
233
+ if (addr) {
234
+ obj?.add_repository(v, pst)
235
+ }
236
+ }
196
237
  break;
197
238
  case 'remove':
198
- obj?.remove_repository(this.data.repository.repositories, false, pst)
199
- break;
200
- case 'set':
201
- obj?.remove_repository([], true, pst)
202
- this.data.repository.repositories.forEach(v => obj?.add_repository(v, pst))
239
+ obj?.remove_repository(await LocalMark.Instance().get_many_address2(this.data.repository.repositories), false, pst)
203
240
  break;
204
241
  case 'removeall':
205
242
  obj?.remove_repository([], true, pst)
@@ -209,14 +246,19 @@ export class CallService extends CallBase {
209
246
  if (this.data?.extern_withdraw_treasury !== undefined) {
210
247
  switch(this.data.extern_withdraw_treasury.op) {
211
248
  case 'add':
212
- this.data.extern_withdraw_treasury.treasuries.forEach(v=>obj?.add_treasury(v.token_type, v.address, pst))
213
- break;
214
249
  case 'set':
215
- obj?.remove_treasury([], true, pst)
216
- this.data.extern_withdraw_treasury.treasuries.forEach(v=>obj?.add_treasury(v.token_type, v.address, pst))
250
+ if (this.data.extern_withdraw_treasury.op === 'set') obj?.remove_treasury([], true, pst);
251
+
252
+ for (let i = 0; i < this.data.extern_withdraw_treasury.treasuries.length; ++ i) {
253
+ let v = this.data.extern_withdraw_treasury.treasuries[i];
254
+ const addr = await LocalMark.Instance().get_address(v.address);
255
+ if (addr && v.token_type) {
256
+ obj?.add_treasury(v.token_type, v.address, pst);
257
+ }
258
+ }
217
259
  break;
218
260
  case 'remove':
219
- obj?.remove_treasury(this.data.extern_withdraw_treasury.addresses, false, pst)
261
+ obj?.remove_treasury(await LocalMark.Instance().get_many_address2(this.data.extern_withdraw_treasury.addresses), false, pst)
220
262
  break;
221
263
  case 'removeall':
222
264
  obj?.remove_treasury([], false, pst)
@@ -224,19 +266,25 @@ export class CallService extends CallBase {
224
266
  }
225
267
  }
226
268
  if (this.data?.machine !== undefined) {
227
- obj?.set_machine(this.data.machine, pst)
269
+ const machine = await LocalMark.Instance().get_address(this.data.machine);
270
+ obj?.set_machine(machine, pst)
228
271
  }
229
272
  if (this.data?.arbitration !== undefined) {
230
273
  switch(this.data.arbitration.op) {
231
274
  case 'add':
232
- this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.token_type, pst))
233
- break;
234
275
  case 'set':
235
- obj?.remove_arbitration([], true, pst)
236
- this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.token_type, pst))
276
+ if (this.data.arbitration.op === 'set') obj?.remove_arbitration([], true, pst);
277
+ for (let i = 0; i < this.data.arbitration.arbitrations.length; ++ i) {
278
+ let v = this.data.arbitration.arbitrations[i];
279
+ const addr = await LocalMark.Instance().get_address(v.address);
280
+ if (addr && v.token_type) {
281
+ obj?.add_arbitration(v.address, v.token_type, pst)
282
+ }
283
+ }
284
+
237
285
  break;
238
286
  case 'remove':
239
- obj?.remove_arbitration(this.data.arbitration.addresses, false, pst)
287
+ obj?.remove_arbitration(await LocalMark.Instance().get_many_address2(this.data.arbitration.addresses), false, pst)
240
288
  break;
241
289
  case 'removeall':
242
290
  obj?.remove_arbitration([], false, pst)
@@ -263,14 +311,22 @@ export class CallService extends CallBase {
263
311
  if (this.data?.withdraw_guard !== undefined) {
264
312
  switch(this.data.withdraw_guard.op) {
265
313
  case 'add':
266
- obj?.add_withdraw_guards(this.data.withdraw_guard.guards, pst)
267
- break;
268
314
  case 'set':
269
- obj?.remove_withdraw_guards([], true, pst)
270
- obj?.add_withdraw_guards(this.data.withdraw_guard.guards, pst)
315
+ if (this.data.withdraw_guard.op === 'set') obj?.remove_withdraw_guards([], true, pst);
316
+
317
+ const add = []
318
+ for (let i = 0; i < this.data.withdraw_guard.guards.length; ++ i) {
319
+ let v = this.data.withdraw_guard.guards[i];
320
+ const addr = typeof(v.guard) === 'string' ? await LocalMark.Instance().get_address(v.guard as string) : v.guard;
321
+ if (addr) {
322
+ v.guard = addr;
323
+ add.push(v)
324
+ }
325
+ }
326
+ obj?.add_withdraw_guards(add, pst)
271
327
  break;
272
328
  case 'remove':
273
- obj?.remove_withdraw_guards(this.data.withdraw_guard.addresses, false, pst)
329
+ obj?.remove_withdraw_guards(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.addresses), false, pst)
274
330
  break;
275
331
  case 'removeall':
276
332
  obj?.remove_withdraw_guards([], true, pst)
@@ -280,14 +336,23 @@ export class CallService extends CallBase {
280
336
  if (this.data?.refund_guard !== undefined) {
281
337
  switch(this.data.refund_guard.op) {
282
338
  case 'add':
283
- obj?.add_refund_guards(this.data.refund_guard.guards, pst)
284
- break;
285
339
  case 'set':
286
- obj?.remove_refund_guards([], true, pst)
287
- obj?.add_refund_guards(this.data.refund_guard.guards, pst)
340
+ if (this.data.refund_guard.op === 'set') obj?.remove_refund_guards([], true, pst);
341
+ const add = []
342
+ for (let i = 0; i < this.data.refund_guard.guards.length; ++ i) {
343
+ let v = this.data.refund_guard.guards[i];
344
+ const addr = typeof(v.guard) === 'string' ? await LocalMark.Instance().get_address(v.guard as string) : v.guard;
345
+ if (addr) {
346
+ v.guard = addr;
347
+ add.push(v)
348
+ }
349
+ }
350
+ obj?.add_refund_guards(add, pst)
288
351
  break;
352
+
353
+
289
354
  case 'remove':
290
- obj?.remove_refund_guards(this.data.refund_guard.addresses, false, pst)
355
+ obj?.remove_refund_guards(await LocalMark.Instance().get_many_address2(this.data.refund_guard.addresses), false, pst)
291
356
  break;
292
357
  case 'removeall':
293
358
  obj?.remove_refund_guards([], true, pst)
@@ -314,39 +379,53 @@ export class CallService extends CallBase {
314
379
  }
315
380
 
316
381
  if (this.data?.order_agent !== undefined) {
317
- const o = this.data.order_agent.order ?? order_new?.order;
318
- if (!o) ERROR(Errors.Fail, 'order invalid: order_agent');
382
+ const o = this.data.order_agent.order ? await LocalMark.Instance().get_address(this.data.order_agent.order) : order_new?.order;
383
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_agent.order}`);
319
384
 
320
- obj?.set_order_agent(o!, this.data.order_agent.agents, this.data.order_agent.progress)
385
+ const p = this.data.order_agent.progress ? await LocalMark.Instance().get_address(this.data.order_agent.progress) : order_new?.progress;
386
+ if (!p) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.progress:${this.data.order_agent.progress}`);
387
+
388
+ obj?.set_order_agent(o, await LocalMark.Instance().get_many_address2(this.data.order_agent.agents), p)
321
389
  }
322
390
  if (this.data?.order_required_info !== undefined && this.data.order_required_info.info !== undefined) {
323
- const o = this.data.order_required_info.order ?? order_new?.order;
324
- if (!o) ERROR(Errors.Fail, 'order invalid: order_required_info');
391
+ const o = this.data.order_required_info.order ? await LocalMark.Instance().get_address(this.data.order_required_info.order) : order_new?.order;
392
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_required_info.order}`);
325
393
 
326
394
  obj?.update_order_required_info(o!, this.data.order_required_info.info)
327
395
  }
328
396
  if (this.data?.order_refund !== undefined) {
329
- const o = this.data.order_refund.order ?? order_new?.order;
330
- if (!o) ERROR(Errors.Fail, 'order invalid: order_refund');
397
+ const o = this.data.order_refund.order ? await LocalMark.Instance().get_address(this.data.order_refund.order) : order_new?.order;
398
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_refund.order}`);
399
+
331
400
 
332
401
  if ((this.data?.order_refund as any)?.arb && (this.data?.order_refund as any)?.arb_token_type) {
333
- obj?.refund_withArb(o!, (this.data?.order_refund as any)?.arb, (this.data?.order_refund as any)?.arb_token_type)
402
+ const arb = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.arb);
403
+ if (arb) {
404
+ obj?.refund_withArb(o!, arb, (this.data?.order_refund as any)?.arb_token_type)
405
+ }
334
406
  } else {
335
- obj?.refund(o!, (this.data?.order_refund as any)?.guard, pst)
407
+ const guard = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.guard);
408
+ if (guard) obj?.refund(o!, guard, pst)
336
409
  }
337
410
  }
338
411
  if (this.data?.order_withdrawl !== undefined && pst) { //@ need withdrawal pst
339
- const o = this.data.order_withdrawl.order ?? order_new?.order;
340
- if (!o) ERROR(Errors.Fail, 'order invalid: order_withdrawl');
341
-
412
+ const o = this.data.order_withdrawl.order ? await LocalMark.Instance().get_address(this.data.order_withdrawl.order) : order_new?.order;
413
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_withdrawl.order}`);
414
+ this.data.order_withdrawl.data.for_guard = await get_object_address(this.data.order_withdrawl.data.for_guard);
415
+ this.data.order_withdrawl.data.for_object = await get_object_address(this.data.order_withdrawl.data.for_object);
416
+ this.data.order_withdrawl.data.treasury = await get_object_address(this.data.order_withdrawl.data.treasury);
417
+ this.data.order_withdrawl.data.withdraw_guard = await get_object_address(this.data.order_withdrawl.data.withdraw_guard);
342
418
  obj?.withdraw(o!, this.data.order_withdrawl.data, pst)
343
419
  }
344
420
 
345
421
  if (this.data?.order_payer !== undefined && obj) {
346
- const o = this.data.order_payer.order ?? order_new?.order;
347
- if (!o) ERROR(Errors.Fail, 'order invalid: order_payer');
422
+ const o = this.data.order_payer.order ? await LocalMark.Instance().get_address(this.data.order_payer.order) : order_new?.order;
423
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_payer.order}`);
424
+ const p = this.data.order_payer.progress ? await LocalMark.Instance().get_address(this.data.order_payer.progress) : order_new?.progress;
425
+ if (!p) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.progress:${this.data.order_payer.progress}`);
348
426
 
349
- obj?.change_order_payer(o!, this.data.order_payer.payer_new, this.data.order_payer.progress)
427
+ const payer = await LocalMark.Instance().get_address(this.data.order_payer.payer_new);
428
+ if (payer) obj?.change_order_payer(o, payer, p)
350
429
  }
351
430
 
352
431
  if (order_new && this?.data?.order_new) {
@@ -4,6 +4,8 @@ import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Error
4
4
  import { query_objects, ObjectTreasury } from '../query/objects.js';
5
5
  import { CallBase, CallResult, Namedbject } from "./base.js";
6
6
  import { Account } from '../local/account.js';
7
+ import { LocalMark } from '../local/local.js';
8
+ import { get_object_address } from '../common.js';
7
9
 
8
10
  /// The execution priority is determined by the order in which the object attributes are arranged
9
11
  export interface CallTreasury_Data {
@@ -11,7 +13,7 @@ export interface CallTreasury_Data {
11
13
  object?: {address:string} | {namedNew?: Namedbject}; // undefined or {named_new...} for creating a new object
12
14
  permission?: {address:string} | {namedNew?: Namedbject, description?:string};
13
15
  description?: string;
14
- deposit?: {data:{balance:string|number; index?:number|string; remark?:string; for_object?:string; for_guard?:string}; guard?:string | 'fetch'};
16
+ deposit?: {data:{balance:string|number; index?:number|string; remark?:string; for_object?:string; for_guard?:string}; guard?:string};
15
17
  receive?: {payment:string; received_object:string};
16
18
  withdraw?: WithdrawParam;
17
19
  deposit_guard?: string;
@@ -32,10 +34,26 @@ export class CallTreasury extends CallBase {
32
34
 
33
35
  var checkOwner = false; const guards : string[] = [];
34
36
  const perms : PermissionIndexType[] = []; var obj: ObjectTreasury | undefined ;
35
- const permission_address = (this.data?.permission as any)?.address;
36
- const object_address = (this.data?.object as any)?.address;
37
+ var [permission_address, object_address, treasury_address] =
38
+ await LocalMark.Instance().get_many_address(
39
+ [(this.data?.permission as any)?.address,
40
+ (this.data?.object as any)?.address]);
37
41
 
38
- if (permission_address && IsValidAddress(permission_address)) {
42
+ if (object_address) {
43
+ if (!this.data.type_parameter || !permission_address) {
44
+ await this.update_content(object_address, 'Treasury');
45
+ if (this.content) {
46
+ permission_address = (this.content as ObjectTreasury).permission;
47
+ this.data.type_parameter = this.content.type_raw!;
48
+ }
49
+ }
50
+ } else {
51
+ if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
52
+ ERROR(Errors.IsValidArgType, 'CallTreasury_Data.data.type_parameter')
53
+ }
54
+ }
55
+
56
+ if (permission_address) {
39
57
  if (!this.data?.object) {
40
58
  perms.push(PermissionIndex.treasury)
41
59
  }
@@ -54,46 +72,36 @@ export class CallTreasury extends CallBase {
54
72
  if (this.data?.deposit_guard !== undefined) {
55
73
  perms.push(PermissionIndex.treasury_deposit_guard)
56
74
  }
57
- if (this.data?.deposit?.guard !== undefined) {
58
- if (IsValidAddress(this.data.deposit.guard)) {
59
- guards.push(this.data.deposit.guard)
75
+ if (this.data?.deposit !== undefined) {
76
+ if (this.data.deposit.guard) {
77
+ const guard = await LocalMark.Instance().get_address(this.data?.deposit?.guard);
78
+ if (guard) {
79
+ guards.push(guard)
80
+ }
60
81
  } else {
61
- if (!this.data.object) {
62
- if (this.data?.deposit_guard && IsValidAddress(this.data?.deposit_guard)) {
63
- guards.push(this.data.deposit_guard)
82
+ if (!object_address) {
83
+ const guard = await LocalMark.Instance().get_address(this.data.deposit_guard);
84
+ if (guard) {
85
+ guards.push(guard);
64
86
  }
65
87
  } else {
66
- if (!obj) {
67
- const r = await query_objects({objects:[object_address]});
68
- if (r?.objects && r.objects[0].type === 'Treasury') {
69
- obj = r.objects[0] as ObjectTreasury;
70
- }
71
- }
72
- if (obj?.deposit_guard) {
73
- guards.push(obj?.deposit_guard)
74
- }
88
+ await this.update_content(object_address, 'Treasury');
89
+
90
+ if ((this.content as ObjectTreasury)?.deposit_guard) {
91
+ guards.push((this.content as ObjectTreasury).deposit_guard!)
92
+ }
75
93
  }
76
-
77
94
  }
78
95
  }
79
96
  if (this.data?.receive !== undefined) {
80
97
  perms.push(PermissionIndex.treasury_receive)
81
98
  }
82
- if (this.data?.withdraw?.withdraw_guard !== undefined) {
83
- if (typeof(this.data.withdraw.withdraw_guard) === 'string' && IsValidAddress(this.data.withdraw.withdraw_guard)) {
84
- guards.push(this.data.withdraw.withdraw_guard)
85
- } else if (this.data.object) {
86
- if (!obj) {
87
- const r = await query_objects({objects:[object_address]});
88
- if (r?.objects && r.objects[0].type === 'Treasury') {
89
- obj = r.objects[0] as ObjectTreasury;
90
- }
91
- }
92
- if (typeof(obj?.withdraw_guard) === 'string') {
93
- guards.push(obj?.withdraw_guard)
94
- }
95
- }
96
- } else {
99
+ if (this.data?.withdraw?.withdraw_guard !== undefined) { // withdraw with guard
100
+ const guard = await get_object_address(this.data.withdraw.withdraw_guard);
101
+ if (guard) {
102
+ guards.push(guard)
103
+ }
104
+ } else { // withdraw with permission
97
105
  perms.push(PermissionIndex.treasury_withdraw)
98
106
  }
99
107
  return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
@@ -102,20 +110,23 @@ export class CallTreasury extends CallBase {
102
110
  }
103
111
  protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
104
112
  let obj : Treasury | undefined ; let permission: any;
105
- const permission_address = (this.data?.permission as any)?.address;
106
- const object_address = (this.data?.object as any)?.address;
113
+ var [permission_address, object_address] = this?.content ?
114
+ [(this.content as ObjectTreasury).permission, this.content.object] :
115
+ await LocalMark.Instance().get_many_address(
116
+ [(this.data?.permission as any)?.address,
117
+ (this.data?.object as any)?.address]);
107
118
 
108
119
  if (!object_address) {
109
- if (!permission_address || !IsValidAddress(permission_address)) {
120
+ if (!permission_address) {
110
121
  const d = (this.data?.permission as any)?.description ?? '';
111
122
  permission = Permission.New(txb, d);
112
123
  }
113
124
  obj = Treasury.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'', permission?undefined:passport)
114
125
  } else {
115
- if (IsValidAddress(object_address) && this.data.type_parameter && permission_address && IsValidAddress(permission_address)) {
126
+ if (this.data.type_parameter && permission_address) {
116
127
  obj = Treasury.From(txb, this.data.type_parameter, permission_address, object_address)
117
128
  } else {
118
- ERROR(Errors.InvalidParam, 'object or permission address invalid.')
129
+ ERROR(Errors.InvalidParam, 'CallTreasury_Data.data.type_parameter or permission')
119
130
  }
120
131
  }
121
132
 
@@ -129,33 +140,42 @@ export class CallTreasury extends CallBase {
129
140
  if (coin) {
130
141
  const index = this.data.deposit.data?.index ?? 0;
131
142
  obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.data.remark ??'',
132
- for_guard:this.data.deposit.data?.for_guard,
133
- for_object: this.data.deposit.data?.for_object
143
+ for_guard:await get_object_address(this.data.deposit.data?.for_guard),
144
+ for_object:await get_object_address(this.data.deposit.data?.for_object)
134
145
  })
135
146
  }
136
147
  }
137
148
  if (this.data?.receive !== undefined) {
138
- obj?.receive(this.data.receive.payment, this.data.receive.received_object, pst);
149
+ const [payment, receive] = await LocalMark.Instance().get_many_address([this.data.receive.payment, this.data.receive.received_object])
150
+ if (payment && receive) obj?.receive(payment, receive, pst);
139
151
  }
152
+
140
153
  if (this.data?.withdraw !== undefined) {
154
+ this.data.withdraw.for_guard = await get_object_address(this.data.withdraw.for_guard);
155
+ this.data.withdraw.for_object = await get_object_address(this.data.withdraw.for_object);
156
+ this.data.withdraw.withdraw_guard = await get_object_address(this.data.withdraw.withdraw_guard);
141
157
  obj?.withdraw(this.data.withdraw, pst)
142
158
  }
143
159
 
144
160
  if (this.data?.deposit_guard !== undefined) {
145
- obj?.set_deposit_guard(this.data.deposit_guard, pst);
161
+ const guard = await LocalMark.Instance().get_address(this.data?.deposit_guard);
162
+ obj?.set_deposit_guard(guard, pst);
146
163
  }
147
164
  if (this.data?.withdraw_guard !== undefined) {
148
165
  switch (this.data.withdraw_guard.op) {
149
166
  case 'add':
150
- this.data.withdraw_guard.data.forEach(v => obj?.add_withdraw_guard(v.guard, BigInt(v.amount), pst))
167
+ case 'set':
168
+ if (this.data.withdraw_guard.op === 'set') obj?.remove_withdraw_guard([], true, pst);
169
+ for (let i = 0; i < this.data.withdraw_guard.data.length; ++ i) {
170
+ let v = this.data.withdraw_guard.data[i];
171
+ const guard = await LocalMark.Instance().get_address(v.guard);
172
+ if (guard) obj?.add_withdraw_guard(guard, BigInt(v.amount), pst);
173
+ }
151
174
  break;
152
175
  case 'remove':
153
- obj?.remove_withdraw_guard(this.data.withdraw_guard.guards, false, pst)
154
- break;
155
- case 'set':
156
- obj?.remove_withdraw_guard([], true, pst)
157
- this.data.withdraw_guard.data.forEach(v => obj?.add_withdraw_guard(v.guard, BigInt(v.amount), pst))
176
+ obj?.remove_withdraw_guard(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.guards), false, pst)
158
177
  break;
178
+
159
179
  case 'removeall':
160
180
  obj?.remove_withdraw_guard([], true, pst)
161
181
  break;
package/src/common.ts CHANGED
@@ -1,5 +1,14 @@
1
+ import { LocalMark } from "./local/local.js";
1
2
 
2
3
 
3
4
  export const isBrowser = () => {
4
5
  return typeof window !== 'undefined' && typeof indexedDB !== 'undefined';
6
+ }
7
+
8
+ export const get_object_address = async (object: any) => {
9
+ if (typeof(object) === 'string') {
10
+ return await LocalMark.Instance().get_address(object)
11
+ } else {
12
+ return object
13
+ }
5
14
  }
package/src/index.ts CHANGED
@@ -17,5 +17,6 @@ export * from './local/account.js'
17
17
  export * from './local/cache.js'
18
18
  export * from './local/local.js'
19
19
  export * from './local/index.js'
20
+ export * from './common.js'
20
21
 
21
22
  export * as WOWOK from 'wowok'